#joe_unexpected
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/1352411667170070658
π Have more to share? Add more details, code, screenshots, videos, etc. below.
Hi! Can you share the ID of the subscription, and the request for your upcoming invoice API call?
Subscription ID: sub_1R4rvMK2Tf1SdvM0Lu0DXIMH
Upcoming Invoice API request:
Invoice.upcoming(
customer='cus_RuuaQaPUVwpBpk',
subscription='sub_1R4rvMK2Tf1SdvM0Lu0DXIMH',
subscription_details={
"items": [{'id': 'si_Rypa97OpYQYl5V', 'price': 'price_1R15B8K2Tf1SdvM00HPA0EkQ', 'quantity': 2, 'discounts': [{'coupon': '10_percent_discount'}]}, {'id': 'si_Rypapq79n9FM7w', 'price': 'price_1R15B7K2Tf1SdvM0FAF6B7Je', 'quantity': 1, 'discounts': [{'coupon': '10_percent_discount'}]}],
"proration_behavior": "always_invoice",
},
)
Response: attached
Actually, it's 2 upcoming invoice requests to 2 subscriptions, this was the first one, I'm sending the next one.
The issue is in the second one, my apologies, but they sometimes shuffle.
No worries. I'll wait until the second one. π
2nd Upcoming Invoice API request:
Invoice.upcoming(
customer='cus_RuuaQaPUVwpBpk',
subscription='sub_1R4ruoK2Tf1SdvM0eGnrca5i',
subscription_details={
"items": [{'id': 'si_RypZVkYpDZQkoM', 'price': 'price_1R15JZK2Tf1SdvM0KTEA7ynv', 'quantity': 2, 'discounts': [{'coupon': '10_percent_discount'}]}, {'id': 'si_RypZZp8bZiVGJV', 'price': 'price_1R15JZK2Tf1SdvM0Ou7299Bi', 'quantity': 1, 'discounts': [{'coupon': '10_percent_discount'}]}],
"proration_behavior": "always_invoice",
},
)
Response: attached
The amount due is 4759, not sure why it's less than the first upcoming invoice.
What do you mean 'less than the first ... invoice'?
The 2 subscriptions should be the same in terms of quantity and discount. So that when I alter them by adding an extra 1 quantity, the upcoming invoice for each should be the same.
Ah
I know this may sound confusing, but let me know how I can help you to understand it better.
No, it makes sense. I am helping a half dozen people but I'm digging into this for you. π
Thanks mate, yeah take your time π
The difference is, I think, coming from the lack of discount on the proration adjustment on the first one.
I'm not sure why that's happening yet.
Yes, thatβs what I concluded as well. Not sure why. Even though the request contains the discounts.. does it not expect to re-add the same discount?
It would add it; if it was there previously it would 're-add' it.
Which one is right?
The second one?
It doesn't expect anything. Still digging, sorry.
Itβs okay take your time
When you created the 'incorrect' one, it was created with a discount.
When you created the 'correct' one, it was created without discounts, and then you updated it to add discounts at Mar 20, 2025 22:50 GMT
Your upcoming Invoice was run at Thu Mar 20 2025 22:52:42 GMT so it should have included those discounts.
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
You have a lot of identically named items in your test account; I'd suggest cleaning that up, and trying this again, and seeing how it goes - I think the second one was actually the one that seems to have rendered incorrectly as it should have also had the discount applied on the proration too.
I unfortunately have to run - well, I had to run 45 minutes ago π€ͺ - but someone will be online again in about 7 1/4 hours.
Cheers!
Cheers mate, is there someone else over here?
Hi, yes. How can I help?
Hi there, umm do you see the previous chat? or do I re ask the question?
Can you summarize the outstanding question please?
Yes sure. I'm using the upcoming invoice API, and it's inaccurate, not sure what caused this.
So I have 2 different subscriptions, with Subscription Items and discounts on the Items.
What I am doing is I want to anticipate the upcoming invoice if I increase the quantity of the subscription items in both.
I'm calling upcoming invoice API twice (once for each). and the amount due is inaccurate in one of them.
I have the proration set as "always_invoice", from what I understand, the items are removed (credited) then re-added. The issue is in the crediting or removing.
The amount credited is the original price, not the discounted price.
We document this here: https://docs.stripe.com/billing/subscriptions/prorations#prorations-and-discounts
Any adjustments from discounts are reflected in the proration invoice itemβs amount. Additional discounts at the invoice item level or invoice line item level donβt apply to prorations because they have discountable=false.
How are the discounts applied? Are you able to review the above?
The discount is applied on the Subscription Item level, and in the upcoming invoice API, the method is called like this:
Invoice.upcoming(
customer='cus_RuuaQaPUVwpBpk',
subscription='sub_1R4ruoK2Tf1SdvM0eGnrca5i',
subscription_details={
"items": [{'id': 'si_RypZVkYpDZQkoM', 'price': 'price_1R15JZK2Tf1SdvM0KTEA7ynv', 'quantity': 2, 'discounts': [{'coupon': '10_percent_discount'}]}, {'id': 'si_RypZZp8bZiVGJV', 'price': 'price_1R15JZK2Tf1SdvM0Ou7299Bi', 'quantity': 1, 'discounts': [{'coupon': '10_percent_discount'}]}],
"proration_behavior": "always_invoice",
},
)
The thing is, this issue occurs for 1 of the subscriptions, and not on the other
While both have the same settings in terms of quantity and discounts, just different prices.
How was the discount created? Did you limit it to certain products, https://docs.stripe.com/payments/checkout/discounts?payment-ui=stripe-hosted#limit-eligible-products?
This is an example:
Subscription.create(
customer=customer_id,
items=[
{
"price": price.stripe_id,
"discounts": [{"coupon": item_discount}]
}
]
)
It's on the Subscription Item level.
The discount itself is created as a coupon.
Coupon.create(
id=payload["id"],
name=payload["name"],
percent_off=payload["percent_off"],
amount_off=payload["amount_off"],
duration=payload["duration"],
duration_in_months=payload["duration_in_months"],
)
One of the invoices, in_1R4rvMK2Tf1SdvM0u3dimAKV has a discount as you passed a discount, https://dashboard.stripe.com/test/logs/req_NJ9k3mdZf8LrD8. However, the other one, in_1R4ruoK2Tf1SdvM0FMfkIo84 does not as you did not pass the discount, https://dashboard.stripe.com/test/logs/req_9kNhmKzeTJahfw. So you're not comparing two different behaviors
I highly recommend that you try creating this scanario from scratch by following identical steps.
Okay sure, I can retry, but is the issue in the current subscription items? or the upcoming invoice call?
I can see both subscriptions are almost the same:
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
These are current, they were created on 3/20. However, you said the upcoming incoices showed different results... and I'm saying since you passed a discount on one and not the other when you created the subscription, you're not comparing the exact same scenarios
No, sub_1R4ruoK2Tf1SdvM0eGnrca5i does not have the discounts
I do not have direct access to that so let's look at the requests instead: https://dashboard.stripe.com/test/logs/req_9kNhmKzeTJahfw
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
I see what you mean.
But what I do is
once the second subscription is created (with a discount), I modify all existing subscriptions and add a discount to them through the webhook.
It's like a promo for the users, if they subscribe to more items, they get discounts on all existing.
So you'd want to create that scenario exactly and then compare the two
Yes exactly
I'll be here while you test
It's not actually a comparison, I just want to figure what the user has to pay
This is the current scenario π
Yeah - on the same page
I'm sorry if I'm confusing you.
Your main question is 'why is this behaving different on the discount on these two subscriptions?' What I'm saying is that you're not comparing the exact same scenarios so they would not be identical.
As a next step, you'd want to test this from scratch, create the subscription, the update subscription with the discount, then use the upcoming invoice API to attain the amount you're seeking for.
I'll be here while you test
Alright, I'll create them from scratch
Just created this subscription: https://dashboard.stripe.com/test/subscriptions/sub_1R55lPK2Tf1SdvM0JowPSFuM (without a discount).
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
Now, I added another subscription: https://dashboard.stripe.com/test/subscriptions/sub_1R55mPK2Tf1SdvM0MIJcltaX (with a discount).
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
And in the webhook, it updated the previous subscription and added a discount.
Everything is fine until now.
I then added another subscription item to each of them (indicates a team member) - and this is correct amount.
Now, when I need to increase the quantity, the upcoming invoice is inaccurate.
What amount did you expect vs what you see with what changes?
Current: 95.20
Expected: 107.10
Should I paste the upcoming invoice params?
I have the responses as well.
Btw the amount is the sum of 2 upcoming invoice calls (one for each subscription).
Hmm, why would you want the sum of 2 upcoming invoice calls?
Yes please, if you can share those it would be helpful
Yes sure, I want the user to pay once, and I need to show them what they will pay, and since it's 2 subscriptions, it's going to be 1 for each. So I create 1 bulk invoice with the invoice items generated from the upcoming invoices.
Why do you have two separate subscriptions? What is the use case?
Request:
InvoiceService(user.site.id).upcoming_invoice(
customer_id='cus_RuuaQaPUVwpBpk',
subscription_id='sub_1R55lPK2Tf1SdvM0JowPSFuM',
subscription_items=[{'id': 'si_Rz3weh6uDDRP80', 'price': 'price_1R15JZK2Tf1SdvM0KTEA7ynv', 'quantity': 2, 'discounts': [{'coupon': '10_percent_discount'}]}, {'id': 'si_Rz3ttwhMFBTkKo', 'price': 'price_1R15JZK2Tf1SdvM0Ou7299Bi', 'quantity': 1, 'discounts': [{'coupon': '10_percent_discount'}]}],
)
Response:
The user subscribes to a product, then later they subscribe to another one.
The user can add team members to their subscriptions with a discounted price.
If the user is subscribed to 2 or more products they get 10% discount on the subscription items in any active subscription.
The data I sent you was for one of the invoices, which is the one that fails, it shows 4759 as the amount due.
While it should be 5355
To simplify this, I think you could have one subscription and just update the subscription with adiditonal products as subscriptions can have multiple products: https://docs.stripe.com/billing/subscriptions/multiple-products
This might make managing things a bit easier on your end and you would not need to do any manual calculations between the two subscriptions to surface the upcoming invoice amount.
π¦
I can't modify the implementation now, it would be great if I can just understand why this is happening.
Fair, looking at the response, hang tight
Thank you mate
Why should it be 5355? because I'm increasing the quantity of a price that costs 59.5 that has 10% discount = 53.55.
From looking at that response, it looks like prorations are working as expected. I do not think you're accounting for the 'Unused time' and 'Remaining time' from the previous invoice. I think you'd want to pass 'proration:none': https://docs.stripe.com/api/invoices/upcoming#upcoming_invoice-subscription_proration_behavior
You can confirm this by looking at the description under lines.data
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 thing is the Unused time doesn't consider the discount.
So it credits the original price not the discounted price.
I'm okay with the proration as it is, the user only has to pay what's left in the subscription.
But not sure why the Unused time is crediting the original price not the discounted price.
I think I undertand now, it credits the paid amount. When I created these items originally they didn't have a discount? is this the case?
I'm not sure how I'm supposed to solve it, it's an issue.
That is right, and this is working as expected. You can confirm this by looking at ' "discountable": false,' under lines.data. We explain this here: https://docs.stripe.com/billing/subscriptions/prorations#prorations-and-discounts
I see, how can I set them to True? and at which stage?
Can you pass the discount here: https://docs.stripe.com/api/invoices/upcoming#upcoming_invoice-discounts instead of the subscription items, https://docs.stripe.com/api/invoices/upcoming#upcoming_invoice-subscription_items?
I cannot, because some of the items in my use case may not be discountable.
In that case, you'd want to create prices that are already discounted
I see, it's unfortunately getting so much more complex.
It will be harder to track them, but I will give it a go.
Is there anything else you can advice me to go for?
You can add metadata to these objects, https://docs.stripe.com/metadata to make tracking better.
I truly think your flow would be much easier if you create one subscription and then just update them when they want to add more products. It might be something you test out first and ensure that it fits your business use case fully.
This way, you would not need to add the total amount from the two invoices to show the full amount