mirror of
https://github.com/PretendoNetwork/website.git
synced 2026-08-24 01:26:57 -05:00
Moved webhook timestamp check to after PNID check
This commit is contained in:
14
src/util.js
14
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');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user