• Resolved marashmallow

    (@marashmallow)


    Hello, is there documentation about how to programmatically capture a previously authorized charge?

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Payment Plugins

    (@mrclayton)

    Hi @marashmallow

    Apologies for the late reply, did not see this thread until now. How you programmatically capture an authorized charge depends on what variables you have access to.

    If you have the order object you can do the following:

    $order = wc_get_order($order_id);
    $payment_gateway = WC()->payment_gateways()->payment_gateways()[$order->get_payment_method()];
    if($payment_gateway instanceof WC_Payment_Gateway_Stripe){
        $amount = 5;
        $payment_gateway->capture_charge($amount, $order);
    }

    Kind Regards,

    Thread Starter marashmallow

    (@marashmallow)

    Thanks for the answer.

    I notice that there’s an amout being passed to be captured. Does this mean that I can charge partial amounts multiple times up to the amount originally authorized?

    Plugin Author Payment Plugins

    (@mrclayton)

    Does this mean that I can charge partial amounts multiple times up to the amount originally authorized?

    No, once you capture an authorized payment you cannot capture again. That amount was just part of the example. You can use any amount up to the order total when you process a capture request.

    Kind Regards

    Thread Starter marashmallow

    (@marashmallow)

    OK. Thanks for your help!

    Thread Starter marashmallow

    (@marashmallow)

    @mrclayton Following up on my earlier query, I’m now looking at the popup help message for setting “Capture Status” in WooCommerce > Stripe by Payment Plugins > Settings > Advanced Settings (see image). It explains:

    For orders that are authorized, when the order is set to this status, it will trigger a capture.

    This leads me to wonder if instead of capturing an authorized charge with the code you suggested above, it would be sufficient to just change the status of the order in WooCommerce, like the following, to be acted on by the “Capture Status” feature?

    $order = wc_get_order( $order_id );
    $new_status = 'completed';
    $order->update_status( $new_status );
    Plugin Author Payment Plugins

    (@mrclayton)

    This leads me to wonder if instead of capturing an authorized charge with the code you suggested above, it would be sufficient to just change the status of the order in WooCommerce, like the following, to be acted on by the “Capture Status” feature?

    Yes, you can capture the payment that way if you want the full order total to be captured.

    Thread Starter marashmallow

    (@marashmallow)

    Excellent, thanks!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Hook to capture authorized charge?’ is closed to new replies.