#beltran_upcoming-invoices
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/1222950481471471699
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
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
}
];
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?
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
}]
}
]
}
)
Thank you, and can you tell me more about the innacuracies?
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
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
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
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
You should just need to provide the string "now"
Nice!
Hmmm
Maybe not yet, but close
I just tried it with a coupon and it's not taking into account the coupon discounted amount
๐ hopping in here since pompey has to head out soon
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
Hmmm.. do you have an example subscription I can take a look at and the request ID for you upcomoing invoice request?
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
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?
Sure, but it is very long:
That's fine!
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
beltran_upcoming-invoices
The amounts charged in the subscription definitely took into account the coupon
Did you maybe send me the wrong subscription/invoice? If I look at sub_1OzMNQFS82LK7Jj2JafACSEz, it was created in this request https://dashboard.stripe.com/test/logs/req_A18exeAnbYSDYB which has no coupon
Yeah, I think that is a different event
Are you looking at this one: req_VhCUDphgiidjTN?
Ah, then can you send the output of the upcoming invoice request for that specific subscription? sub_1OzMcQFS82LK7Jj2buYI1izt
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).
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
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