• Resolved miroslavps

    (@miroslavps)


    Hi to all,
    I want to create a refund programmatically, so I use wc_create_refund(), but it returns me “An error occurred while attempting to create the refund using the payment gateway API.”.
    So I flow the code to find where this message come from. The massage is from same file where wc_create_refund() is, and the function is wc_refund_payment().

    In this function we have the following few lines of code:

    $result = $gateway->process_refund( $order->get_id(), $amount, $reason );

    if ( ! $result ) {
    throw new Exception( __( ‘An error occurred while attempting to create the refund using the payment gateway API.’, ‘woocommerce’ ) );
    }

    Following the code again I found process_refund() function in the abstract class WC_Payment_Gateway. But this function always return false:

    public function process_refund( $order_id, $amount = null, $reason = ” ) {

    return false;
    }

    so I can not see the way I can skip this check if ( ! $result ).

    Can someone help me? Do I use the correct functions or there is another solution to create refund?

    Regards!

Viewing 1 replies (of 1 total)
  • Thread Starter miroslavps

    (@miroslavps)

    Sorry guys, I missed parameter refund_payment in data array for the wc_create_refund.
    I set it to false, and I skip the check if ( ! $result ).

    So do not worry with this.
    Regards!

Viewing 1 replies (of 1 total)

The topic ‘Create a refund programmatically’ is closed to new replies.