From f2115f2ba495a2868a89c3082fb3ab508c0cea64 Mon Sep 17 00:00:00 2001 From: Jonathan Barrow Date: Sat, 1 Oct 2022 11:42:14 -0400 Subject: [PATCH] Moved webhook timestamp check to after PNID check --- src/util.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/util.js b/src/util.js index a5a9bbf..6729b2a 100644 --- a/src/util.js +++ b/src/util.js @@ -263,13 +263,6 @@ async function handleStripeEvent(event) { const pid = Number(customer.metadata.pnid_pid); const pnid = await database.PNID.findOne({ pid }); - const latestWebhookTimestamp = pnid.get('connections.stripe.latest_webhook_timestamp'); - - if (latestWebhookTimestamp && latestWebhookTimestamp > event.created) { - // Do nothing, this webhook is older than the latest seen - return; - } - if (!pnid && subscription.status !== 'canceled' && subscription.status !== 'unpaid') { // PNID does not exist. Abort and refund! logger.error(`PNID PID ${pid} does not exist! Found on Stripe user ${customer.id}! Refunding order`); @@ -294,6 +287,13 @@ async function handleStripeEvent(event) { return; } + const latestWebhookTimestamp = pnid.get('connections.stripe.latest_webhook_timestamp'); + + if (latestWebhookTimestamp && latestWebhookTimestamp > event.created) { + // Do nothing, this webhook is older than the latest seen + return; + } + const currentSubscriptionId = pnid.get('connections.stripe.subscription_id'); const discordId = pnid.get('connections.discord.id');