From 97cb2be7e482bc1a1554db75e84f419ee29910c5 Mon Sep 17 00:00:00 2001 From: aiirvizionz Date: Mon, 13 Jul 2026 11:48:47 -0600 Subject: [PATCH] fix(payment-coinpay): normalize webhook status case --- packages/payments/coinpay/src/index.test.ts | 6 +++--- packages/payments/coinpay/src/index.ts | 11 ++++++----- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/packages/payments/coinpay/src/index.test.ts b/packages/payments/coinpay/src/index.test.ts index 122729bd..96d11548 100644 --- a/packages/payments/coinpay/src/index.test.ts +++ b/packages/payments/coinpay/src/index.test.ts @@ -137,10 +137,10 @@ describe('payment-coinpay', () => { it('verifies CoinPay webhook signatures and normalizes payment events', async () => { const raw = JSON.stringify({ id: 'evt_pay_123', - type: 'payment.confirmed', + type: 'Payment.Confirmed', data: { payment_id: 'pay_123', - status: 'confirmed', + status: 'PAID', amount_usd: '24.40', currency: 'USDC', metadata: { customer_email: 'buyer@example.com' }, @@ -160,7 +160,7 @@ describe('payment-coinpay', () => { ); expect(webhook).toMatchObject({ - type: 'payment.confirmed', + type: 'Payment.Confirmed', paymentId: 'pay_123', status: 'succeeded', amount: 2440, diff --git a/packages/payments/coinpay/src/index.ts b/packages/payments/coinpay/src/index.ts index 3f337390..895d3ba1 100644 --- a/packages/payments/coinpay/src/index.ts +++ b/packages/payments/coinpay/src/index.ts @@ -247,13 +247,14 @@ function normalizeWebhook(event: CoinPayWebhookEvent): Webhook { function normalizeStatus(status: string | undefined): Webhook['status'] | undefined { if (!status) return undefined; - if (['confirmed', 'forwarded', 'succeeded', 'paid', 'payment.confirmed', 'payment.forwarded'].includes(status)) { + const normalized = status.trim().toLowerCase(); + if (['confirmed', 'forwarded', 'succeeded', 'paid', 'payment.confirmed', 'payment.forwarded'].includes(normalized)) { return 'succeeded'; } - if (['pending', 'awaiting_payment', 'processing', 'created'].includes(status)) return 'pending'; - if (['expired', 'failed', 'cancelled', 'canceled', 'payment.expired'].includes(status)) return 'failed'; - if (status === 'refunded') return 'refunded'; - if (status === 'disputed') return 'disputed'; + if (['pending', 'awaiting_payment', 'processing', 'created'].includes(normalized)) return 'pending'; + if (['expired', 'failed', 'cancelled', 'canceled', 'payment.expired'].includes(normalized)) return 'failed'; + if (normalized === 'refunded') return 'refunded'; + if (normalized === 'disputed') return 'disputed'; return undefined; }