From 6a2edf96be5351b8e5d02c0a443a877bb47bcdf6 Mon Sep 17 00:00:00 2001 From: adueck Date: Thu, 13 Oct 2022 20:12:31 +0500 Subject: [PATCH] userId should go to metadata on webhook now --- account/src/index.ts | 2 +- account/src/routers/payment-router.ts | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/account/src/index.ts b/account/src/index.ts index c29641a..c95dba6 100644 --- a/account/src/index.ts +++ b/account/src/index.ts @@ -13,7 +13,7 @@ const app = express(); // MIDDLEWARE AND SETUP 🔧 // app.set("view engine", "ejs"); -app.use("/payment/webhook", express.raw({type: "*/*"})) +app.use("/payment/webhook", express.raw({type: "*/*"})); app.use(express.json()); app.use(express.urlencoded({ extended: true })); app.use(express.static("public")); diff --git a/account/src/routers/payment-router.ts b/account/src/routers/payment-router.ts index b97752a..03fe6f0 100644 --- a/account/src/routers/payment-router.ts +++ b/account/src/routers/payment-router.ts @@ -8,8 +8,6 @@ const stripe = new Stripe(env.stripeSecretKey, { }); const paymentRouter = express.Router(); -const endpointSecret = env.stripeWebhookSecret; -console.log({ endpointSecret }); paymentRouter.post( '/webhook', @@ -22,11 +20,10 @@ paymentRouter.post( // at https://dashboard.stripe.com/webhooks // Only verify the event if you have an endpoint secret defined. // Otherwise use the basic event deserialized with JSON.parse + const endpointSecret = env.stripeWebhookSecret; if (endpointSecret) { // Get the signature sent by Stripe const signature = request.headers['stripe-signature'] || ""; - console.log(request.headers); - console.log({ signature, endpointSecret }); try { event = stripe.webhooks.constructEvent( request.body, @@ -53,8 +50,7 @@ paymentRouter.post( subscription = event.data.object; status = subscription.status; console.log(`Subscription status is ${status}.`); - console.log(subscription); - console.log(subscription.metadata); + console.log({ userId: subscription.metadata.userId }); // Then define and call a method to handle the subscription created. // handleSubscriptionCreated(subscription); break; @@ -94,7 +90,11 @@ paymentRouter.post("/create-checkout-session", async (req, res, next) => { quantity: 1, }, ], - client_reference_id: req.user.userId, + subscription_data: { + metadata: { + userId: req.user.userId, + } + }, mode: 'subscription', success_url: `https://account.lingdocs.com/user?upgrade=success`, cancel_url: `https://account.lingdocs.com/user`,