#nickdnk_api

1 messages ¡ Page 1 of 1 (latest)

rotund irisBOT
#

👋 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/1405198357365788752

📝 Have more to share? Add more details, code, screenshots, videos, etc. below.

shadow flame
#

My plan was to have it check if I have a coupon (or discount object?) that matches the percent I want (by fetching them and iterating them), then applying that coupon ID to the sub

#

if not, create the coupon, then do it

#

It doesn't seem like a very good solution though

#

These are metered subscriptions, so I can't just calculate the discount amount as a line item at that time

shadow monolith
#

To add you can update the Subscription directly

shadow flame
#

Yea I just found that. So I would just if discount == 0 and subscription.coupon != null then delete discount, else create/apply coupon

#

but is it correct that I would/should fetch coupons and iterate to find one that matches, or am I just expected to create a new one every time? Both seem kind of clumsy

shadow monolith
#

I'd recomend storing a mapping of coupon id: percentage in your database

#

Just so the retrieval is a bit quicker

#

And if there's not one that has the percentage you want, create a new one

shadow flame
#

I guess I could do that yea

#

gonna go with iteration for now though as it's kind of rare that I need this and I'm a little in a hurry

#

increase technical debt