#neha_subscription-events
1 messages ยท Page 1 of 1 (latest)
๐ 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/1216845940871401625
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.
- neha_api, 22 minutes ago, 38 messages
- neha_upcoming-prorationdate, 2 hours ago, 48 messages
- neha_best-practices, 2 days ago, 15 messages
- neha_docs, 3 days ago, 25 messages
- neha_best-practices, 3 days ago, 110 messages
- neha_docs, 3 days ago, 26 messages
and 3 more
const newSubscription = await this.stripe.subscriptions.update(
subscriptionId,
{
items: [{ id: subscription.items.data[0].id, price: nextPriceId }],
proration_behavior: "none",
payment_behavior: "pending_if_incomplete",
},
);
// If the Subscription object that's returned contains a pending_update, the payment failed.
// https://docs.stripe.com/billing/subscriptions/pending-updates
if (newSubscription.pending_update == null) {
const newSchedule = await this.stripe.subscriptionSchedules.create({
from_subscription: subscriptionId,
});
await this.stripe.subscriptionSchedules.update(newSchedule.id, {
end_behavior: "release",
phases: [
{
start_date: newSubscription.current_period_start,
end_date: newSubscription.current_period_end,
items: [{ price: newSubscription.items.data[0].price.id }],
},
{
start_date: newSubscription.current_period_end,
items: [{ price: finalPriceId }],
},
],
});
return newSubscription;
}```
this is what i want, visually
i upgrade them to an intermediate plan till the end of their current cycle, then they go back down to the final paln
Hi again ๐ it looks like you have the structure for two phases in there, what is the problem you're trying to solve right now? Are you encountering an error?
but i don't see any record of the subscription schedule in the event log
what's happening is they're immediately going from A => C
They're not making a stop in B, which is what i want (A=>B=>C)
i don't have any errors
so this is supposed to move them from A to B
const newSubscription = await this.stripe.subscriptions.update( subscriptionId, { items: [{ id: subscription.items.data[0].id, price: nextPriceId }], proration_behavior: "none", payment_behavior: "pending_if_incomplete", }, );
Can you share the ID of a Subscription from your testing, where you saw the behavior you're describing?
sub_1OtFQrBZ8IchjqOeRtvkcfMR
{
start_date: newSubscription.current_period_start,
end_date: newSubscription.current_period_end,
items: [{ price: newSubscription.items.data[0].price.id }],
},
{
start_date: newSubscription.current_period_end,
items: [{ price: finalPriceId }],
},
do these need to be off by 1? the start and end dates?
i'm sorry
i think it was my mistkae
Ah, gotcha, a timing issue?
i got the scheule
but the one-time payment didn't happen
const newSubscription = await this.stripe.subscriptions.update(
subscriptionId,
{
items: [{ id: subscription.items.data[0].id, price: nextPriceId }],
proration_behavior: "none",
payment_behavior: "pending_if_incomplete",
// promotion_code: promoCode,
},
);
i want them to pay the full difference between the 2 plans
so that's why i did "pro-ration behavior none"
but instead they paid nothing
hmm
i can't get it to work in the UI eitehr
That sounds expected, because the updated Price won't be billed until the next billing period. Are you also hoping to change the billing period?
if your cycle starts on march 1 and you paid $50
then you upgrade on march 15 to a $80 plan
i want you to pay $30 on march 15, then $80 on april 1
does that make sense?
That's a proration
oh so maybe i should prorate but use the sub_start_date as the proration date?
Sounds like you don't want to suppress prorations
because i want it to be 100% pro-rated
er like, not based on time, just based on value
so not a proration
let me try this
payment_behavior: "pending_if_incomplete",
proration_date: subscription.current_period_start,```
when i create a subscription through the UI, only subscription.created is called? not subscription.updated?
If you're referring to using the Stripe dashboard for that, then I think so, but am not certain that will always be the case. What is the context for the question?
i was just trying to reset my subscription via the dashboard
but i only update my DB on sub.updated
i thought created + updated were always called in tande,
created is when a Subscription is created, updated is when a Subscription is updated, they are usually not sent in tandem
neha_subscription-events
after a checkout session they are
yeah because Checkout will do multiple calls in a row to create/update/confirm the Subscription
ok so across all 4 events:
sub.created
sub.updated
invoice.paid
invoice.payment_failed
should i always fetch the latest subscription details from stripe and update my internal records?
yep that can work
since the events can be sent out of order
i don't love that there's not one "correct" place to do this
where the data attached to the event is trustworthy
The data attached to the Event is a snapshot of the object at the time of Event creation. It's reliable and trustworthy and always correct. But it's not what you use to know "the latest state". If all you care about is the latest state then retrieving that object via the API is your best bet
are there any other events i should be listening to as a sign to update my internal status regarding the subscription?
There are tons of Events depending on what you want to do. We document them all on https://docs.stripe.com/billing/subscriptions/webhooks
But there's no logic that always guarantees you get the latest state since Events are delivered async out of order
will invoice.paid or invoice.payment_failed ever happen in isolation of subscription.created or subscription.updated?
i just have the same util that gets the latest sub and stores a few details in my own table
but it's weird to me to put it in all 4 places.
yes they happen in isolation
so if i simply want to know 1) the subscription priceId and 2) the subscription status, i need to react to all 4 events?
yes