accounts/**

This commit is contained in:
Karol Wypchlo 2021-02-24 17:20:46 +01:00
parent b453713474
commit 1e770227d0
2 changed files with 27 additions and 1 deletions

View File

@ -18,6 +18,7 @@
"dayjs": "^1.10.4",
"express-jwt": "^6.0.0",
"formik": "^2.2.6",
"got": "^11.8.1",
"http-status-codes": "^2.1.4",
"jwks-rsa": "^1.12.2",
"ky": "0.25.1",

View File

@ -1,8 +1,32 @@
import got from "got";
import Stripe from "stripe";
import { StatusCodes } from "http-status-codes";
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY);
const getAuthenticatedUser = async () => {
const { body } = await got.get("http://user", {
json: {
hello: "world",
},
responseType: "json",
});
};
const getStripeCustomerId = async (req) => {
console.log(req.header);
console.log(req.headers);
// const user = got(`http://accounts:3000/user/${userId}`).json();
// if (user.stripeCustomerId) {
// return user.stripeCustomerId;
// }
// const customer = await stripe.customers.create();
return "cus_J09ECKPgFEPXoq";
};
export default async (req, res) => {
if (req.method !== "POST") {
return res.status(StatusCodes.NOT_FOUND).end();
@ -21,7 +45,8 @@ export default async (req, res) => {
// [customer_email] - lets you prefill the email input in the form
// For full details see https://stripe.com/docs/api/checkout/sessions/create
try {
const stripeCustomerId = "cus_J09ECKPgFEPXoq";
const userId = req.headers["x-user"];
const stripeCustomerId = await getStripeCustomerId(userId);
const session = await stripe.checkout.sessions.create({
mode: "subscription",
payment_method_types: ["card"],