#Pdot - Checkout installments

1 messages · Page 1 of 1 (latest)

strong rover
#

Good question. I am trying to think of how best to link Checkout and that flow.

#

Actually, yes, you have it right. The easiest way to do this would probably be doing a Checkout session that starts a subscription and then you create a schedule from that subscription that ends at whatever point

robust sinew
#

okay great. Let me tell you the work flow that I am thinking of and you can let me know if there is a better improvement

#
  • user purchases a subscription that is indefinite with stripe.checkout.Session.create
  • soon as the purchases is successful and the webhook for a successful purchase is fired, I would grab the customer ID and invoke stripe.SubscriptionSchedule.create

The question that comes up is how can I pass the subscription the user just purchased in phases. It seems like phases takes items.

strong rover
#

Yes, that should do it correctly. When you create the schedule, it will automatically have one phase that has items. You can just copy the first phase you get back and add an iterations argument to tell us when to cancel the schedule after

robust sinew
#

Ahh okay, if I am understanding correctly the webhook after creating the Stripe.checkout for a subscription should return a phase which I can use to call stripe.subscriptionschedule.create and pass iteration?

strong rover
#

Not quite, the subscription in that event will just be a subscription, when you make the call to create a schedule for it, that schedule will start with one phase and you can use that phase when making your update call to say when it should end

#

Trying to find me code for when I tested this

robust sinew
#

Got it, Thanks you Pompey

strong rover
#

I found this code that gets at the concept but for some reason it is not actually setting iterations properly :/

    updated_phase = schedule.phases[0]
    updated_phase.pop('end_date')
    updated_phase.iterations = 4
    updated_schedule = stripe.SubscriptionSchedule.modify(schedule.id, phases=[updated_phase], end_behavior='cancel')
    print(updated_schedule)```
#

But I think that gets at the concept, you can re-use the phase object or you can create a new one based on its old data

robust sinew
#

got it, I'll test it out and let you know. I'll update you on the code for future references

#

if it works lol of course