fix(stripe): use new data structure for webhooks event.request

This commit is contained in:
Matteo Pagliazzi
2020-12-26 16:45:36 +01:00
parent bc74e40280
commit 17d918a172
2 changed files with 9 additions and 8 deletions

View File

@@ -32,6 +32,7 @@ export async function handleWebhooks (options, stripeInc) {
try {
// Verify the event by fetching it from Stripe
event = stripeApi.webhooks.constructEvent(body, headers['stripe-signature'], endpointSecret);
console.log(event);
} catch (err) {
logger.error(new Error('Error verifying Stripe webhook'), { err });
throw new BadRequest(`Webhook Error: ${err.message}`);
@@ -80,7 +81,7 @@ export async function handleWebhooks (options, stripeInc) {
case 'customer.subscription.deleted': {
// event.request !== null means that the user itself cancelled the subscrioption,
// the cancellation on our side has been already handled
if (event.request !== null) break;
if (event.request && event.request.id !== null) break;
const subscription = event.data.object;
const customerId = subscription.customer;