Handle PNID not found error on all subscription types

This commit is contained in:
Jonathan Barrow 2022-10-01 11:45:30 -04:00
parent f2115f2ba4
commit 9efb061a7e
No known key found for this signature in database
GPG Key ID: E86E9FE9049C741F

View File

@ -263,8 +263,10 @@ async function handleStripeEvent(event) {
const pid = Number(customer.metadata.pnid_pid);
const pnid = await database.PNID.findOne({ pid });
if (!pnid && subscription.status !== 'canceled' && subscription.status !== 'unpaid') {
// PNID does not exist. Abort and refund!
if (!pnid) {
// PNID does not exist
if (subscription.status !== 'canceled' && subscription.status !== 'unpaid') {
// Abort and refund!
logger.error(`PNID PID ${pid} does not exist! Found on Stripe user ${customer.id}! Refunding order`);
await stripe.subscriptions.del(subscription.id);
@ -283,6 +285,9 @@ async function handleStripeEvent(event) {
} catch (error) {
logger.error(`Error sending email | ${customer.id}, ${customer.email} | - ${error.message}`);
}
} else {
logger.error(`PNID PID ${pid} does not exist! Found on Stripe user ${customer.id}!`);
}
return;
}