Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Bug: Error when refunding a payment via PayPal #264

Open
stackflow-arnaud opened this issue Jan 30, 2025 · 0 comments
Open

🐛 Bug: Error when refunding a payment via PayPal #264

stackflow-arnaud opened this issue Jan 30, 2025 · 0 comments

Comments

@stackflow-arnaud
Copy link

Problem Description
When I process a refund via PayPal, I encounter the following error:

Crashed in non-app: /vendor/payplug/sylius-payplug-plugin/src/PaymentProcessing/RefundPaymentProcessor.php in PayPlug\SyliusPayPlugPlugin\PaymentProcessing\RefundPaymentProcessor::process
The issue occurs in the RefundPaymentProcessor.php file, specifically in the following code:
{
    $this->prepare($payment);
    $details = $payment->getDetails();
    try {
        $this->payPlugApiClient->refundPayment($details['payment_id']);
    } catch (Exception $exception) {
        $message = $exception->getMessage();
        $this->logger->error('[PayPlug] RefundHistory Payment', ['error' => $message]);
    }
}

This happens because PayPlug registers a listener on the payment state change, as defined in the winzou_state_machine configuration:

winzou_state_machine:
    sylius_payment:
        callbacks:
            before:
                payplug_sylius_payplug_plugin_refund_process:
                    on: ["refund"]
                    do: ["@payplug_sylius_payplug_plugin.payment_processing.refund", "process"]
                    args: ["object"]

Root Cause
The issue occurs because the process() method is triggered for all payments, regardless of whether they were processed via PayPlug. This leads to an error when attempting to refund a non-PayPlug payment, such as PayPal.

Suggested Fix
Before calling $this->payPlugApiClient->refundPayment($details['payment_id']);, the plugin should check whether the payment was originally processed via PayPlug.

A possible solution could be to add a condition in RefundPaymentProcessor.php.
Would you consider implementing this fix in the plugin?

Thanks for your support! 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant