Scenario 2: Direct Subscription from Home Page
Description: A visitor subscribes to a plan directly from the home page without creating an account first. Details:
Distinction: Differentiate between recurring and one-time payments because different stripe events are triggered for each case.
Case 1: Recurring Payment
Stripe Triggered Event:
customer.subscription.created
Process:
Generate a
PreClientPlan
table to temporarily store all plan properties (email, subscriptionId, currentPeriodEnd, amount, interval, token, etc.) with a unique token.Send an email to the client containing an account creation link with the token in the format
/auth/sign-up?token=token_code
.Use the stored data to create the actual
ClientPlan
.The client proceeds to create their account.
Case 2: One-Time Payment
Stripe Triggered Event:
payment_intent.succeeded
Process:
Handle payments via payment intents (paymentIntentId).
If the user was on a recurring plan before purchasing a lifetime plan, cancel their previous subscription using the subscriptionId from the database to stop recurring payments.
To prevent the
customer.subscription.updated
event (triggered by cancellation) from affecting the ClientPlan, we add a note in the subscription object's metadata to handle this exception.
Cancellation Call:
Exception Handling:
Post-Subscription Tasks
In both scenarios, post-subscription tasks are handled by the handleAfterSubscriptionTasks()
function.
Last updated