Skip to content

Revamp Trial Subscription Flow with Stripe SetupIntent, Legacy Support, and Webhook Fixes#161

Merged
Ashad001 merged 3 commits intoFireBird-Technologies:mainfrom
Ashad001:refactor/paid-plan
Jun 24, 2025
Merged

Revamp Trial Subscription Flow with Stripe SetupIntent, Legacy Support, and Webhook Fixes#161
Ashad001 merged 3 commits intoFireBird-Technologies:mainfrom
Ashad001:refactor/paid-plan

Conversation

@Ashad001
Copy link
Contributor

This pull request fixes critical issues in the subscription system and implements a robust, modern trial flow using Stripe SetupIntents. It also adds backward compatibility for legacy subscriptions and improves webhook signature verification reliability.


🔍 Issues Addressed

Issue #1: Premature Invoice Creation

  • Problem: Stripe subscription and invoice were created immediately when the user visited the checkout page.
  • Fix: Modified the /api/checkout-sessions endpoint to only create a SetupIntent (not a subscription). The subscription is now created after payment confirmation via the /api/trial/start endpoint.
  • Impact: No invoices are generated until the user confirms payment.

Issue #2: Legacy Users Can't Cancel

  • Problem: Legacy users had stripeSubscriptionId values like pi_... (Payment Intent), not actual sub_... (Subscription IDs), causing cancellation to fail.

  • Fix: Added logic in /api/trial/cancel to detect and gracefully handle legacy users:

    • If the ID starts with pi_, it skips Stripe API cancellation and cleans up Redis instead.
  • Impact: Legacy users can now cancel without issues.

Issue #3: Webhook Signature Failures

  • Problem: Stripe webhook verification was failing despite the secret being configured.

  • Fix:

    • Improved error handling and diagnostics in /api/webhooks
    • Added clearer logging for missing/invalid secrets and signature mismatches
    • Ensured correct raw body usage to support Stripe signature verification
  • Impact: Easier debugging and better observability of webhook behavior.


Major Changes

  • New Trial Flow:

    • Users first create a SetupIntent on the checkout page.

    • After confirming the payment method, /api/trial/start is called to:

      • Create the Stripe subscription
      • Add credits (500) to Redis
    • No invoice is generated until this step is complete.

  • Legacy Support:

    • Detects and handles legacy users with pi_-based IDs
    • Avoids Stripe errors by skipping subscription API calls for such users
  • Frontend Updates:

    • Updated CheckoutForm to align with the new SetupIntent-first flow
    • Adjusted state handling in /checkout/page.tsx to support the new API
    • Updated UI logic to reflect new subscription and trial state handling

@Ashad001 Ashad001 merged commit d78aede into FireBird-Technologies:main Jun 24, 2025
1 check passed
ArslanS1997 pushed a commit that referenced this pull request Mar 17, 2026
Revamp Trial Subscription Flow with Stripe SetupIntent, Legacy Support, and Webhook Fixes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant