This commit is contained in:
Karol Wypchlo 2021-03-03 16:30:06 +01:00
parent 932a7f10a8
commit 5ce0f73293
1 changed files with 9 additions and 8 deletions

View File

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