fix: attach payment method to customer before creating subscription
Deploy to Staging / Build Images (push) Successful in 3m39s
Deploy to Staging / Deploy to Staging (push) Successful in 23s
Deploy to Staging / Verify Staging (push) Successful in 8s
Deploy to Staging / Notify Staging Ready (push) Successful in 8s
Deploy to Staging / Notify Staging Failure (push) Has been skipped
Deploy to Staging / Build Images (push) Successful in 3m39s
Deploy to Staging / Deploy to Staging (push) Successful in 23s
Deploy to Staging / Verify Staging (push) Successful in 8s
Deploy to Staging / Notify Staging Ready (push) Successful in 8s
Deploy to Staging / Notify Staging Failure (push) Has been skipped
Stripe requires payment methods to be attached to a customer before they can be set as default_payment_method on a subscription. The createSubscription() method was skipping this step, causing 500 errors on checkout with: "The customer does not have a payment method with the ID pm_xxx". Co-Authored-By: Claude Opus 4.6 <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
853a075e8b
commit
72e557346c
@@ -75,6 +75,14 @@ export class StripeClient {
|
|||||||
try {
|
try {
|
||||||
logger.info('Creating Stripe subscription', { customerId, priceId, paymentMethodId });
|
logger.info('Creating Stripe subscription', { customerId, priceId, paymentMethodId });
|
||||||
|
|
||||||
|
// Attach payment method to customer before creating subscription
|
||||||
|
if (paymentMethodId) {
|
||||||
|
await this.stripe.paymentMethods.attach(paymentMethodId, {
|
||||||
|
customer: customerId,
|
||||||
|
});
|
||||||
|
logger.info('Payment method attached to customer', { customerId, paymentMethodId });
|
||||||
|
}
|
||||||
|
|
||||||
const subscriptionParams: Stripe.SubscriptionCreateParams = {
|
const subscriptionParams: Stripe.SubscriptionCreateParams = {
|
||||||
customer: customerId,
|
customer: customerId,
|
||||||
items: [{ price: priceId }],
|
items: [{ price: priceId }],
|
||||||
|
|||||||
Reference in New Issue
Block a user