[web] purchase: use consistent idempotency params when creating Stripe customer + add network retries
(cherry picked from commit 2953fa0a4205c11c3fc5dd3de67976ad16407dc4)
This commit is contained in:
parent
6e6dbc8040
commit
bf02fdef1f
|
|
@ -65,6 +65,7 @@ export async function POST(req: NextRequest) {
|
|||
|
||||
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!, {
|
||||
apiVersion: '2023-10-16',
|
||||
maxNetworkRetries: 2,
|
||||
});
|
||||
|
||||
// This is needed because sometimes this hook is called after the
|
||||
|
|
@ -94,9 +95,10 @@ export async function POST(req: NextRequest) {
|
|||
}
|
||||
|
||||
const customer = await stripe.customers.create(
|
||||
// Keep parameters across customer creation synced
|
||||
// because they use the same idempotency key
|
||||
{
|
||||
email: user.email,
|
||||
name: user.user_metadata.name,
|
||||
},
|
||||
{
|
||||
idempotencyKey: user.id,
|
||||
|
|
|
|||
|
|
@ -111,9 +111,12 @@ export default async function handler(req: NextRequest) {
|
|||
|
||||
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!, {
|
||||
apiVersion: '2023-10-16',
|
||||
maxNetworkRetries: 2,
|
||||
});
|
||||
|
||||
const customer = await stripe.customers.create(
|
||||
// Keep parameters across customer creation synced
|
||||
// because they use the same idempotency key
|
||||
{
|
||||
email: user.email,
|
||||
},
|
||||
|
|
|
|||
|
|
@ -395,6 +395,7 @@ export const promotionsRouter = router({
|
|||
|
||||
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY as string, {
|
||||
apiVersion: '2023-10-16',
|
||||
maxNetworkRetries: 2,
|
||||
});
|
||||
|
||||
let stripeCustomer = profile?.stripeCustomer;
|
||||
|
|
@ -412,9 +413,10 @@ export const promotionsRouter = router({
|
|||
}
|
||||
|
||||
const newCustomer = await stripe.customers.create(
|
||||
// Keep parameters across customer creation synced
|
||||
// because they use the same idempotency key
|
||||
{
|
||||
email: user.email,
|
||||
name: user.user_metadata.name,
|
||||
},
|
||||
{
|
||||
idempotencyKey: user.id,
|
||||
|
|
|
|||
Loading…
Reference in New Issue