#Taylor

1 messages · Page 1 of 1 (latest)

dusky snowBOT
vague coyote
#

a few days before the trial ends, you'll receive this event customer.subscription.trial_will_end

#

Then if the subscipriton/customer has a default payment methods you have nothing to do

#

Otherwise you need to collect payment methods from the customer.

dusky snowBOT
untold osprey
#

The payment method is collected when the subscription is purchased, and includes the free trial before the payment method is charged. After checkout I want to upgrade their account to pro status, I believe the correct event is customer.subscription.created.

If the trial ends and payment fails revert the status to free, or if its successful do nothing until the subscription is cancelled and payment period is finished.

This is the part I cannot clear up. I dont know what events I should care about regarding cancellation or failed payment. I also am unsure how to update the correct user as the client_reference_id is only passed in checkout events, and not any events regarding invoices or customer subscriptions

loud spire
#

failed payment is an invoice.payment_failed. cancellation depends what you mean by that, since by default Subscriptions continue forever until you explicitly cancel them

I also am unsure how to update the correct user as the client_reference_id is only passed in checkout events, and not any events regarding invoices or customer subscriptions
you should be saving the customer and subscription IDs cus_xxxx and sub_xxxx in your database when handling the initial checkout.session.completed event, and use those for future subscription-related webook handling; the client_reference_id is not long-lived, it's just specific to the Checkout attempt

untold osprey
#

The two scenarios I can think of are either a purposeful cancellation, in which the user should keep the pro status until the billing period ends, or upon a payment failed, which you mentioned, should revert the user to free immediately. What is the event lifecycle for the purposeful early cancellation?

And okay I will store the sub and customer id's in my database upon checkout and use those for future events

loud spire
#

What is the event lifecycle for the purposeful early cancellation?
depends what exact API you call, but it generates a customer.subscription.deleted when the subscription is fully cancelled

untold osprey
#

So would I be missing anything if I change status to pro upon checkout.session.completed, and change status to free upon invoice.payment_failed and customer.subscription.deleted

loud spire
#

I think it sounds reasonable enough to me at a high level

#

obviously needs more nuance, like you should ignore invoice.payment_failed if it's the first Invoice(it has billing_reason:subscription_create ) which you'd find in testing

untold osprey
#

These are the events sent to my webhook upon a customers first purchase that includes a short free trial. Dont see the invoice.payment_failed you are mentioning but other than that I think like you said at a high level this should work. If you have any other nuances I should think about please let me know. Other than that I will move forward in this direction and hopefully get this working