How to attach Stripe customer to Payment Intent in Checkout for delayed Capture.
-
I need to hold a Stripe charge and capture it later (only when a customer keeps the product).
In WooCommerce shortcodes checkout, Stripe attaches the customer to the Payment Intent, so later capture works.
But in WooCommerce Blocks checkout, the customer is not attached, so the card is “burned” (not reusable), and later capture fails.Here’s the relevant code I use to attach the customer:
function attach_stripe_customer_to_payment_method( $payment_method_id, $customer_id, $stripe_secret ) { $response = wp_remote_post( "https://api.stripe.com/v1/payment_methods/$payment_method_id/attach", array( 'method' => 'POST', 'headers' => array( 'Authorization' => 'Bearer ' . $stripe_secret, ), 'body' => array( 'customer' => $customer_id, ), ) ); return wp_remote_retrieve_body( $response ); }In shortcodes checkout, I can get
$payment_method_idin:add_action( 'woocommerce_checkout_order_processed', function( $order_id, $posted_data, $order ) { // Works here - we can get payment_method_id and attach the customer. }, 10, 3 );But in Blocks checkout, the only hook available is:
add_action( 'woocommerce_store_api_checkout_order_processed', function( $order ) { // Can't get payment_method_id here, so we can't attach the customer. }, 10, 1 );The
payment_method_idis only available much later inwoocommerce_thankyou, but by then Stripe marks the card as used, so the Payment Intent can’t be reused for delayed capture.How can I access the
payment_method_idearlier in the WooCommerce Blocks checkout flow (similar to shortcodes) so that I can attach the customer to the Payment Intent and hold the charge for later capture?The page I need help with: [log in to see the link]
The topic ‘How to attach Stripe customer to Payment Intent in Checkout for delayed Capture.’ is closed to new replies.