This commit is contained in:
adueck 2022-10-13 19:56:40 +05:00
parent 0cf6daf434
commit a8964793af
1 changed files with 4 additions and 1 deletions

View File

@ -8,6 +8,8 @@ const stripe = new Stripe(env.stripeSecretKey, {
});
const paymentRouter = express.Router();
const endpointSecret = env.stripeWebhookSecret;
console.log({ endpointSecret });
paymentRouter.post(
'/webhook',
@ -18,12 +20,13 @@ paymentRouter.post(
// If you are testing with the CLI, find the secret by running 'stripe listen'
// If you are using an endpoint defined with the API or dashboard, look in your webhook settings
// at https://dashboard.stripe.com/webhooks
const endpointSecret = env.stripeWebhookSecret;
// Only verify the event if you have an endpoint secret defined.
// Otherwise use the basic event deserialized with JSON.parse
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,