#sidorela_webhooks

1 messages ¡ Page 1 of 1 (latest)

vagrant orioleBOT
#

👋 Welcome to your new thread!

⏲️ We'll be here soon! We typically respond in a few minutes, but in some cases we might need a bit more time (e.g., server's busy, you've got a complex question, etc.).

⏱️ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can start a new thread if you have another question.

🔗 This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1250820413705945118

📝 Have more to share? Add details, code, screenshots, videos, etc. below.

spark panther
#

I do not know which event to choose on renew

dull heron
spark panther
#

I need to use only client_reference_id because only that can be different, client can have many like that. On checkout successful I could get it but on refund I can not.

dull heron
#

Yeah that client reference id is only stored on the checkout session object

#

So why can't you use the customer id in Stripe exactly?

spark panther
#

because my customer may create subscriptions or buy many products with same user but with client reference id different as we store in db by that not with customer info

dull heron
#

Ok

#

So when you get checkout.session.completed webhook event, you should store the client_reference_id to subscription id mapping in your database

spark panther
#

yes

#

but on refund I need to update again in db

dull heron
#

So that way you can know which subscription events are related to which customer reference id

#

Yeah you need to work backwards

spark panther
#

yes

#

exactly

dull heron
#

So you get the invoice id in the refund event

#

Retrieve that invoice and see which subscription it belongs to

#

You'll then check your database for the client reference id

spark panther
#

I have not invoice on refund

#

it this the event of refund
charge.refunded

dull heron
#

So you need to retrieve that via the api to see which subscription id the invoice is associated with

spark panther
#

this are the events on single payment, invoices are present on subscription

dull heron
#

Yes

#

What's your question exactly?

spark panther
#

I have no invoice created in this case

dull heron
#

Can you share the event id? If it's the same one you shared earlier, it has an invoice. I checked

#

Look at the event body

spark panther
#

it was just a random what I sent before

dull heron
#

Yeah look at the refunded event json

#

It has an invoice param

#

ie this one: evt_3PQt49RpvgHyxzWO18z0pq3G

spark panther
#

evt_3PQrmfRpvgHyxzWO0a0R9v3G

#

you can check this event

dull heron
#

That's because that payment intent isn't associated with a subscription

#

So it wouldn't have an invoice

#

It's from a payment mode checkout session

#

For those you'd need to store a client_reference_id to payment intent (or charge id) mapping your database

#

Upon receiving checkout.session.completed

spark panther
#

I need to retrieve this client_reference_id on refund to update the exact matching document in mongodb

#

this is that I do not understand

#

how to retrieve it client_reference_id

dull heron
#

It's tied to the checkout session

#

So my recommendation is to store the client_reference_id to subscription (or payment intent if it's a payment mode checkout session) mapping in your database when you receive the checkout.session.completed event

#

That way when you receive charge.refunded, you can check this mapping in your database to know the client_reference_id

#

Otherwise, you'll have to make additional api calls

#

Then get the client reference id from the checkout session returned

spark panther
#

what about the subscription renew automaticlly

dull heron
#

It's the exact same concept

#

There's multiple events you can choose from

#

Recommend doing invoice.paid though

#

But same concept as above

#

Recommend storing the subscription to client_reference_id mapping ahead of time in your db

#

So you can just check that and not have to make an api call

spark panther
#

I do not understand how to retrieve client_reference_id from this api calls

#

looks complicated

dull heron
#

Ok I explained a few times above. My recommendation is to listen to checkout.session.completed events. In those events, you'll get the checkout session object. Then, you can store a mapping of the client_reference_id received in that event: https://docs.stripe.com/api/checkout/sessions/object#checkout_session_object-client_reference_id to the subscription id or payment intent id (if it's a payment mode checkout session): https://docs.stripe.com/api/checkout/sessions/object#checkout_session_object-subscription or https://docs.stripe.com/api/checkout/sessions/object#checkout_session_object-payment_intent. For subscription renewal, if you listen to invoice.paid events, you'll have the subscription id on those events: https://docs.stripe.com/api/invoices/object#invoice_object-subscription. You can check your database for the subcsription id to client_reference_id mapping and see what client it was. For refunds, I explained how to do this above here: #1250820413705945118 message

#

The alternative is to just list checkout sessions each time you receive an event (not recommended as it's more api calls)

#

And look at the client_reference_id attached to the checkout session returned

spark panther
#

Ok I will check all docs you sent