#gecko - checkout events

1 messages ยท Page 1 of 1 (latest)

delicate condor
#

Hello! Just starting a thread for you -- I'll review and respond as soon as I can ๐Ÿ™‚

#

Yes it does

brittle arch
#

hi synthrider

delicate condor
#

howdy

brittle arch
#

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

delicate condor
#

The payload is the Stripe object represented in the event

brittle arch
#

let me clarify

delicate condor
#

so checkout.session.completed is a checkout session object

brittle arch
#

i get the event

#

i fetch the object

delicate condor
#

and customer.subscription.created is a subscription object

brittle arch
#

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

delicate condor
brittle arch
#

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?

delicate condor
#

Correct, but that's associated with invoices

#

Are you trying to get the payment intent of the initial subscription payment?

brittle arch
#

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

delicate condor
#

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)

#
#

expand[]=subscription.latest_invoice

#

then the invoice object has payment_intent

brittle arch
#

ok great, thanks!!

delicate condor
#

NP!

brittle arch
#

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

delicate condor
#

Yes, mode=payment or mode=subscription

brittle arch
#

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

delicate condor
#

Yep, it just shows payment as an example

brittle arch
#

last question, I hope....can a checkout.session.async_payment_succeeded event ever fire as a result of a subscription? I'm assuming yes?

delicate condor
#

Hmm i think that might only be for payment mode, but I'd suggest trying out your support flows in test mode to confirm

brittle arch
#

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)

delicate condor
#

Sure, thats separate

brittle arch
#

so, once I'm here, if I want to do an expansion, do I have to do that on a call, to re-fetch?

delicate condor
#

You can't expand in webhook payload, you have to retrieve the object (you said you were retrieving them at the start, i thought)

brittle arch
#

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

delicate condor
brittle arch
#

so I need to 're-fetch', with expansion?

delicate condor
#

Yep

#

well, retrieve for the first time

#

the webhook event delivery is not a retrieval, stripe is sending that to your endpoint

brittle arch
#

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?

delicate condor
#

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)

brittle arch
#

const session = await stripe.checkout.sessions.retrieve(
'cs_test_KdjLtDPfAjT1gq374DMZ3rHmZ9OoSlGRhyz8yTypH76KpN4JXkQpD2G0',
{
expand: ['customer'],
}
);

#

like so?

delicate condor
#

well not customer but yes

brittle arch
#

yes ๐Ÿ˜…

delicate condor
#

expand: ['subscription.latest_invoice'],

brittle arch
#

ok thanks!

delicate condor
#

NP!