userId should go to metadata on webhook now
This commit is contained in:
parent
7ef471d530
commit
6a2edf96be
|
@ -13,7 +13,7 @@ const app = express();
|
||||||
|
|
||||||
// MIDDLEWARE AND SETUP 🔧 //
|
// MIDDLEWARE AND SETUP 🔧 //
|
||||||
app.set("view engine", "ejs");
|
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.json());
|
||||||
app.use(express.urlencoded({ extended: true }));
|
app.use(express.urlencoded({ extended: true }));
|
||||||
app.use(express.static("public"));
|
app.use(express.static("public"));
|
||||||
|
|
|
@ -8,8 +8,6 @@ const stripe = new Stripe(env.stripeSecretKey, {
|
||||||
});
|
});
|
||||||
|
|
||||||
const paymentRouter = express.Router();
|
const paymentRouter = express.Router();
|
||||||
const endpointSecret = env.stripeWebhookSecret;
|
|
||||||
console.log({ endpointSecret });
|
|
||||||
|
|
||||||
paymentRouter.post(
|
paymentRouter.post(
|
||||||
'/webhook',
|
'/webhook',
|
||||||
|
@ -22,11 +20,10 @@ paymentRouter.post(
|
||||||
// at https://dashboard.stripe.com/webhooks
|
// at https://dashboard.stripe.com/webhooks
|
||||||
// Only verify the event if you have an endpoint secret defined.
|
// Only verify the event if you have an endpoint secret defined.
|
||||||
// Otherwise use the basic event deserialized with JSON.parse
|
// Otherwise use the basic event deserialized with JSON.parse
|
||||||
|
const endpointSecret = env.stripeWebhookSecret;
|
||||||
if (endpointSecret) {
|
if (endpointSecret) {
|
||||||
// Get the signature sent by Stripe
|
// Get the signature sent by Stripe
|
||||||
const signature = request.headers['stripe-signature'] || "";
|
const signature = request.headers['stripe-signature'] || "";
|
||||||
console.log(request.headers);
|
|
||||||
console.log({ signature, endpointSecret });
|
|
||||||
try {
|
try {
|
||||||
event = stripe.webhooks.constructEvent(
|
event = stripe.webhooks.constructEvent(
|
||||||
request.body,
|
request.body,
|
||||||
|
@ -53,8 +50,7 @@ paymentRouter.post(
|
||||||
subscription = event.data.object;
|
subscription = event.data.object;
|
||||||
status = subscription.status;
|
status = subscription.status;
|
||||||
console.log(`Subscription status is ${status}.`);
|
console.log(`Subscription status is ${status}.`);
|
||||||
console.log(subscription);
|
console.log({ userId: subscription.metadata.userId });
|
||||||
console.log(subscription.metadata);
|
|
||||||
// Then define and call a method to handle the subscription created.
|
// Then define and call a method to handle the subscription created.
|
||||||
// handleSubscriptionCreated(subscription);
|
// handleSubscriptionCreated(subscription);
|
||||||
break;
|
break;
|
||||||
|
@ -94,7 +90,11 @@ paymentRouter.post("/create-checkout-session", async (req, res, next) => {
|
||||||
quantity: 1,
|
quantity: 1,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
client_reference_id: req.user.userId,
|
subscription_data: {
|
||||||
|
metadata: {
|
||||||
|
userId: req.user.userId,
|
||||||
|
}
|
||||||
|
},
|
||||||
mode: 'subscription',
|
mode: 'subscription',
|
||||||
success_url: `https://account.lingdocs.com/user?upgrade=success`,
|
success_url: `https://account.lingdocs.com/user?upgrade=success`,
|
||||||
cancel_url: `https://account.lingdocs.com/user`,
|
cancel_url: `https://account.lingdocs.com/user`,
|
||||||
|
|
Loading…
Reference in New Issue