Revamp Trial Subscription Flow with Stripe SetupIntent, Legacy Support, and Webhook Fixes#161
Merged
Ashad001 merged 3 commits intoFireBird-Technologies:mainfrom Jun 24, 2025
Conversation
ArslanS1997
pushed a commit
that referenced
this pull request
Mar 17, 2026
Revamp Trial Subscription Flow with Stripe SetupIntent, Legacy Support, and Webhook Fixes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
/api/checkout-sessionsendpoint to only create a SetupIntent (not a subscription). The subscription is now created after payment confirmation via the/api/trial/startendpoint.Issue #2: Legacy Users Can't Cancel
Problem: Legacy users had
stripeSubscriptionIdvalues likepi_...(Payment Intent), not actualsub_...(Subscription IDs), causing cancellation to fail.Fix: Added logic in
/api/trial/cancelto detect and gracefully handle legacy users: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:
/api/webhooksImpact: 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/startis called to:No invoice is generated until this step is complete.
Legacy Support:
pi_-based IDsFrontend Updates:
CheckoutFormto align with the new SetupIntent-first flow/checkout/page.tsxto support the new API