#Imdad-webhooks

1 messages ยท Page 1 of 1 (latest)

haughty plinth
#

Hey, what's the Q

hallow crystal
#

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?

haughty plinth
hallow crystal
#

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_....

#

?

haughty plinth
#

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

hallow crystal
#

okay

#

so the sequence of events

#
  1. listen for checkout.session.completed
  2. extract the session.id
  3. make a call to get session to get the line items (expanded)
  4. one of these line items (assuming therell just be 1) will contain a reference to underlying product id?
haughty plinth
#

Yep, exactly!

#

You can see the API shape of the line_items field at the link above

hallow crystal
#

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

haughty plinth
#

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

hallow crystal
#

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

haughty plinth
#

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

hallow crystal
#

okay fab, going to test now

#

hm

#

still not seeing the product

#

am i missing something

haughty plinth
#

Which also needs expanding apparently

hallow crystal
#

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

haughty plinth
#

That's because you need to do some nested expanding:

const lineItems = await stripe.checkout.sessions.listLineItems(sessionId, {
  expand: ["data.line_items.price.product"],
})
hallow crystal
#

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

haughty plinth
#

Wait

#

I misread the method you were using

#
const lineItems = await stripe.checkout.sessions.listLineItems(sessionId, {
  expand: ["data.price.product"],
})
#

Should work

hallow crystal
#

yeah i just tried that

haughty plinth
#

I thought you were doing checkout.sessions.retrieve

hallow crystal
#

oh

#

ignore me

#

ace that worked

#

thanks for help!

haughty plinth
#

Np!

hallow crystal
#

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?

haughty plinth
#

The default behaviour is for Checkout to create a new Customer object for each session, assuming you don't pass the customer parameter

hallow crystal
#

this is what i get when i expand the customer in the Session object

haughty plinth
#

Can you share the Checkout Session ID?

hallow crystal
#

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

haughty plinth
#

Hmm, shouldn't be

hallow crystal
#

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?

haughty plinth
#

Yeah it just sets the default, name isn't required

hallow crystal
#

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

haughty plinth
#

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

hallow crystal
#

ah okay

#

sweet

haughty plinth
#

I can see the customer field there

#

Is expand not working?

hallow crystal
#

yup it works

#

the name is in there

#

its just null so all good

#

based on the above

haughty plinth
#

Right, but customer_details is a different field to customer

hallow crystal
#

yup, that's where i messed up

#

now im looking at customer

#

initially was just looking at customer_details

#

which didnt have the name

haughty plinth
#

All sorted?

hallow crystal
#

yup all good, thanks ๐Ÿ‘Œ