Only confirm Stripe intents minted for this user's membership - #424
Merged
Merged
Conversation
confirmMembershipAfterPayment refused an intent only when metadata.userId was present and named someone else. A succeeded intent with no userId — hosted Checkout, a payment link, a Dashboard charge — passed with no type or amount check, and readPlan(undefined) granted a full year. Anyone holding such a charge id could claim it, including a $1 link or a $15 semester checkout confirmed before the webhook arrived. It now applies the same gate as the webhook and reconcileMyPayments: metadata.userId must equal the caller, metadata.type must be a membership or the bootcamp add-on, and the amount must be within MAX_MEMBERSHIP_CHARGE_CENTS. Every intent createPaymentIntent mints has carried type since June; mock intents now carry it too. The insert also uses onConflictDoNothing: when the webhook records the same intent first, confirm skips the grant instead of surfacing the unique violation as a 500 on a successful payment.
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.
Automated PR tracking changes from
fix/confirm-payment-gateintodev.Note
High Risk
Changes payment confirmation authorization and membership grant idempotency—security-sensitive paths where bugs could grant free or duplicate memberships.
Overview
Tightens
confirmMembershipAfterPaymentso only portal-minted membership or bootcamp add-on intents can grant access, aligning confirm with webhook/reconcile rules.Live confirmation now requires matching
metadata.userId,typeofmembershipor the bootcamp add-on type, and an amount at or belowMAX_MEMBERSHIP_CHARGE_CENTS. Intents withoutuserId(Checkout links, Dashboard charges, etc.) or wrong type/amount return FORBIDDEN instead of silently granting—especially whenplanwas missing and defaulted to a full year. Mock confirm paths always tag non–add-on intents withtype: "membership".Race with the webhook: payment rows insert with
onConflictDoNothing(); if the webhook already recorded the intent, confirm returns success without a second membership grant or a unique-constraint 500.membershipGrantsincrements only when this path actually grants.Tests add configurable Stripe retrieve/conflict mocks and a “confirming a live payment” suite for allow/deny cases and webhook-first idempotency.
Reviewed by Cursor Bugbot for commit e2ccdc2. Bugbot is set up for automated code reviews on this repo. Configure here.