This commit is contained in:
Karol Wypchlo 2021-03-03 16:21:26 +01:00
parent c8c9d216ee
commit 220c68d196
1 changed files with 4 additions and 3 deletions

View File

@ -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`,