Moved webhook timestamp check to after PNID check

This commit is contained in:
Jonathan Barrow 2022-10-01 11:42:14 -04:00
parent 885e4d7b17
commit f2115f2ba4
No known key found for this signature in database
GPG Key ID: E86E9FE9049C741F

View File

@ -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');