next-stripe-helper
Advanced tools
Comparing version 1.1.23 to 1.1.24
@@ -24,16 +24,16 @@ "use strict"; | ||
const setupIntent = await stripe_1.stripe.setupIntents.retrieve(checkoutSession.setup_intent); | ||
if (setupIntent.payment_method) { | ||
// Assuming payment_method is either a string or a PaymentMethod object, | ||
// we check its type and handle accordingly. | ||
const paymentMethodId = typeof setupIntent.payment_method === 'string' | ||
? setupIntent.payment_method | ||
: setupIntent.payment_method.id; | ||
// Set the payment method as the default for the customer | ||
await stripe_1.stripe.customers.update(checkoutSession.customer, { | ||
invoice_settings: { | ||
default_payment_method: paymentMethodId, | ||
}, | ||
}); | ||
await manageCustomerDetailsChange(checkoutSession.customer, paymentMethodId, client_reference_id); | ||
// Ensure the customer ID and payment method are valid | ||
if (!checkoutSession.customer || typeof checkoutSession.customer !== 'string') { | ||
throw new Error('Invalid customer ID'); | ||
} | ||
if (!setupIntent.payment_method || typeof setupIntent.payment_method !== 'string') { | ||
throw new Error('Invalid payment method ID'); | ||
} | ||
// Set the payment method as the default for the customer | ||
await stripe_1.stripe.customers.update(checkoutSession.customer, { | ||
invoice_settings: { | ||
default_payment_method: setupIntent.payment_method, | ||
}, | ||
}); | ||
await manageCustomerDetailsChange(checkoutSession.customer, setupIntent.payment_method, client_reference_id); | ||
} | ||
@@ -40,0 +40,0 @@ catch (error) { |
{ | ||
"name": "next-stripe-helper", | ||
"version": "1.1.23", | ||
"version": "1.1.24", | ||
"description": "Easily add Stripe boilerplate code to Nextjs, like webhook handling, and subscription updates. This package provides a thin wrapper around the Stripe API, and makes integrating Stripe and NextJS a lot faster!", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -41,22 +41,24 @@ import Stripe from 'stripe'; | ||
); | ||
if (setupIntent.payment_method) { | ||
// Assuming payment_method is either a string or a PaymentMethod object, | ||
// we check its type and handle accordingly. | ||
const paymentMethodId = typeof setupIntent.payment_method === 'string' | ||
? setupIntent.payment_method | ||
: setupIntent.payment_method.id; | ||
// Set the payment method as the default for the customer | ||
await stripe.customers.update(checkoutSession.customer as string, { | ||
invoice_settings: { | ||
default_payment_method: paymentMethodId, | ||
}, | ||
}); | ||
await manageCustomerDetailsChange( | ||
checkoutSession.customer as string, | ||
paymentMethodId, | ||
client_reference_id | ||
); | ||
// Ensure the customer ID and payment method are valid | ||
if (!checkoutSession.customer || typeof checkoutSession.customer !== 'string') { | ||
throw new Error('Invalid customer ID'); | ||
} | ||
if (!setupIntent.payment_method || typeof setupIntent.payment_method !== 'string') { | ||
throw new Error('Invalid payment method ID'); | ||
} | ||
// Set the payment method as the default for the customer | ||
await stripe.customers.update(checkoutSession.customer, { | ||
invoice_settings: { | ||
default_payment_method: setupIntent.payment_method, | ||
}, | ||
}); | ||
await manageCustomerDetailsChange( | ||
checkoutSession.customer, | ||
setupIntent.payment_method, | ||
client_reference_id | ||
); | ||
} catch (error) { | ||
@@ -66,3 +68,4 @@ console.error("Failed to update customer's default payment method:", error); | ||
} | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
110071