#hash_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/1409877642219491329
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
I'm making subscription and i want to delete some items for it but keep them active for the current period. Is it possible to do this?
You mean, you want to delete that item for the current period or for the next period ?
i want to delete for the next period. Since the user is going to pay for the end of the month i want it to still be active but the subscription update i receive doesn't have the item anymore.
The AI was writing that if i add the Deleted to true, it will send the subscription object on the update with the item still inside until the end of the period and i will receive another update for the next period where the object will not be there anymore
so i need to make sure the phases are done at the end of the billing, the management of the date must be done from my side?
Yes, you have all the control on these dates
yeah tho i don't want to fuck up the custome subscription, i'll try to read a bit more my goal is just to have an added item to be invoiced immediately and in case he deselect it. Remove it on the next billing period since he would have paid. And in case he select again just add it again without any payment done again and keep it again on the next billing period
but it seems that this management requires to use a lot of different part of the billing i guess with those phases
What you did in the request req_x6BZFgxLzjaqBD is correct too between, when no impact use proration none and when you want to invoice use invoice always as proration
but using Subscription Shceduler will give you just more flexibility
but i need to modify the whole code somehow because this is a new kind of object from what i understand. I admit its a part where i'm a bit worried since its the money of the customer and the ai is sometime giving me code that doesn't seems to work with the golang library xD. But i suppose i need to understand this a bit more.
Basically tho instead of using subscription like i did before i will need to use the subscriptionSchedule right?
Yeah that's the straightforward path
wait sorry for asking so many question but i read in the doc i can still use my subscription object i created and add phase to it? So for exemple i can just use the phase parameter when i cancel an element but keep the rest of the code with the "github.com/stripe/stripe-go/v82/subscription" instead of the "github.com/stripe/stripe-go/v82/subscriptionschedule"?
Or to avoid some potential bug i should just rewrite all with the subscriptionSchedule?
hey there, i'm taking over for @manic crest who needed to step away. Catching up...
no problem, sorry for all my question. I'm trying to build a subscription system where user can add and remove items during the month with the only downside being once they add an item
there is proration paid for the rest of the month
and if they delete it only delete for the next period
and basically i used a normal susbscription item at first and removed payment with none when there was a deletion but since i wasn't using phases it was deleting for the current period as well
You can add schedules to existing subscriptions:
https://docs.stripe.com/billing/subscriptions/subscription-schedules#existing-subscription
Using the delete with prorations disabled like you share before is a fine approach here. Schedules are more powerful but also more complex.
It would delete it right away yes, but since you disabled prorations this removal doesnt affect invoicing until the renewal
my problem is that i'm dependend on the webhook to update my items and since the webhook updating with the item being immediatly deleted the app is removing the item for the current month too
because there are some items that are really cheap and when the user add them i don't immediatly charge for exemple but leave the proration for next period however i still let the user use those new items added
i feel like my payment strategy is complex but i wanted to give lots of flexibility for the end user
You mean on your side for provisioning?
yeah to update the customer information on what he is allowed to use the code is based on the subscription.update hook and just loop in the items that exist
when i was using the doc with ai it told me that at the end of the period when items gets deleted an update is sent again
yea you'd have to manage that differently if you're removing items
but i use the phase i can use it the same way? i will receive a new update at the end of the period right?
if*
This is not accurate when using deleted: true
yeah i just learned that in my tests ๐
Yes, if you sent up subscription schedules with phases to update the item at the period end you'd get an update event with the new items
So you can look into setting that up if the item existing is important to your systems
Glad you tested it ๐
yeah its the part i'm trying to be extremely careful about, if user lose money or find it weird there. My company is dead i guess xD
Just be prepared for some more complexity with schedules and also test thoroughly
yeah its just it was basically // Delete items that are not in the request first if len(stripeSubscriptionItemsToDelete) > 0 { stripeSubParams := &stripe.SubscriptionParams{ Items: stripeSubscriptionItemsToDelete, PaymentBehavior: stripe.String("default_incomplete"), ProrationBehavior: stripe.String("none"), } stripeSubscription, err = subscription.Update(legalSubscription.SubscriptionID, stripeSubParams) if err != nil { h.Log.Error("retrieve-stripe-subscription", zap.String("part", "subscription"), zap.Error(err)) return ctx.Status(500).JSON(fiber.Map{"error": "InternalError"}) } }
This part but now i can use that params := &stripe.SubscriptionScheduleParams{ FromSubscription: stripe.String("{{SUBSCRIPTION_ID}}"), } result, err := subscriptionschedule.New(params) that is in the doc to actually change the update to that kind of thing. Tho is it upgrading the whole subscription to a new object or i can still use the nomal subscription items for other purpose?
the subscription still exists, the schedule is a layer on top for managing changes over time
You set up scheduled upgrades/downgrades etc by creating phases: https://docs.stripe.com/billing/subscriptions/subscription-schedules?lang=go#downgrading-subscriptions
When the clock reaches the phase transition, the subscription is updated according to the items you specify (eg, in your case, the second phase would have the to-be-deleted item removed).
yeah i'm thinking of using that result, err := subscriptionschedule.New(params) when i'm in my function so i can verify what is in the current phase and the next one and then modify accordingly probably
my problem being mostly billing appearing for small items but well i'll cehck that after i guess
Also, i would suggest you think about how this provisioning is happening. Your Stripe integration already seems correct for how you want to invoice the customer, the issue is on your provisioning side reacting to the item removal
Instead of making your billing system more complex unnecessarily, you could change the way you manage provisioning
mmmh its just my source of truth is suppose to be stripe. but if i don't have the information there i feel it can lead to some mixup later
thats why i decided not to hold too much data about items on my backend side
so that later i could also just use some scrript to reset items from the stripe side but well i admit it does make it a bit complex to manage the phases this way
Yep, you can go down the SubscriptionSchedule path if you want, it'll work the way you say you want it to, then. It's more complex but if it gets you what you need so be it.
Just to sketch out an alternative you could track in your system:
- current period access
- recurring access
and you only remove items from the recurring access, but leave items in the current access alone, only update that when the billing cycle renews