#mikeybelike - subscription events
1 messages · Page 1 of 1 (latest)
What do you mean by "inline" product?
All subscription creations or cancelations are customer.subscription.created and .deleted
https://stripe.com/docs/api/events/types#event_types-customer.subscription.created
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
The best event for recurring invoice payments is invoice.paid, which would include teh subscription id in the payload
by inline, I mean a product that isn't predefined in Stripe. e,g
<?php
$checkout_session = \Stripe\Checkout\Session::create([
'customer' => $stripeCustomer,
'line_items' => [
[
'price_data' => [
'currency' => $currency->code,
'product_data' => [
'name' => "Payment for $name",
],
'unit_amount' => $amount * 100,
'recurring' => $subscription ? [
'interval' => 'month',
'interval_count' => 1,
] : []
],
'quantity' => 1,
]
],
'mode' => $subscription ? 'subscription' : 'payment',
'expires_at' => time() + 3600,
'metadata' => [
'user_id' => $user->id,
'anon' => $anon
]
], $intentObjOptions);
also what about if the subscription invoice is NOT paid, what event should I listen out for here?
Do you mean the first invoice when starting or any future invoice? When charging automatically, payment failures produce invoice.payment_failure events.
okay that's good to know. is there a difference between the first and subsequent recurring ones? Currently i've been using checkout.session.completed for the initial one is this best practice?
That will only exist for the initial subscription creation
but yes that will correspond to your customer completing checkout, which would also indicate successful payment of the first invoice (unless you use a trial period).
Okay basically the idea is I want to give user roles based on the subscription, is this a good plan:
- Use
checkout.session.completedfor the initial subscription payment - award role on receipt of this webhook event - Listen for
invoice.paidorinvoice.payment_failureto decide whether to keep the users role or to remove them - Maybe another event to listen to if they manually cancel the subscription to remove the role? Does one exist?
The cancelation would only happen if you settings/integration enabled it, and you'd get the customer.subscription.deleted event in that case
Be careful of payment failures and your retry logic, you may want to wait longer than just one payment failure before revoking access
but thats up to you
Thank you, that's solid advice^
Read more about retry logic/handling herE: https://stripe.com/docs/billing/revenue-recovery
perfect, thank you for your patience!
NP! happy to help
would you say the above plan is good practice though?
Generally yes - i'd say following the successful setup you just default to keeping it active until a future failure/cancellation
You cna use the billing settings to auto-cancel following all payment retry failures if you prefer, and rely on that cancellation event.
awesome thanks again!
now is there a way I can save this thread to view quickly in future?
You can copy the link to your message if you want: https://discord.com/channels/841573134531821608/961356572347494401
But it might be best to copy paste the text for reference into a separate document