#bruce-zhang_webhooks

1 messages ¡ Page 1 of 1 (latest)

reef waveBOT
#

👋 Welcome to your new thread!

⏲️ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.

⏱️ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always 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/1221646111618367570

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

warm haloBOT
zenith glen
#

Which webhook event do you expect the metadata to be in?

azure girder
#

The metadata will contains some information about the plan that user choose. We know what plan the user choose when checkout session is created at the frontend, and we want to let backend knows it when the webhook event is received.

#

payment_intent.succeeded

#

If this is the best event that can let us know user successfully pays for a subscription product in checkout session

zenith glen
#

If this is the best event that can let us know user successfully pays for a subscription product in checkout session
I'd recommend using checkout.session.* events for the subscription sign up using Checkout Session. Here's the guide on how to get the payment status in a Checkout Session via these events: https://stripe.com/docs/payments/checkout/fulfill-orders

Learn how to fulfill orders after a customer pays with Stripe Checkout or Stripe Payment Links.

azure girder
#

Do you mean this event?
checkout.session.completed

zenith glen
azure girder
#

If the payment fails, the checkout.session.completed event will still sent to webhook, is that correct?

#

Because I see that the next steps for checkout.session.completed is waiting for payment success

#

I think we want to update our database only after payment is successful

zenith glen
#

If the payment fails, the checkout.session.completed event will still sent to webhook, is that correct?
No. checkout.session.completed event will only be sent when the customer completes the payment:

  • For synchronous payment methods - the payment outcome will be immediate on checkout.session.completed event
  • For asynchronous payment methods - checkout.session.completed event will inform you that the payment is still processing. Separate events will be sent for the payment outcome

You'd need to check the payment_status of the checkout.session.* event: https://docs.stripe.com/api/checkout/sessions/object#checkout_session_object-payment_status

Alternatively, invoice.paid event is recommended for successful subscription payment: https://docs.stripe.com/billing/subscriptions/overview#subscription-lifecycle

Learn how subscriptions work within Stripe.

azure girder
#

I think invoice paid can be great since it can check first time subscription (at checkout session), recurrent charge (renew subscription), and update subscription (at customer portal) in our case.

#

will invoice.paid also be sent when subscription plan is updated in customer portal?

zenith glen
#

We recommend to use invoice.paid events throughout subscriptions

#

will invoice.paid also be sent when subscription plan is updated in customer portal?
Yes - invoice.paid event is not integration path dependent. As long as the invoice is paid successfully, this event will be sent

azure girder
#

Is there a way to add metadata at the front end when I trigger either the checkout session or customer portal and retrieve the metadata in webhook through invoice.paid event?

zenith glen
#

Yes! You can set the metadata in subscription_data.metadata: https://docs.stripe.com/api/checkout/sessions/create#create_checkout_session-subscription_data-metadata

This metadata will be available in subscription_details.metadata on the Invoice object in invoice.paid event: https://docs.stripe.com/api/invoices/object#invoice_object-subscription_details-metadata

#

I'd recommend giving it a try in test mode

azure girder
#

I have tried the test mode! I will test the metadata. Thanks!