#beltran_upcoming-invoices

1 messages ยท Page 1 of 1 (latest)

twin raftBOT
#

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

๐Ÿ“ Have more to share? Add more details, code, screenshots, videos, etc. below.

tame wrenBOT
mellow scroll
#

The `items" value in the sample code above is an array of objects as follows
const items = [
{
id: customerDoc.subscriptionItemId,
deleted: true,
},
{
price: subscriptionPriceId,
quantity: 1
}
];

dark cave
#

Hello, that retrieve upcoming endpoint should be able to do this. Can you send me the code for your update call as well and give me a bit more detail about what isn't accurrate from the upcoming endpoint's invoice?

mellow scroll
#

Sure

#

Here is the actual update call:

#

var subscription = await stripe.subscriptionSchedules.update(
subscriptionSchedule.id,
{
end_behavior: "release",
phases:[
{
start_date : subscriptionSchedule.current_phase.start_date,
end_date: subscriptionSchedule.current_phase.end_date,
items: [{
price: PremiumPriceId
}]
},
{
start_date: subscriptionSchedule.current_phase.end_date,
items: [{
price: BasicPriceId
}]
}
]
}
)

dark cave
#

Thank you, and can you tell me more about the innacuracies?

mellow scroll
#

Let's suppose a user initially subscribes to our Basic plan, which is $49/month, and sometime later is thinking of upgrading to Premium which is 99$/month. The response from the call to invoices.retrieveUpcoming() that I have returns in the line key:
โ€ข data[0] description: "Unused time" this amount is -49.00 it's the user's credit and is correct
โ€ข data[1] description: "Remaining time" this amount is <99.00 it's the user's debit and is incorrect because it should be exactly 99.00

#

The reason the latter is incorrect is because it assumes the start date of the new billing cycle doesn't change, when in reality it starts anew

dark cave
#

Can you try setting subscription_billing_cycle_anchor to now? That is the parameter that tells us to start the cycle anew. I think because you specify a proration date we should treat that date as "now" https://docs.stripe.com/api/invoices/upcoming#upcoming_invoice-subscription_billing_cycle_anchor

mellow scroll
#

Sure. I'll try it right now

#

Should I pass the same value as in subscription_proration_date? That would be Math.floor(Date.now() / 1000)

#

Oh, it's supposed to be a string

#

One sec

dark cave
#

You should just need to provide the string "now"

mellow scroll
#

Looks like it worked

#

Haha

#

Thank you

#

Very much

tame wrenBOT
dark cave
#

Nice!

mellow scroll
#

Hmmm

#

Maybe not yet, but close

#

I just tried it with a coupon and it's not taking into account the coupon discounted amount

shell drift
#

๐Ÿ‘‹ hopping in here since pompey has to head out soon

mellow scroll
#

Before adding the subscription_billing_cycle_anchor: "now" it did take into account the exisitng coupon

#

Sounds good

#

Let me know @shell drift . Pompey's solution is almost there, but it looks like the coupon discount is no longer taken into account, whereas in the actual subscription.update() I pasted above it is. So the amounts are different

shell drift
#

Hmmm.. do you have an example subscription I can take a look at and the request ID for you upcomoing invoice request?

mellow scroll
#

Sure

#

One sec

#

I'll send the request IDs for the initial subscription with a coupon and the plan upgrade update that we are trying to mimic with invoices.retrieveUpcoming()
โ€ข Initial subscription to basic: req_VhCUDphgiidjTN
โ€ข Upgrade to premium: req_Ui35zwtW7E4NAG

#

Oh wait

#

It's req_Ui35zwtW7E4NAG

shell drift
#

And you're saying that the coupon isn't included at all in the response you get from the retrieve upcoming invoice? Do you mind copy-pasting the full response you get back from the upcoming invoice request?

mellow scroll
#

Sure, but it is very long:

shell drift
#

That's fine!

mellow scroll
shell drift
#

That susbcription didn't have a coupon to begin with - so it'd be expected that there's no coupon being applied to future invoices

twin raftBOT
#

beltran_upcoming-invoices

mellow scroll
#

The amounts charged in the subscription definitely took into account the coupon

shell drift
mellow scroll
#

Yeah, I think that is a different event

#

Are you looking at this one: req_VhCUDphgiidjTN?

shell drift
#

Ah, then can you send the output of the upcoming invoice request for that specific subscription? sub_1OzMcQFS82LK7Jj2buYI1izt

mellow scroll
#

Ah, yes

#

I have to do the whole thing again

#

Give me a sec.

#

Initial subscription to Basic: req_h7lBq86f7JHnyA
Upgrade to Premium: req_AQy2abc0Xk1UfC

Attached is the upcoming invoice request for the upgrade to Premium (returned before the upgrade event).

shell drift
#

That output does from the upcoming invoice request actually matches the output you're getting from your upgrade request.

The output you sent over has "amount_due": 2500, and includes the discounts di_1OzN9kFS82LK7Jj2r166OP9N, both of which match what is in the latest_invoice from request req_AQy2abc0Xk1UfC

mellow scroll
#

Gotcha. So the amount_due says how much the user will pay. That works. However, is there a way to see how much the coupon discount is? I know it's 44.50 but I don't see it anywhere in the proration. I see the credit for unused time, which is -24.5, but not the discounted amount from the debit.

#

I think I just saw it

#

Nope

#

Ah, my bad the discount is 49.50 and I do see it in the invoice

shell drift
#

Are you trying to get the discount of the original proration, or just how much is discounted on this invoice? If you want the amount discounted on this invoice you can find it in total_discount_amounts

#

๐Ÿ‘

mellow scroll
#

Yes

#

Thank you

#

That is all

#

Bye bye