From 220c68d196d3ce09c9d52b0166dafde9705939e1 Mon Sep 17 00:00:00 2001 From: Karol Wypchlo Date: Wed, 3 Mar 2021 16:21:26 +0100 Subject: [PATCH] payments --- .../src/pages/api/stripe/createCheckoutSession.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/dashboard/src/pages/api/stripe/createCheckoutSession.js b/packages/dashboard/src/pages/api/stripe/createCheckoutSession.js index eb7b7052..bc6191bd 100644 --- a/packages/dashboard/src/pages/api/stripe/createCheckoutSession.js +++ b/packages/dashboard/src/pages/api/stripe/createCheckoutSession.js @@ -30,10 +30,10 @@ export default async (req, res) => { // For full details see https://stripe.com/docs/api/checkout/sessions/create try { const authorization = req.headers.authorization; // authorization header from request - const { stripeCustomerId } = await got("http://accounts:3000/user", { headers: { authorization } }).json(); - const customer = await getStripeCustomer(stripeCustomerId); + const user = await got("http://accounts:3000/user", { headers: { authorization } }).json(); + const customer = await getStripeCustomer(user.stripeCustomerId); - if (!stripeCustomerId) { + if (!user.stripeCustomerId) { await got.put(`http://accounts:3000/user`, { headers: { authorization }, json: { stripeCustomerId: customer.id }, @@ -45,6 +45,7 @@ export default async (req, res) => { payment_method_types: ["card"], line_items: [{ price, quantity: 1 }], customer: customer.id, + customer_email: user.email, // ?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}`, cancel_url: `${process.env.SKYNET_DASHBOARD_URL}/payments`,