#iandk_api

1 messages ¡ Page 1 of 1 (latest)

proper helmBOT
#

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

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

blazing garden
#

What's the best way to calculate the remaining/already paid time so I can then credit the customer accordingly?
Probably there are multiple ways to achieve this... but I think using upcoming/preview invoice API is a good one...
https://docs.stripe.com/invoicing/preview

sullen lodge
#

hello! fyi i'm taking over for my colleague here - let me know if there are any further questions

mystic sorrel
#

Hi!

#

Hmm, is there a better way?
That doesnt seem very intuitive to me

sullen lodge
#

fyi the server is a little busy atm, but i will get back to you as soon as i can!

mystic sorrel
#

thanks!

sullen lodge
#

one way would be to cancel the existing subscriptions immediately and just rely on our automatic prorations

#

and then update the subscription you want to consolidate the multiple other subscriptions on, which in turn can automatically prorate things for you

#

one thing i should note is that we don't allow multiple different payment periods per subscription, so you won't be abe to combine monthly and annual subscriptions

mystic sorrel
#

when I cancel the subscriptions, will it automatically do the proration handling?

#

So esentially my plan was to cancel all subscriptions and then create a single, new one with monthly billing.

sullen lodge
#

actually let me run a quick test just to confirm some things

mystic sorrel
#

thanks a lot!

proper helmBOT
sullen lodge
#

ok yes, i just ran through a test simulation to confirm. when you cancel the subscription you can pass the prorate: True parameter, which will create a negative value invoice item attached to the customer

#

then the next time you generate an invoice for them (in your case via updating the new subscription to add the new subscription items) the value of that negative invoice item will automatically be deducted

#

i would recommend setting up a quick test to confirm on your end. my example (written in python) looks like this:

        customer=customer.id,
        items=[{"price": get_price_id("basic_monthly")}],
        payment_behavior="allow_incomplete",
        expand=["latest_invoice.payment_intent"],
        
    )
    print(subscription.id)
    
    advance_clock(customer.test_clock, increment=1 * 60 * 60 * 24 * test_clock_days) # 31 days

    stripe.Subscription.cancel(
        subscription.id,
        prorate=True,
    )
    subscription_2 = stripe.Subscription.create(
        customer=customer.id,
        items=[{"price": get_price_id("basic_monthly")}],
        payment_behavior="allow_incomplete",
        expand=["latest_invoice.payment_intent"],
    )
    print(subscription_2.id)```
#

(advance clock is a function that wraps our test clocks which are very useful for testing billing scenarios like this)

mystic sorrel
#

Will the value of that negative invoice apply to any new invoices?

sullen lodge
#

yep!

heavy glacier
#

hi! I'm taking over this thread. let me know if you have other questions.

mystic sorrel
#

Is it possible to just see how much the proration amount would be but without actually applying that?

heavy glacier
#

kind of. you can look at the invoice item created to see the proration, and then delete that invoice item so it's not applied to the next invoice.

mystic sorrel
#

hmm can you expand on that?