Skip to content

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

@stackflow-arnaud

Description

@stackflow-arnaud

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! 🙏

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions