From 5ce0f73293e3794084a801e5b3c4f7b08cbc2f9a Mon Sep 17 00:00:00 2001 From: Karol Wypchlo Date: Wed, 3 Mar 2021 16:30:06 +0100 Subject: [PATCH] payments --- .../pages/api/stripe/createCheckoutSession.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/packages/dashboard/src/pages/api/stripe/createCheckoutSession.js b/packages/dashboard/src/pages/api/stripe/createCheckoutSession.js index 104d7ca6..dcbc894f 100644 --- a/packages/dashboard/src/pages/api/stripe/createCheckoutSession.js +++ b/packages/dashboard/src/pages/api/stripe/createCheckoutSession.js @@ -31,20 +31,21 @@ export default async (req, res) => { try { const authorization = req.headers.authorization; // authorization header from request const user = await got("http://accounts:3000/user", { headers: { authorization } }).json(); - const customer = await getStripeCustomer(user); + // const customer = await getStripeCustomer(user); - if (!user.stripeCustomerId) { - await got.put(`http://accounts:3000/user`, { - headers: { authorization }, - json: { stripeCustomerId: customer.id }, - }); - } + // if (!user.stripeCustomerId) { + // await got.put(`http://accounts:3000/user`, { + // headers: { authorization }, + // json: { stripeCustomerId: customer.id }, + // }); + // } const session = await stripe.checkout.sessions.create({ mode: "subscription", payment_method_types: ["card"], line_items: [{ price, quantity: 1 }], - customer: customer.id, + customer: user.stripeCustomerId, + customer_email: user.stripeCustomerId ? undefined : user.email, client_reference_id: user.id, // ?session_id={CHECKOUT_SESSION_ID} means the redirect will have the session ID set as a query param success_url: `${process.env.SKYNET_DASHBOARD_URL}/payments?session_id={CHECKOUT_SESSION_ID}`,