#manuel_api

1 messages · Page 1 of 1 (latest)

glossy groveBOT
#

👋 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.

south hollow
#

hi! just want to acknowledge your question, i'm wrapping some other things up but i'll be with you asap.

stable saffron
#

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, }, )

south hollow
#

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

stable saffron
#

so how can I attach a coupon to invoices if I can't create it with those parameters?

south hollow
#

one option would be to create a one off coupon each time you want to apply a discount

stable saffron
#

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?

south hollow
#

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

stable saffron
#

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.

south hollow
#

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

stable saffron
#

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

glossy groveBOT
south hollow
#

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},
  ]
)