#Imdad-webhooks
1 messages ยท Page 1 of 1 (latest)
Hi
On Stripe we have created a Product. We then created a payment link for this product and are using the Stripe checkout feature so that users can use the Stirpe ui to pay for it.
What is the webook event to look out for when a payment is made for the product?
Let me know?
It'll be checkout.session.completed: https://stripe.com/docs/payments/payment-links#handle-fulfillment-with-the-stripe-api
hmm
{
id: 'evt_1KeHIuFYGrqwPVpiocobbl3F',
object: 'event',
api_version: '2020-03-02',
created: 1647515739,
data: {
object: {
id: 'cs_test_a1a2dbuhW3GMmnn3byED3Rtbj4bniaWsbxRBhUceHo4Q2t22oqFaV7SuOh',
object: 'checkout.session',
after_expiration: null,
allow_promotion_codes: null,
amount_subtotal: 3000,
amount_total: 3000,
automatic_tax: [Object],
billing_address_collection: null,
cancel_url: 'https://httpbin.org/post',
client_reference_id: null,
consent: null,
consent_collection: null,
currency: 'usd',
customer: 'cus_LKxDHv6FHSpTnU',
customer_creation: 'always',
customer_details: [Object],
customer_email: null,
display_items: [Array],
expires_at: 1647602134,
livemode: false,
locale: null,
metadata: {},
mode: 'payment',
payment_intent: 'pi_3KeHIoFYGrqwPVpi1AkPPAhL',
payment_link: null,
payment_method_options: {},
payment_method_types: [Array],
payment_status: 'paid',
phone_number_collection: [Object],
recovered_from: null,
setup_intent: null,
shipping: null,
shipping_address_collection: null,
shipping_options: [],
shipping_rate: null,
status: 'complete',
submit_type: null,
subscription: null,
success_url: 'https://httpbin.org/post',
total_details: [Object],
url: null
}
},
livemode: false,
pending_webhooks: 3,
request: { id: null, idempotency_key: null },
type: 'checkout.session.completed'
}
i tested with the stripe webhook cli
theres no reference to the underlying prod_....
?
Yep, that'll be included in the line_items field: https://stripe.com/docs/api/checkout/sessions/object#checkout_session_object-line_items
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
But that's not included by default (it's expandable), so you need to make a follow-up API request to retrieve the Checkout Session
okay
so the sequence of events
- listen for
checkout.session.completed - extract the
session.id - make a call to get session to get the line items (expanded)
- one of these line items (assuming therell just be 1) will contain a reference to underlying product id?
Yep, exactly!
You can see the API shape of the line_items field at the link above
okay great
thansk for that
last
q
so given im using the webhook cli
would i be able to carry out the steps for these stubbed webhook event
Well you'd just make the API request in your webhook handler and then trigger a checkout.session.completed event
You can tell the CLI to send line_items, no. As that's not how it works in production
so im using the stripe cli to trigger the checkout.session.completed event
it gives me back a stub object
in that is the session id right, so i was going to use the get session to get the line items
but my q is, given that im using the webhook cli which returns a stub object
if i did an api request in dev for that stubbed object id
would it return back any line items data
Yes, the CLI creates the actual corresponding objects on your account
So you'll be able to retrieve the Checkout Session object created by the CLI using the API in your webhook handler
okay fab, going to test now
hm
still not seeing the product
am i missing something
It's in the price hash: https://stripe.com/docs/api/checkout/sessions/object#checkout_session_object-line_items-data-price-product
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 also needs expanding apparently
is there any doc on how to expand an object
const lineItems = await stripe.checkout.sessions.listLineItems(sessionId, {
expand: ["data.price"],
})
doesnt seem to be working
That's because you need to do some nested expanding:
const lineItems = await stripe.checkout.sessions.listLineItems(sessionId, {
expand: ["data.line_items.price.product"],
})
ah okay, so its from the root
thanks
okay maybe not
let me try to figure out, the expandable stuff is quite confusing
it seems
Wait
I misread the method you were using
const lineItems = await stripe.checkout.sessions.listLineItems(sessionId, {
expand: ["data.price.product"],
})
Should work
yeah i just tried that
I thought you were doing checkout.sessions.retrieve
Np!
one more q
so you know when a customer checks out
they provide their firstname, surname etc. using the stripe chekcout ui
which stripe object can i find this in?
The default behaviour is for Checkout to create a new Customer object for each session, assuming you don't pass the customer parameter
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Can you share the Checkout Session ID?
cs_test_a1vUS88FXJf5lZc2K1TyFq549Uf7KziQJ8Z3n1ASPbDt52nqPrjCmiNSc1
i think it might just be because this is a stubbed object given by the stripe webhook cli
whereas if it was actually an event in prod, it would contain the relevant details
Hmm, shouldn't be
Can see the Customer object on it: https://dashboard.stripe.com/test/customers/cus_LKy4RFrjYdlL9F
but name is not provided
which is why im guessing it's null
whereas in prod, if the customer gives their name it should be?
Yeah it just sets the default, name isn't required
makes sense, in our stripe checkout ui
we've made name compulsory
so fingers crossed that means it should be there
when the webhook event triggers
Well, to be clear that's compulsory for the billing details of the card
And just so happens to also be used on the corresponding Customer object
yup it works
the name is in there
its just null so all good
based on the above
Right, but customer_details is a different field to customer
yup, that's where i messed up
now im looking at customer
initially was just looking at customer_details
which didnt have the name
All sorted?
yup all good, thanks ๐