fix(btcpay webhook handler): respond with 200 immediately if there is no metadata

This commit is contained in:
Artur
2024-10-10 12:24:53 -03:00
parent 73e08ce1a7
commit 437dccd917

View File

@@ -27,7 +27,7 @@ type BtcpayBody = Record<string, any> & {
timestamp: number
storeId: string
invoiceId: string
metadata: DonationMetadata
metadata?: DonationMetadata
paymentMethod: string
}
@@ -59,6 +59,10 @@ async function handleBtcpayWebhook(req: NextApiRequest, res: NextApiResponse) {
return
}
if (!body.metadata) {
return res.status(200).json({ success: true })
}
if (body.type === 'InvoicePaymentSettled') {
// Handle payments to funding required API invoices ONLY
if (body.metadata.staticGeneratedForApi === 'false') {
@@ -105,6 +109,8 @@ async function handleBtcpayWebhook(req: NextApiRequest, res: NextApiResponse) {
await Promise.all(
paymentMethods.map(async (paymentMethod) => {
if (!body.metadata) return
const cryptoAmount = Number(paymentMethod.paymentMethodPaid)
if (!cryptoAmount) return