#karina-6458_api
1 messages ยท Page 1 of 1 (latest)
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.
- karina-6458_api, 5 days ago, 10 messages
๐ 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/1270476919489429605
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
Hello
What do you mean by discount ID? can you share examples?
on the stripe invoice, there is stripe_invoice.discounts
and then on each item there is also a discounts array
and without expansion, those arrays contain discount ids starting with di_
recently we discovered that stripe invoices max out at 10 lines at which point you need to refetch the lines specifically
so we have tried to use the list_upcoming_line_items endpoint
however when using that endpoint, the discount ids for subscription discounts seem to change, though interestingly, the discount ids for the line discount remains the same ๐ค
Are you specifically trying to fetch upcoming invoices' line items?
or an existing invoices line items?
upcoming invoice. i'm trying to preview a change to a subscription
Gotcha.. I haven't really tested this myself so I don't know what the expected behavior is..
Can you share an example request ID where you're listing the upcoming lines?
i can't seem to find the requests in the logs
it is for this subscription https://dashboard.stripe.com/test/subscriptions/sub_1PjUb4DAWTp2PXOweVk6CHCl
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
Ah its a GET request
We don't store the responses for these
So the subscription currently has di_1PjUb4DAWTp2PXOwBhDIJAL2 applied
and line items have di_1PjUb4DAWTp2PXOwiv3PzIbN and di_1PjUb4DAWTp2PXOwWGAVRe90
what ID are you seeing in the response for list_upcoming_line_items?
if you can share the whole response, that'd be awesome
๐งโ๐ป How to format code on Discord
Inline code: wrap in single backticks (`)
This:
The variable `foo` contains the value `bar`.
Will turn into this:
The variable
foocontains the valuebar.
Code blocks: wrap in three backticks (```)
Also, you can specify the language after the first three backticks to get syntax highlighting.
This:
```javascript
function foo() {
return 'bar';
}
```
Will turn into this:
function foo() {
return 'bar';
}```
Notes about **code blocks**:
- Specifying the language is optional (e.g., you can omit `javascript` in the example above)
- If you don't specify the language you won't get syntax highlighting
- When you're inside a code block (after you type \`\`\`) the `Return`/`Enter` key will add a new line instead of sending your message
- Once you end the code block `Return`/`Enter` works normally again
You can [read more about message formatting on Discord's website.](https://support.discord.com/hc/en-us/articles/210298617)
feel free to use a code block
oh, also very interesting that you are saying it is di_1PjUb4DAWTp2PXOwBhDIJAL2
because the initial invoice response has di_1Pku2gDAWTp2PXOwBiK8Kscq
lol, i copied and pasted only part of the invoice and it is telling me it is too long...
[27] pry(StripeService)> stripe_invoice.lines.map{|x| x.discounts.map(&:id)}
=> [[],
[],
[],
[],
[],
[],
[],
["di_1PjUb4DAWTp2PXOwiv3PzIbN", "di_1PktLEDAWTp2PXOwNBvQ6rl2"],
["di_1PjUb4DAWTp2PXOwWGAVRe90", "di_1PktLEDAWTp2PXOwNBvQ6rl2"],
["di_1PktLEDAWTp2PXOwNBvQ6rl2"]]
[28] pry(StripeService)> items.map{|x| x.discounts.map(&:id)}
=> [[],
[],
[],
[],
[],
[],
[],
["di_1PjUb4DAWTp2PXOwiv3PzIbN", "di_1PktSMDAWTp2PXOwfHqsV0PQ"],
["di_1PjUb4DAWTp2PXOwWGAVRe90", "di_1PktSMDAWTp2PXOwfHqsV0PQ"],
["di_1PktSMDAWTp2PXOwfHqsV0PQ"],
["di_1PktSMDAWTp2PXOwfHqsV0PQ"],
["di_1PktSMDAWTp2PXOwfHqsV0PQ"],
["di_1PktSMDAWTp2PXOwfHqsV0PQ"]]
because the initial invoice response has di_1Pku2gDAWTp2PXOwBiK8Kscq
which invoice are you referring to?
here are some scraped results, you can see i am digging into the discounts array on the initial 10 invoices lines, the bottom items is the result of a call to Stripe::Invoice.list_upcoming_line_items
these are all previews, so i do not have persisted invoice ids
oh, i think the subscription level discount id is always changing in the preview? ๐ค
๐
Since previewing an upcoming invoice doesn't actually create and Invoice and the child objects (they're just previews), I think we're just returning some placeholder IDs
but curiously the line item discount ids are remaining consistent
here is the params for the first call that grabs the invoice preview {:customer=>"cus_Qafwqrl3nJ31HK", :subscription=>"sub_1PjUb4DAWTp2PXOweVk6CHCl", :discounts=>[{:coupon=>"SALES10"}], :invoice_items=>nil, :subscription_items=> [{:id=>"si_QafwCFTrXbAcw6", :discounts=>[{:coupon=>"SALES10"}], :plan=>"plan_manage_essentials_plus_usd_2023_10_03_365_day", :quantity=>4}, {:id=>"si_QafwIo1mAbPYfd", :discounts=>[{:coupon=>"SALES10"}], :plan=>"plan_grow_essentials_plus_usd_2023_10_03_365_day", :quantity=>4}, {:id=>"si_Qafw2FszlEaHCa", :discounts=>"", :plan=>"price_1PAhWrDAWTp2PXOwtGdefkiQ", :quantity=>4}, {:id=>"si_QafwQCUNl2Vv4v", :discounts=>"", :plan=>"personal_injury_add_on_365_day", :quantity=>4}, {:id=>"si_QafwKsfx4wj7lS", :discounts=>"", :plan=>"accountant_user_add_on_365_day", :quantity=>4}, {:id=>"si_Qafw7GONLepWGq", :discounts=>"", :plan=>"price_1PL74vDAWTp2PXOwYf2NTHp2", :quantity=>4}], :subscription_proration_behavior=>"always_invoice", :subscription_proration_date=>1722977862, :expand=>["lines.data.discounts", "lines.data.discount_amounts.discount"]}
i wanted to say it was because we are passing the subscription level discounts without an id, but we appear to do the same with lines and the lines are able to maintain their discount ids
i'm digging in with my team why we do it specifically this way, but recall it being a way to get around another stripe issue we have been hitting with the discounts array on the subscription objects
but i was not there for that project so i'm not entirely sure...
ah yes, i retried and i do not alter the subscription discounts array and the ids are looking more consistent. however that doesn't seem to explain why the item ids are remaining consistent.
I'm having trouble following and I see lots of requests in your test logs
Can you share the params for this and the response?
i did the same params as above, but set discounts to []
Can you share the response?
Okay, the Discount IDs we return in this response are expected. They're the IDs for the existing Discounts on the Subscription Items and on the top level Subscription
yes, that is the new one where i pass in discounts = [] at the top level
Right
so my question is why the line item discount ids seem unaffected when i do pass in discounts, but the subscription discount ids change
why the line item discount ids seem unaffected when i do pass in discounts
You mean when you don't pass in discounts (when you usediscounts = [])?
i mean that as per the request params above, i do specify discounts on the line items themselves via :discounts=>[{:coupon=>"SALES10"}] but the resulting invoice line items appear to maintain the their discount ids properly
I suspect it's because the SALES10 coupon already applies to those SubscriptionItems so we're just giving you a "real" Discount ID
but in this case SALES10 is also already on the subscription
If you make a request that looks just like this one: https://dashboard.stripe.com/test/logs/req_oekSDanSW7r0T6
but pass a different coupon for si_QafwCFTrXbAcw6, what discount ID do you get in the response for the associated line item?
hold on, let me try
yes, it did appear to change the discount id
that is good, it means i am sending that param through correctly ๐
so ultimately does that mean that subscription items will nicely infer discounts based on coupon id, but the subscription will not?
Not quite, I think. If your goal with passing discounts = [] was to clear the subscription-level discount, I think you need to pass an empty string here, not an empty array
If you make a request that looks just like this one: https://dashboard.stripe.com/test/logs/req_oekSDanSW7r0T6
but pass an empty string: https://docs.stripe.com/api/invoice-line_item/retrieve-upcoming#upcoming_invoice_lines-discounts
Does the response include a null top-level discount value?
i didn't want to clear the subscription level discount, i just didn't want to explicitly overwrite it so that the discount id could be maintained
Got it. In that case, this seems expected, no? If you don't pass a value for top level discounts retrieving an upcoming invoice's line items, the Subscription discount is inherited. This explains why the response included di_1PjUb4DAWTp2PXOwBhDIJAL2 for the existing discount with SALES10
The behaviour that is confusing me is: when i send discounts: {coupon: "SALES10"} on the subscription level that already has a SALES10 coupon, why is it returning a new discount id. but i send the exact same thing on the subscription item that already has a SALES10 coupon and the resulting invoice line is returning the existing discount id?
Can you try this request one more time and share the full response? https://dashboard.stripe.com/test/logs/req_sC6QqNgDbbOLNN
Hm, yeah, I don't know why that is
Taking a step back since we've been in the weeds for some time. Can you share more about what you're working on here and how this discrepancy affects your flow?
this impacts our invoice previewing UI for changes that result in more than 10 lines. the code is getting confused because the discount id on the invoice preview is different from the discount id from the upcoming_invoice_lines call
Got it. Since it's a preview of an upcoming invoice (and not retrieving an actual invoice object), I think it's fair to not rely on the IDs since those may change (as we've seen here)
Is that an option for your team?
is there any way to specify that we want more lines expanded in the initial upcoming invoice call?
By "more lines expanded", you mean include more line items?
If so, yes. you can pass up to limit: 100: https://docs.stripe.com/api/invoice-line_item/retrieve-upcoming#upcoming_invoice_lines-limit
no, i mean in the initial invoice upcoming call. not when i'm trying to retrieve the remainder of the lines
Ah no, that's not possible