Needs to include payment method id for block checkout but its missing there.
-
Needs to include payment method id for block checkout but its missing there.
-
This topic was modified 3 months, 1 week ago by
awaisaezad.
-
This topic was modified 3 months, 1 week ago by
-
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.
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.Thanks for the explanation.
woocommerce_store_api_checkout_order_processedis 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?)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:
- Create and attach the payment method to the customer before order placement.
- Store those IDs with the order so that I can later call Stripe’s
captureAPI.
Right now
woocommerce_store_api_checkout_order_processeddoesn’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.The
woocommerce_store_api_checkout_order_processedaction provides the$orderobject 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.
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.
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_chargeaction 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?
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.
Alright. You can use your custom code for the late capture then. Still, the snippet above might be useful.
You must be logged in to reply to this review.