#Eranga

1 messages ยท Page 1 of 1 (latest)

lilac pollenBOT
viral bolt
#

Can you share the subscription ID or request ID?

tawdry granite
#

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

viral bolt
#

I don't quite understand your question

tawdry granite
#

Sorry, let me give you a bit more information

viral bolt
#

Can you explain more what is the expected outcome you're looking for and the problem you're facing?

tawdry granite
#

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)

viral bolt
#

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?

tawdry granite
#

Yes, that is what I am trying to achieve

viral bolt
#

If the upcoming invoice line item has a discount, it will contain discount_amounts

tawdry granite
#

Cool, so it is okay to rely on the length of discount_amounts to be greater than 0 , right?

viral bolt
#

You can use discount_amounts to determine a discount has been applied to the line item

tawdry granite
#

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?

viral bolt
#

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

tawdry granite
#

Great, that is very helpful ๐ŸŽ‰. Thank you

viral bolt
#

No problem! Happy to help ๐Ÿ˜„

tawdry granite
#

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? ๐Ÿ‘ผ

viral bolt
#

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

tawdry granite
#

first invoice means the first line item in the upcoming invoice, or the subscription's first invoice?

viral bolt
#

Sorry, my bad

#

I read it wrongly

tawdry granite
#

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 ๐Ÿ‘ผ

viral bolt
#

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

tawdry granite
#

Yeah, true. I agree

#

How about using other APIs as well?

viral bolt
#

It's not possible to get upcoming invoice from other API

tawdry granite
#

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

viral bolt
#

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

tawdry granite
#

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?

viral bolt
#

That sounds good

tawdry granite
#

Cool, thank you so much for your time @viral bolt

viral bolt
#

No problem! Happy to help ๐Ÿ˜„

tawdry granite
#

That is all for now

#

Have a nice day ๐Ÿฅ‚

viral bolt
#

Have a nice day to you as well ๐Ÿ˜