respond 200 to valid but unsupported paddle webhooks
This commit is contained in:
parent
cc4390d050
commit
3edf0cb471
@ -6,7 +6,7 @@ import type {
|
|||||||
PaddleSdkSubscriptionPaymentSucceededEvent,
|
PaddleSdkSubscriptionPaymentSucceededEvent,
|
||||||
PaddleSdkSubscriptionUpdatedEvent,
|
PaddleSdkSubscriptionUpdatedEvent,
|
||||||
} from "@devoxa/paddle-sdk";
|
} from "@devoxa/paddle-sdk";
|
||||||
import { PaddleSdkWebhookEventType } from "@devoxa/paddle-sdk";
|
import { PaddleSdkException, PaddleSdkWebhookEventType } from "@devoxa/paddle-sdk";
|
||||||
|
|
||||||
import type { ApiError } from "app/core/types";
|
import type { ApiError } from "app/core/types";
|
||||||
import subscriptionCreatedQueue from "../queue/subscription-created";
|
import subscriptionCreatedQueue from "../queue/subscription-created";
|
||||||
@ -47,17 +47,26 @@ const webhook: BlitzApiHandler = async (req, res) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const event = paddleSdk.parseWebhookEvent(req.body);
|
try {
|
||||||
const alertName = event.eventType;
|
const event = paddleSdk.parseWebhookEvent(req.body);
|
||||||
logger.info(`Received ${alertName} webhook`);
|
const alertName = event.eventType;
|
||||||
logger.info(event);
|
logger.info(`Received ${alertName} webhook`);
|
||||||
if (isSupportedWebhook(alertName)) {
|
logger.info(event);
|
||||||
await queues[alertName].enqueue({ event: event as Events }, { id: event.eventId.toString() });
|
if (isSupportedWebhook(alertName)) {
|
||||||
|
await queues[alertName].enqueue({ event: event as Events }, { id: event.eventId.toString() });
|
||||||
|
|
||||||
return res.status(200).end();
|
return res.status(200).end();
|
||||||
|
}
|
||||||
|
|
||||||
|
return res.status(400).end();
|
||||||
|
} catch (error) {
|
||||||
|
if (error instanceof PaddleSdkException && error.message.includes(req.body.alert_name)) {
|
||||||
|
// event implementation is missing such as `subscription_payment_refunded`
|
||||||
|
return res.status(200).end();
|
||||||
|
}
|
||||||
|
|
||||||
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
||||||
return res.status(400).end();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default webhook;
|
export default webhook;
|
||||||
|
Loading…
Reference in New Issue
Block a user