Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author Wesley Rosa

    (@wesleyjrosa)

    Hello there,

    Could you please share more details on your issue? This way we can assist you better. Your need may be something simple for us to add.

    Thread Starter awaisaezad

    (@awaisaezad)

    https://wordpress.org/support/topic/how-to-attach-stripe-customer-to-payment-intent-in-checkout-for-delayed-capture/
    Above is the link explaining about my issue and how i overcame it. Block checkout does not have a payment_method_id or _stripe_source_id accessible in woocommerce_store_api_checkout_order_processed hook but only accessible later on in woocommerce_thankyou hook by which time the card is already burned as it does not attach the customer when making payment.

    Plugin Author Wesley Rosa

    (@wesleyjrosa)

    Thanks for the explanation. woocommerce_store_api_checkout_order_processed is a WooCommerce hook, not specific to Stripe. So we cannot include Stripe-specific data there. But we may consider adding a new hook for this purpose. Could you detail how this potential new hook could solve your issue? I mean, all the information you need (or is it just the payment method ID?)

    Thread Starter awaisaezad

    (@awaisaezad)

    I’d like to have both the Stripe customer ID and the payment method ID available in that hook.

    The reason is that for delayed capture in WooCommerce Blocks, I need to:

    1. Create and attach the payment method to the customer before order placement.
    2. Store those IDs with the order so that I can later call Stripe’s capture API.

    Right now woocommerce_store_api_checkout_order_processed doesn’t expose Stripe‑specific data, so I can’t retrieve those values at that stage. Having a dedicated hook that passes the customer ID and payment method ID would allow me to reliably store them on the order and solve the “capture later” problem in Blocks.

    Plugin Author Wesley Rosa

    (@wesleyjrosa)

    The woocommerce_store_api_checkout_order_processed action provides the $order object as the first parameter. Did you try to retrieve the Stripe-specific information from the metas there? I mean something like:

    add_action( 'woocommerce_store_api_checkout_order_processed', function( $order ) {
    $customer_id = $order->get_meta( '_stripe_customer_id', true );
    $payment_method_id = $order->get_meta( '_stripe_source_id', true );

    // Your custom code...
    } );

    Asking because I did some research around it and that’s basically what a new hook would look like.

    Thread Starter awaisaezad

    (@awaisaezad)

    Yes i have already seen the whole $order meta and the customer_id and payment_method_id is missing in this hook . I have carefully searched through the whole $order and i didn’t see the payment_method_id or the customer_id in this object which i could use to capture the charge later.

    Plugin Author Wesley Rosa

    (@wesleyjrosa)

    Right! I did some tests here and we cannot get those using this hook indeed. But you can:

    1 – Disable automatic capture without custom code. You can follow the guide here to just change the existing setting.

    2 – Add your custom code to the existing wc_gateway_stripe_process_payment_charge action hook. This one provides the information you need. Example:

    add_action( 'wc_gateway_stripe_process_payment_charge', function( $response, $order ) {
    $customer_id = $order->get_meta( '_stripe_customer_id', true );
    $payment_method_id = $order->get_meta( '_stripe_source_id', true );

    // Your custom code...
    }, 10, 2 );

    Could you please give it a try and let us know?

    Thread Starter awaisaezad

    (@awaisaezad)

    Thanks for the suggestion — I’m already aware of this approach. The problem is that enabling “Capture charge later” affects the entire order, and in my case, an order could contain both trial products and regular products. I can’t restrict the whole order to delayed capture just to support trials, I need my plugin to work regardless of whether the “Capture charge later” checkbox is enabled or disabled in Stripe settings.

    Plugin Author Wesley Rosa

    (@wesleyjrosa)

    Alright. You can use your custom code for the late capture then. Still, the snippet above might be useful.

Viewing 9 replies - 1 through 9 (of 9 total)

You must be logged in to reply to this review.