#Gavin-webhook

1 messages · Page 1 of 1 (latest)

lusty grove
#

Hello, your use case is totally reasonable. You can save your unique ID into client_reference_id or metadata as well

#

When you want to retrieve it via webhook, you would need to listen to the Checkout Session event, for example checkout.session.completed

#

it will contain a Checkout Session object, and has client_reference_id and metadatainside

dry crow
#

hmm ok, yes, I see now the checkout session does return it.

    [client_reference_id] => 1
    [metadata] => Stripe\StripeObject Object
        (
            [order_id] => 1
        )

however, since that's for checkout.session.completed, I'm still confused how I can reference the order when the payment is successful or fails within payment_intent.succeeded / payment_intent.payment_failed.

Since there is no other information in checkout session as far as I can tell that would allow me to match it to a payment intent object?

lusty grove
#

Inside Checkout Session you have a PaymentIntent Id

dry crow
#

Is there a reason why it's empty? Do I need to create / set a payment attempt before creating a session & redirecting to checkout?

[payment_intent] => 
#

I currently have this

$checkout_session = \Stripe\Checkout\Session::create([
  'success_url' => 'removed',
  'cancel_url' => 'removed',
  'payment_method_types' => ['card'],
  'customer_email' => $user['email'],
  'mode' => 'subscription',
  'line_items' => [[
    'price' => "price_1KJkhgEmnddknpefEve4sOwu",
    'quantity' => 1,
  ]],
  'client_reference_id' => $id,
  'metadata' => [
    'order_id' => $id   
  ],
]);
var session = "<?php echo $checkout_session['id']; ?>";
stripe.redirectToCheckout({ sessionId: session })
lusty grove
#

Only after the customer finish the Checkout, you will have the PaymentIntent inside the Checkout object

#

redirecting is just only presenting the link to your customer. He/She still needs to input their card info ... etc

dry crow
#

Ok, that is what I assumed.
Why is it empty for me then? checkout session id cs_test_a1zAaz4vprbhMEkwQJBryoVw07eieMrlxs9MxQQOOtu5c7IGshbiAwfEHL returned no value for payment_intent when capturing the event data for checkout.session.completed

#

I can send the full response data if needed.

lusty grove
#

can you send the event id ? (evt_xxx)

#

I do see a PaymentIntent inside that session pi_3KPKtEEmnddknpef1zcbG7By

dry crow
#

hmm I see. That is the correct payment intent.
I did not capture the event ID before, only the checkout session. I can make a new request and do so though. 1 sec.

#

Ok

#

event ID for checkout.session.completed: evt_1KPMkBEmnddknpef2DnREmbp
checkout session ID: cs_test_a1Wesbubtk5TY0bSFndqwiLhYKpIfKSIlNUcnZDdCmfsXnP4LskFPxnoTr

PaymentIntent ID from payment_intent.succeeded: pi_3KPMk8Emnddknpef1aicxLB8

and payment_intent is still empty in the checkout.session.completed data just like before.

lusty grove
#

Oh sorry that's a Subscription Session