#neha_subscription-events

1 messages ยท Page 1 of 1 (latest)

dusk sableBOT
#

๐Ÿ‘‹ 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.

frozen dirgeBOT
#

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.

pseudo sparrow
#
        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

hard kraken
#

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?

pseudo sparrow
#

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", }, );

hard kraken
#

Can you share the ID of a Subscription from your testing, where you saw the behavior you're describing?

pseudo sparrow
#

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

hard kraken
#

Ah, gotcha, a timing issue?

pseudo sparrow
#

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

hard kraken
#

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?

pseudo sparrow
#

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?

hard kraken
#

That's a proration

pseudo sparrow
#

oh so maybe i should prorate but use the sub_start_date as the proration date?

hard kraken
#

Sounds like you don't want to suppress prorations

pseudo sparrow
#

because i want it to be 100% pro-rated

#

er like, not based on time, just based on value

hard kraken
#

so not a proration

pseudo sparrow
#

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?

hard kraken
#

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?

pseudo sparrow
#

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,

frozen dirgeBOT
proper remnant
#

created is when a Subscription is created, updated is when a Subscription is updated, they are usually not sent in tandem

#

neha_subscription-events

pseudo sparrow
#

after a checkout session they are

proper remnant
#

yeah because Checkout will do multiple calls in a row to create/update/confirm the Subscription

pseudo sparrow
#

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?

proper remnant
#

yep that can work

pseudo sparrow
#

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

proper remnant
#

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

pseudo sparrow
#

are there any other events i should be listening to as a sign to update my internal status regarding the subscription?

proper remnant
pseudo sparrow
#

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.

proper remnant
#

yes they happen in isolation

pseudo sparrow
#

so if i simply want to know 1) the subscription priceId and 2) the subscription status, i need to react to all 4 events?

proper remnant
#

yes

pseudo sparrow
#

ok

#

thanks