#msomji_api

1 messages ยท Page 1 of 1 (latest)

grave ploverBOT
#

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

๐Ÿ“ 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.

visual ocean
#

Hello, apologies for the delay. Good question, looking in to this and will get back with what I can find

visual ocean
#

When you say you were only seeing one discount, was that in the API response somewhere else?

#

Also apologies for the delay again, I should be faster for replies from here on o

fading cliff
#

When i retreve the subscription i see discount: nil

#

but I was able to preview the upcomming invoice to see the discounts, as such:
discounts: ["di_1RqaaPF5n5KjLa7R1H3mLJnS", "di_1RqajlF5n5KjLa7RKcdLZ92O"],

#

So that may work, however need to be able to determine the promotion_code that is linked to said discount

#

example - req_Tt10XZXI7E5bMk

#

Can't seem to find a way to determine what promotion those discounts are linked to

visual ocean
#

From what I can see, both should still apply. Can you try retrieving the subscription again and paste the response object that you get here? Request Id from that could be helpful to

#

Looking in to how to link to that as well

fading cliff
#

notice how retrieve only has the discount (singular) and that is nil.

#

Yes, both discounts are applying, what I need is a way to be able to add say a potential 3rd discount. So in order to do that am now thinking I would:

  1. get the upcomming invoice and get the discounts that would be applied
  2. get the promotion_codes from the discounts <--- missing piece atm
  3. create a new discounts array with the 2 existing discounts and 1 new one (if it is not one of the existing ones) and update the subscription
visual ocean
#

I think the issue with your GET request may be API version and a weird side-effect of how we used to backport new features

#

Basically, our API only used to support one discount at a time on subscriptions. In the 2022 API version that you are using I think that was the case

#

Eventually we replaced single promotion_code and coupon parameters with a discounts array that allows multiple discounts at once, and we changed the API object as well. We used to add new parameters to older API versions, so I think what happened here is that you are able to access the discounts parameter beause it was backported, but the API object is still rendering the old version that can only show one discount at a time

#

So I think you would need to retrieve the subscription with a newer API version, which may require upgrading your SDK.

#

Looking in to the promo code part in a minute

#

It looks like promotion_code is an expandable property of discounts. So if you expand discount.promotion_code in the older API version or discounts.promotion_code on the newer API version it should return the mapping

fading cliff
#

okay let me look how to expand that in using the library we are using atm

#

whats the latest api version? I tried 2025-06-30.basil but the subscription still had discount: nil

#

expanding worked on the upcomming invoice โœ… !

#

but seems like retrieving ther subscription, even with the latest api version didn't populate the promotions or discounts in the response

visual ocean
#

Oh ๐Ÿคฆโ€โ™‚๏ธ I now see the issue. The discounts property is expandable, meaning it only shows up if you expand it. Can you try retrieving in your original API version while passing expand=['discounts.promotion_code']? That should make it appear properly
https://docs.stripe.com/api/subscriptions/object?api-version=2024-11-20.acacia#subscription_object-discounts

fading cliff
#

yeah i got the discounts to expand and am able to see the promotionc code now, but only in the upcomming invoice calls, not in the retrieve subscription

#

which may be okay?

#

By re-applying these promotion codes on the subscription update, will that reset the redemption number? like these promotion codes are 3 months long, say I stack another promotion to the same subscription on the second month, will that initial promo time also get reset and result in being active for another 3 more months?

visual ocean
#

You should be able to do the same expand on the subscription retrieve, at least in the latest API version but I think earlier versions should do it to. Do you get an error when doing it on the subscription retrieve?

#

That is a good question on the redemption count, looking in to that

fading cliff
#

no error on subscrition retrieve. but the upcomming invoice is a decent workaround for now. so not concerned about that

visual ocean
#

No error but the field also doesn't show up? That is surprising, we should show it then. If the upcoming retrieve is a fine workaround that is good, I am just very surprised by that behavior

fading cliff
visual ocean
#

Ah, I was saying to run Stripe.Subscription.retrieve("sub_1RgX0pF5n5KjLa7RaWfvuiju", %{expand: ["discounts.promotion_code"]}

#

Also I confirmed that re-applying the discounts on the update just keeps them, it doesn't increment the redemption count

fading cliff
#

just to clarify: so if at the time of update the redepmtion count is 3, it will continue to be 3 if the same promotion code is applied?

#

the discounts field doesnt exist in the response so nothing to expand

visual ocean
#

Ah, I tried to mention this before but the discounts property is expected to be hidden unless you expand it. If you run that code, we will add a discounts array to the response

#

And yes, it will stay at 3 in that scenario

grave ploverBOT
fading cliff
#

the discounts field doesnt exist in the response so nothing to expand there

#

but maybe something with the api version, I'll try to play around with it when i have a moment

#

thanks again for the help!

visual ocean
#

the discounts field doesnt exist in the response so nothing to expand there
Yep, I did see when you said that the first time. Expansion can reveal certain fields that were initially hidden and this discounts field is one of them. If you try running expanding it - even though it doesn't exist otherwise - I think it will be clearer

fading cliff
#

I also tried Stripe.Subscription.retrieve("sub_1RgX0pF5n5KjLa7RaWfvuiju", %{expand: ["discounts.promotion_code"]}, [api_version: "2025-06-30.basil"]) and not seeing the additional field, maybe its a library limitation?

visual ocean
#

Ah gotcha, so I think this is happening because of the library's typing. This data is probably present in what we send back, but if the library doesn't map to it in the response then it might as well not exist.
I do see the field when making the same API request but with a different library. If you have a sec and run this curl command with your test key, I think it will show for you, but that ultimately isn't that helpful unless your library has a way to get the raw data from our response ๐Ÿ˜…

  -u "sk_test_1234:" \
  -d "expand[]"="discounts.promotion_code" ```
fading cliff
#

hah yeah i can try it but i beleive you that the api will return what we expect hah

#

for now I think we'll use the upcomming invoice to and expand the discounts.promotion_code in that response since the stripity stripe does have that in their response

#

Thanks for helping figure this out though ๐Ÿ™