#manuel_api
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/1408153095158104186
📝 Have more to share? Add more details, code, screenshots, videos, etc. below.
hi! just want to acknowledge your question, i'm wrapping some other things up but i'll be with you asap.
also this is how i was creating the coupons before the update:
custom_coupon = stripe.Coupon.create( id = name_coupon, duration = "forever", amount_off = amount_off, currency = currency, metadata = metadata, applies_to={ "products": list_products_to_apply_coupon, }, )
it looks like this breaking change is documented here:
https://docs.stripe.com/changelog/basil/2025-03-31/restrict-coupon-duration
and the only alternative appears to be to create and apply coupons directly to each invoice you want to discount
one way to do that would be to listen to the invoice.created webhook and then inspect the invoice to decide if you want to apply a discount
so how can I attach a coupon to invoices if I can't create it with those parameters?
one option would be to create a one off coupon each time you want to apply a discount
but i need coupons with amount_off with a duration of forever? how can i attach it to an invoice if i cant create it?
so when you get the invoice.created event and decide you want to apply a discount
no, the idea is that you don't create the coupon with a duration of forever
you create it with a duration of once (which is the default value), and apply it to that one invoice
So every time a subscription needs to be updated or paid for, do I have to add that information?
It's no use to me if it lasts for “once”; I need that discount to be permanent.
if you set up a webhook event listener and apply a one-off coupon to every single invoice created for a given subscription, you can effectively make it permanent
Can you give me a real example? I really don't see the point of this...
i have my event listeners in my proyect but idk how to attach a discount in this way that you explains to me
you mean you already have a webhook set up? does that mean you know what i mean when i say listen for the invoice.created event?
if so, when you get an event, you would just do:
# insert logic to check if you want to apply a discount
# (for example, maybe inspect invoice metadata)
coupon = stripe.Coupon.create(
amount_off=100,
currency="usd",
)
stripe.Invoice.modify(
invoice.id,
discounts=[
{"coupon": coupon.id},
]
)