#sidorela_webhooks
1 messages ¡ Page 1 of 1 (latest)
đ 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.
I do not know which event to choose on renew
Assuming the client_reference_id you're referring to is the one passed in when creating checkout session? https://docs.stripe.com/api/checkout/sessions/create#create_checkout_session-client_reference_id
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.
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?
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
Ok
So when you get checkout.session.completed webhook event, you should store the client_reference_id to subscription id mapping in your database
So that way you can know which subscription events are related to which customer reference id
Yeah you need to work backwards
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
It has invoice on the charge object: https://docs.stripe.com/api/charges/object#charge_object-invoice
So you need to retrieve that via the api to see which subscription id the invoice is associated with
this are the events on single payment, invoices are present on subscription
I have no invoice created in this case
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
it was just a random what I sent before
Yeah look at the refunded event json
It has an invoice param
ie this one: evt_3PQt49RpvgHyxzWO18z0pq3G
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
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
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
The alternative would be to list checkout sessions by payment intent: https://docs.stripe.com/api/checkout/sessions/list#list_checkout_sessions-payment_intent
Then get the client reference id from the checkout session returned
what about the subscription renew automaticlly
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
I do not understand how to retrieve client_reference_id from this api calls
looks complicated
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)
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
And look at the client_reference_id attached to the checkout session returned
Ok I will check all docs you sent