#Rohit89
1 messages · Page 1 of 1 (latest)
Hi! Let me help you with this.
You can listen to the checkout.session.completed event: https://stripe.com/docs/api/events/types#event_types-checkout.session.completed
The data.object is a Checkout Session: https://stripe.com/docs/api/checkout/sessions/object
but for recurring monthly payment, will this event initiated?
If it is created via Checkout Session - yes, but only once.
yea.. what should I check for recurring monthly payment? Customer is subscribed to monthly plan..
You can try customer.subscription.updated - https://stripe.com/docs/api/events/types#event_types-customer.subscription.updated
Which will return Subscription object with items property: https://stripe.com/docs/api/subscriptions/object#subscription_object-items
The even is created every time a new subscription period starts, e.g. monthly.
Ok. Customer.subscription.updated event is initiated every month if it is monthly subscription. ??
But technically the plan is not updated, so how I would know it just deducting the monthly amount not updating the subscription to another plan .... because upgrading a plan also call customer.subscription.updated
Yes
Yes, every month/period a few properties are updated automatically, e.g. current_period_start : https://stripe.com/docs/api/subscriptions/object#subscription_object-current_period_start
This triggers the event.
Charging monthly or upgrading to new plan via portal... both initiate Customer.subscription.updated
How I would know which is upgrading a plan vs just monthly payment for existing plan?
data.previous_attributes contain properties that were updated: https://stripe.com/docs/api/events/object#event_object-data-previous_attributes
There is no event that would work for both one time payment via checkout session or recurring via subscription, to get details like line items, quantity?
You can get line items at any time if you have the subscription ID, you don't need to rely on the webhook events: https://stripe.com/docs/api/subscriptions/retrieve
yeah but I would like to get when payment happens each month automatically?
cant we use invoice.paid response?
Yes
Wether it is one time payment via checkout session or monthly via subscription --- invoice.paid this will be initiated.
Correct?
Yes
If subscription is created I can see - "billing_reason": "subscription_create" in the invoice.paid webhook response
For monthly payment but will be the billing reaon?
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
I just checked when I do one time payment via checkout session mode: payment...
invoice.paid is not iniated.
Correct. We only create invoices for one-time payments if you explicitly opt-in to that feature: https://stripe.com/docs/payments/checkout/post-payment-invoices
- payment_intent.created
- payment_intent.succeeded
- charge.succeeded
- checkout.session.completed
it triggers these 4
if mode is subscription then invoice:paid is initiated ?
Yes, always assuming the session is completed
if we have 10 days trial at start of subscription, then there will be no invoice. But after 10th day invoice will be generated
and invoice.paid will be triggered
There will still be an initial invoice and subsequent invoice.paid event in cases of a free trial
let me check
I have checked for 10 days free trial. Subscription is created.
It initiate invoice.payment_succeeded event but not invoice.paid
sub_1MRbDyLv5rdhLZWUURNkSR5A
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
We have following scenario.
- Customer can subscribed to monthly or yearly plan via checkout session.
- Customer can do one time payment to purchase anything
In both case which is best event that tell us if it is just subscription created or charging monthly for existing subscription or one time payment for a purchasing any asset.
yeah got it.. missed the logs
one time payment for a purchasing any asset
Probablycheckout.session.completed: https://stripe.com/docs/payments/checkout/fulfill-orders
if it is just subscription created or charging monthly for existing subscription
invoice.paidand use thebilling_reasonfield to determine the cause
For one time , We should check checkout.session.completed and get the id of payment intent when succeeded and then list the checkout session. because checkout session will be completed even if payment is pending
correct?
if it is just subscription created or charging monthly for existing subscription
invoice.paid and use the billing_reason field to determine the cause. Correct?
If user upgrade the plan. Then also invoice paid?
Depends on what payment methods you're supporting. For example, card payments are synchronous so will also be successful once the session is completed. A little more complex for async banking methods (details at the link above)
It is card..
Yep, and I think billing_reason is subscription_update
So we are thinking to use payment.intent.succeeded ... list the session completed in case of one time payment
Then checkout.session.completed event will always correspond with a successful payment. Check the payment_status field on the event to confirm: https://stripe.com/docs/api/checkout/sessions/object#checkout_session_object-payment_status
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Ok, When I had conversation here yesterday I have been told to payment.intent.succeeded because sometimes session is completed but payment is pending
Yes, if using an async payment method. See: https://stripe.com/docs/payments/checkout/fulfill-orders#delayed-notification
But if just cards then that'll never be the case
What will be the billing reason if it charge for next month for existing subscription?
in invoice.paid
I don't understand the question
If I have monthly plan subscribed today.. what will be the billing reason when next month invoice will be paid
recurring payment for same subscription
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
subscription_cycle
Ok so if we sum-up our conversation.
- For one time payment using checkout - Use the checkout.session.completed to get all the details. If the payment is only card.
- For recurring payment that is created via monthly or yearly subscription. - Use the invoice.paid and check the billing_reason field to determine the cause that will be subscription_cycle
- If it is upgrade a plan - Use the invoice.paid and check the billing_reason field to determine the cause. billing_reason should be subscription_update.
- When subscription created first time - Use the customer.subscription.created or invoice.paid and check the billing_reason.
correct?
Yep, sounds right. All of this should be easy enough to test, especially with a billing test clock
billing test clock? how? any doc