#Eranga
1 messages ยท Page 1 of 1 (latest)
Can you share the subscription ID or request ID?
Sure
There are few
Because of different scenarios
sub_1Lu7xjC8JGuaUdU67HVe8S4N
The above one is with a discount
This is a subscription without a discount sub_1K13BIC8JGuaUdU60tD1KntB
I don't quite understand your question
Sorry, let me give you a bit more information
Can you explain more what is the expected outcome you're looking for and the problem you're facing?
I am building a UI where it shows the description of the upcoming invoice when the user do changes to the subscription.
Let's say one of my customer has a coupon attached to the subscription and they try to modify the quantity
Then, I am going to show something like this
And if there is no coupon applied, I want to show the description like this.
To do this, I need to differentiate different invoice items in the upcoming invoice
Am I clear so far? ๐ผ
(BTW this is the same thing we can see in the invoice generated by Stripe)
Yup, it's clear so far! Let me check and get back to you
Am I right to understand you would like to know how to differentiate the line item with discounts in upcoming invoice, so that you can display the information accordingly?
Yes, that is what I am trying to achieve
If the upcoming invoice line item has a discount, it will contain discount_amounts
Cool, so it is okay to rely on the length of discount_amounts to be greater than 0 , right?
You can use discount_amounts to determine a discount has been applied to the line item
However, the discount amount is already within the invoiceLineItem.amount of the invoice item. The discount_amounts[0].amount will be 0. This is not an issue, right?
One way is to check that discount_amounts is not an empty array. If it's not empty, then a discount is applied
The amount on line items for unused and remaining is usually 0
Great, that is very helpful ๐. Thank you
No problem! Happy to help ๐
Now for a bit more complex question on the same topic ๐
When the subscription has a one-time coupon applied, the behavior will be different.
stripe invoices upcoming \
--customer=cus_MbrCNS72FGY29A \
--subscription=sub_1Lu94iC8JGuaUdU6hAI8xgD2 \
--subscription-proration-behavior="always_invoice" \
--data "subscription_items[0][id]"=si_MdPuhiFYPls20p \
--data "subscription_items[0][quantity]"=20 \
--data "subscription_items[0][price]"=price_1K7BEwC8JGuaUdU6DUNs8JTW
We can see
"Unused time on 10 ร Standard (with 40.0% off) after 20 Oct 2022"
"Remaining time on 20 ร Standard after 20 Oct 2022"
So one description has the discount, and the other does not.
In this scenario, what we discussed earlier would be false
Both invoice items will not have any element in discount_amounts
How do you suggest we handle this case? ๐ผ
I took a look at sub_1Lu94iC8JGuaUdU6hAI8xgD2 and discount wasn't applied to the first invoice
That's why it doesn't have discount_amounts
first invoice means the first line item in the upcoming invoice, or the subscription's first invoice?
No worries
Thank you for taking your time
I'll wait in this thread until you have good news. I have a way in my mind to handle this case. I'm trying to see if you will have a better one ๐ผ
Since the discount has been used up (removed from the subscription), no discount would be used to calculate the discounted line items. Therefore, discount_amounts is empty
There's no good way to use upcoming invoice API to determine whether a past invoice line item has a discount applied
It's not possible to get upcoming invoice from other API
So the goal is to identify the invoice item "Unused time on 10 ร Standard (with 40.0% off) after 20 Oct 2022".
This is what I am thinking
I'm afraid this scenario won't be possible via Stripe API. One possible way is to keep track of the price_ in the last invoice has promotion applied yourself
This was the idea I had as well. We get the latest invoice and see if that one has a discount applied, and the upcoming invoice request time is within that invoice period
And if the invoice items in upcoming invoice has no elements in discount_amounts we consider the invoice item where amount < 0 will be "Unused time on 10 ร Standard (with 40.0% off) after 20 Oct 2022"
Would this logic be okay?
That sounds good
Cool, thank you so much for your time @viral bolt
No problem! Happy to help ๐
Have a nice day to you as well ๐