SaasCore Docs
  • Get Started
  • Configuration
    • Database
    • Stripe
      • Product ID and Price ID
      • API keys
      • Stripe Webhook
    • Emails
      • Cron Jobs
    • Claudinary
    • Chat plugin
    • Upstash Redis
    • OAuth with Google and GitHub
    • Subscription types and plans
    • Affiliate program
    • Google Analytics Api
  • Landing page
    • Header
    • Hero
      • Discount
      • AvatarCircles
    • Other components
  • Authentication Flow
    • For Admins
    • For Clients
      • OAuth
      • Credentials
    • For Affiliates
  • Payments
    • Payment Flow Scenarios
      • Scenario 1: Registered Client
      • Scenario 2: Direct Subscription from Home Page
      • Upgrading/Downgrading/Canceling Subscriptions
    • Pricing Table
  • Component Protection
  • Pending ...
Powered by GitBook
On this page
  1. Payments
  2. Payment Flow Scenarios

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:

  1. 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:

    await stripe.subscriptions.update(subscriptionId, {
        cancel_at_period_end: true,
        metadata: {
            reason: "upgrade-to-lifetime-subscription",
        },
    });

    Exception Handling:

    if (reason === "upgrade-to-lifetime-subscription") {
        return new Response(null, { status: 200 });
    }

Post-Subscription Tasks

In both scenarios, post-subscription tasks are handled by the handleAfterSubscriptionTasks() function.

PreviousScenario 1: Registered ClientNextUpgrading/Downgrading/Canceling Subscriptions

Last updated 10 months ago