#gecko - checkout events
1 messages ยท Page 1 of 1 (latest)
Hello! Just starting a thread for you -- I'll review and respond as soon as I can ๐
Yes it does
hi synthrider
howdy
ok got it....so in the case of a subscription, can you please point me to the doc that descibes the fields for the event.data.object? I was using paymentIntent, which works fine for one time payments, but need to pull out details for when a subscription hits the "checkout.session.completed" action
The payload is the Stripe object represented in the event
let me clarify
so checkout.session.completed is a checkout session object
and customer.subscription.created is a subscription object
for checkout.session.completed event, I fetch the object
it's a payment intent
and I can query paymentIntent.payment_status, and so on
for a one time payment, there is paymentIntent.payment_intent
you likely want to use expansion to expand the subscription then:
https://stripe.com/docs/api/expanding_objects
expand[]=subscription
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
which gives me piXXXXXXX
for subscriptions, it's null
and so I'm wanting to know the object structure that's returned when it's a subscription vs one time
I'm not sure that link exactly covers what I'm seeking
let me ask differently
a subscription is a series of payments
each payment (when renewal occurs), should have a unique payment intent id, would it not?
Correct, but that's associated with invoices
Are you trying to get the payment intent of the initial subscription payment?
i need to know the piXXX for every transaction
when a subscription is created, it seems that the structure that appears as the event object is different than a one time payment
i had fetched the object previously as a payment-intent....but looks like subscriptions are not responding as payment-intents
OK so following a subscription checkout that would be on the subscription.latest_invoice, you can use expansion to get that when retrieving the session (or retrieve the subscription directly)
https://stripe.com/docs/api/checkout/sessions/object#checkout_session_object-subscription
https://stripe.com/docs/api/subscriptions/object#subscription_object-latest_invoice
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
expand[]=subscription.latest_invoice
then the invoice object has payment_intent
ok great, thanks!!
NP!
since the event is a checkout.session.completed, is there a field easily to test if it's a subscription or one time payment? such as "payment" or "subscription" for mode? the link you shared above, shows 'payment' even for a subscription
first link
Yes, mode=payment or mode=subscription
the example code describes mode as having these choices but the code responses show payment...so it was unclear.
thanks, I'll test on that
Yep, it just shows payment as an example
last question, I hope....can a checkout.session.async_payment_succeeded event ever fire as a result of a subscription? I'm assuming yes?
Hmm i think that might only be for payment mode, but I'd suggest trying out your support flows in test mode to confirm
ok will do...testing always wins theory
ok....so I'm continuing to think this through....sorry for the continuation
right now I do this:
let event;
try {
event = stripe.webhooks.constructEvent(
payload,
sig,
STRIPE_WEBHOOK_ENDPOINT_SECRET,
);
}
when I get a webhook
the expansion link you provided says I can start at the .data member (of event I assume)
Sure, thats separate
so, once I'm here, if I want to do an expansion, do I have to do that on a call, to re-fetch?
You can't expand in webhook payload, you have to retrieve the object (you said you were retrieving them at the start, i thought)
because right now, I believe I get this event, and then when I get this:
case 'checkout.session.completed':
const paymentIntent = event.data.object;
so I have the object....but this is a direct assignment...I don't put an expansion here
Yes, when you get the event you'd need to retrieve the session from the API to expand. Sorry, I thought you were already doing this or I would have mentioned.
so I need to 're-fetch', with expansion?
Yep
well, retrieve for the first time
the webhook event delivery is not a retrieval, stripe is sending that to your endpoint
this is all inside my webhook endpoint
and my point is that event.data.object is in essence a 'retrieval' in that the data I need, is there already. I don't have to 'fetch' anything
but to do an expansion, I'd need to do a fetch...on which parameter?
It's not a retrieval, but it is the same default object data yes. For payments the payment intent id is included, for subscriptions the subscription id is included.
To expand either of those, you need to make an explicit retrieval/GET request with expansion
You can either retrieve the checkout session (using the session id) or retrieve the subscription (using the subscription id)
const session = await stripe.checkout.sessions.retrieve(
'cs_test_KdjLtDPfAjT1gq374DMZ3rHmZ9OoSlGRhyz8yTypH76KpN4JXkQpD2G0',
{
expand: ['customer'],
}
);
like so?
well not customer but yes
yes ๐
expand: ['subscription.latest_invoice'],
ok thanks!
NP!