#ironbeard_invoice-preview-discounts
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/1328382789568958559
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.
- ironbeard_api, 4 days ago, 28 messages
Thanks for the info, looking in to this
Apologies but the server got busy and I am just now looking in to this. Would you be able to paste the json output of one of those invoices here? Also if you do actually create the invoice have you seen the discounts apply?
No worries, one sec
Here are the invoice IDs, do they help?
il_tmp_123351CoTIfwbn281fbfaed2, il_tmp_143640CoTIfwbn2854be19af
I haven't tried actually creating the invoices, I'm using the preview feature to generate a shopping cart page to show lines / cost / discounts / prorations before they start the "actual" checkout flow
Unfortunately I can't look them up. It looks like the items should have a discounts array that shows what discounts apply to them. Are those populated on your temporary items?
yeah one second
A "correct" one, where you promotion code and the items line up
so neither of them have the discounts array populated, but they do have the discount_amounts array, and it's zero for the "mismatched" scenario. But I can't use discountable to detect discounts bc it's True for both situations
kind of as a related sitation, I'm kind of surprised Stripe doesn't provide a "line subtotal," it looks like I have to calculate it myself using amount / amount_excluding_tax and the values in discount_amounts.
(in the end, I suppose it's something I could prevent on my end by not requesting preview invoices containing promotion codes that don't apply to the "cart," which I'll fix. But was still surprised by this behavior and wasn't sure if it was a bug)
Oh I found clarification. Will see if we can update the wording. This is meant to be a field that you set to true or false depending on whether discounts should apply to the item. So when we say "discounts will apply to this item" it more means "discounts can apply to this item". We will apply them if they line up, but we don't mean "will" as in "we found a specific discount that will apply to this item"
And yeah on the subtotals unfortunately. Can put in feedback about that
But if the promotion code's coupon doesn't apply the product, is it still true that the discount "can" apply to the item?
Or is "discountable" going to be True for every line in an Invoice that has a promotion code *regardless of whether or not the promotion code applies to that line?
It means that a discount can apply to the invoice item, but not necessarily the discount(s) that are actually on the previewed invoice.
So yes it will be true whether or not the promotion code applies, unless you set it to false on the invoice item yourself
So the docs say that discountable is always False for proration. Are the following statements true?
- If the preview invoice has no discount / promotion code / coupon, then every line will have
discountable = False - If the preview invoice has a discount / promotion code / coupon, then every non-proration-related line will have
discountable = Trueregardless of whether or not the discount applies to the line?
From my understanding it would be true in the first bullet point as well (for non proration items). My understanding is that this is entirely the behavior of whether the item can in theory have a discount applied to it if you add one that is usable for its product and so on
Oh, strange I didn't catch that but yes it does seem like that's the case
btw I've noticed in all scenarios (e.g. whether or not discount_amounts is populated, and whether or not a discount applies to that line), that discounts is always an empty list. Do I need to use the expand parameter in order to get something there?
I think so, I think our API ref is slightly out of sync there. We show "Expandable" on discounts on the actual invoice item reference, but not the one for the upcoming invoice's items. Can you test this out quickly? If they do start showing up, I can file something about that. That is strange that we return an empty array though, usually in this scenario we don't reaturn anything until the expand param is passed
https://docs.stripe.com/api/invoiceitems/object#invoiceitem_object-discounts
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
data = {
'subscription_details': {
'items': [{'price': 'price_1Qf5qKCoTIfwbn28OC1QgABk',
'quantity': 1}]
},
'discounts': [{'coupon': 'RUMSnBKh'}],
'expand': ['discounts']
}
i = stripe.Invoice.create_preview(**data)
Still had empty array for i.lines[0]['discounts']
(but discount_amounts had a positive value, e.g. the discount applied to the line)
Interesting. I do not know why that would be. Consulting my colleagues
If you're able to figure out when I could expect a value for InvoiceLineItem.discounts (docs link), that'd be great, but I think I have the info needed to finish my current implementation.
But it'd be nice to be able to just loop through invoice.items in an HTML template and have all the information to show e.g. "$150.00 $0.00" (e.g., 1) whether the line actually has a discount applied and 2) what the final price of the line is, instead of having to do subtraction between the Stripe API request and rendering the template).
As a final question, can you offer any guidance for when I should use Invoice.create_preview vs Invoice.upcoming, or if one of them is a better fit for showing price information to a user in a checkout / shopping cart page?
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Hi ๐
I'm stepping in as my colleague needs to go soon. So, if I read this correctly, the issue is that while you do see discounts applied in the top level discoutns property, the line_item specific discount_amounts property is not being populated?
no worries ๐ For context, all my questions are currently with respect to Invoice.upcoming. I think this is a good summary of our findings and my remaining questions:
Findings:
Invoice.lines.discountableis False for prorations, but otherwise is basically always True, regardless of if the line has discounts actually applied to it
Questions:
- Under what circumstances is
Invocie.lines.discountsanything other than an empty list? I've usedInvoice.upcomingwith applied discounts and without them, even withexpand=['discounts']and I never get anything other than an empty list. - Is there any recommendations on when to use
Invocie.create_previewvsInvoice.upcoming? My use case is displaying a shopping cart with prices, prorations, discounts, etc.
Enhancements:
- It would be nice if
Invoice.lineswould have an indicator of whether a discount was actually applied to the line - It would be nice if i didn't have to calculate the line's subtotal using e.g.
amount-discount_amounts[0]['amount']
Okay first let me ask, when you reference Invoice.upcoming are you referring to the Invoice data you receive from this endpoint? https://docs.stripe.com/api/invoices/upcoming making a GET request to /v1/invoices/upcoming
OR
this endpoint https://docs.stripe.com/api/invoices/create_preview making a POST request to /v1/invoice/create_preview?
Ack. Just wanted to confirm because we added a new API that allows users to persist the Invoice preview
So both create_preview and upcoming seem to have empty discounts arrays. can you see the requests if I give you their ids?
Yes but for the GET request I can only see the parameters you pass, not the data returned
- req_Z1bBHHhsQyMiNt (POST create_invoice)
- req_M8jMtCo6OsYpxI (GET upcoming)
Okay taking the first request first, I do see the discount_amounts populated with data
GET upcoming:
Corrct, discount_amounts has data, but discounts is just an empty list. Is it maybe being depreciated? It doesn't really matter to me, I just was curious what it should respond, and it it would help me detect if 1) a discount applies to the line (since discountable seems to basically always be True for non-prorations) or 2) would provide me the "final" price of the line
My colleague has suggested that the Invoice.lines.discounts is only populated when you apply the discount to specific line items. In your case, you are applying the discount at the Invoice level.
The amount is deducted from each line item (populated discount_amounts) but since the Discount object is applied at the Invoice level, that is where you can find the data.
Oh, interesting. So currently i'm doing e.g.
stripe.Invoice.upcoming({
'subscription_items': [{'price': 'price_1Qf5qKCoTIfwbn28OC1QgABk', 'quantity': 1}],
'discounts': [{'coupon': 'RUMSnBKh'}],
}]
and letting Stripe figure out how/where/if to apply the discount (I'm just passing on the coupon value from a form in the ShoppingCart.
But, if I did the logic to determine if the promocode/coupon applies on my end, and specify it in e.g. subscription_items['discounts'], I'd probably get something back.
Yup, seems to be the case.
Sorry but I think I'm missing a key part here. Is there a specific reason the details in discount_amounts is not sufficient?
Well, the details in discount_amounts would be non-empty and "0" for a line in my invoice that the coupon doesn't apply to
I didn't know if there was something else I could check. And I didn't know if discounts would tell me the "final" amount, not just the discount amount. (e.g., for an item that cost $100 and a discount of $20, it seems like if i want to display "$100 $80" in my HTML template I have to do the calculation myself).
True, and include logic to handle whether situations where you use either percent_off or amount_off
Yeah, but my understanding is that discount_amounts is a calculated value in cents, regardless of percent_off or amount_off. So that's nice. It would just be nice if Stripe was able to send the "$80" number instead of "$100" and "$20", but no worries ๐
One sec I'll show a final example
In this one, I specified the discount on the invoice, not the item/line: req_4dIWXwyf6zF1o8. So the response has a discount_amounts for both items, one of which is 0 (since the coupon only applies to one item).
In this one, I specify the discount on the subscription_item: req_U7z5jmatDuu41x, so the response only has discount_amounts for the relevant line.
I suppose this all makes sense. But it turns out that I either need to:
- Validate the coupon on my end and only send it in the appropriate
subscription_itemor - Send the coupon on the invoice as a whole (and let Stripe validate it), but then I'd have to check if
discount_amounts[i]['amount']is nonzero.
Yes that all matches what we would expect. I realize it makes your integration a little more complicated (since you have to figure out if your coupons apply for each line item). But on our side, we are trying to do exactly what you tell us. If you apply a discount at the level of the Invoice, that is where we store the data. If you apply it at the item level, then we put it there.
Yeah, that all makes sense, I just had to walk myself through it. Thanks!
On an unrelated note, you've been helping me for years and I really appreciate it! One last question: any guidance on when to use .upcoming vs .create_preview?
Yeah, that all makes sense, I just had to walk myself through it. Thanks!
Honestly, if I don't talk through our products when I'm integrating them with my colleagues I find I don't really understand them either.
One last question: any guidance on when to use .upcoming vs .create_preview?
That depends on the use case. The create_preview method corresponds to our newer API that creates an actual record that can persist on your account. This could allow you to create a preview once and refer to it multiple times.
the upcoming method dynamically calculates the data for each request and you cannot persist the data unless you store it locally
Hmm, gotcha. Good to know! So if I wanted to view a persisted preview invoice could I still just use e.g. stripe.Invoice.retrieve('upcoming_in_1QgrPlCoTIfwbn28jXUK3XDU')
lol it looks like Invoice.create_preview IDs start with upcoming, not to be confused with Invocie.upcoming which has no IDs?
Correct!
Invoice.upcoming does not create a data objecton your account so you cannot retrieve it again
Invoice.create_preview creates a data object with it's own ID for you to retrieve again
Okay, thanks so much ๐
Sure thing! It's why we're here. ๐
And we appreciate that you are always willing to be patient and test out different approaches when you ask complex questions here. It makes digging into these issues easier.
Of course, it's nice to be able to actually ask technical questions to tech support! Y'all are amazing. Have a wonderful day!
You too ๐