#karina-6458_api

1 messages ยท Page 1 of 1 (latest)

abstract forgeBOT
worthy pulsarBOT
#

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.

abstract forgeBOT
#

๐Ÿ‘‹ 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.

weary badger
#

Hello
What do you mean by discount ID? can you share examples?

static snow
#

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 ๐Ÿค”

weary badger
#

Are you specifically trying to fetch upcoming invoices' line items?

#

or an existing invoices line items?

static snow
#

upcoming invoice. i'm trying to preview a change to a subscription

weary badger
#

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?

static snow
#

i can't seem to find the requests in the logs

weary badger
#

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

abstract forgeBOT
#

๐Ÿง‘โ€๐Ÿ’ป 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 foo contains the value bar.

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)
weary badger
#

feel free to use a code block

static snow
#

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"]]
weary badger
#

because the initial invoice response has di_1Pku2gDAWTp2PXOwBiK8Kscq
which invoice are you referring to?

static snow
#

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

abstract forgeBOT
static snow
#

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? ๐Ÿค”

restive sable
#

๐Ÿ‘‹ Stepping in for my teammate

#

That...makes sense but isn't super intuitive

static snow
#

๐Ÿ‘‹

restive sable
#

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

static snow
#

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.

restive sable
#

I'm having trouble following and I see lots of requests in your test logs

restive sable
static snow
#

i did the same params as above, but set discounts to []

restive sable
#

Can you share the response?

static snow
#

trying to make a file, discord will not let me paste

restive sable
#

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

static snow
#

yes, that is the new one where i pass in discounts = [] at the top level

restive sable
#

Right

static snow
#

so my question is why the line item discount ids seem unaffected when i do pass in discounts, but the subscription discount ids change

restive sable
#

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 use discounts = [])?

static snow
#

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

restive sable
#

I suspect it's because the SALES10 coupon already applies to those SubscriptionItems so we're just giving you a "real" Discount ID

static snow
#

but in this case SALES10 is also already on the subscription

restive sable
static snow
#

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?

restive sable
#

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

static snow
#

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

restive sable
#

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

static snow
#

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?

restive sable
static snow
restive sable
#

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?

static snow
#

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

restive sable
#

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?

static snow
#

is there any way to specify that we want more lines expanded in the initial upcoming invoice call?

restive sable
#

By "more lines expanded", you mean include more line items?

static snow
#

no, i mean in the initial invoice upcoming call. not when i'm trying to retrieve the remainder of the lines

restive sable
#

Ah no, that's not possible

static snow
#

ok, then i guess this will have to be the option for our team ๐Ÿ˜…

#

thanks for talking this out with me