diff --git a/packages/ramps-controller/src/TransakService.test.ts b/packages/ramps-controller/src/TransakService.test.ts index 5cb1f029619..4444cea742e 100644 --- a/packages/ramps-controller/src/TransakService.test.ts +++ b/packages/ramps-controller/src/TransakService.test.ts @@ -1686,6 +1686,48 @@ describe('TransakService', () => { await expect(promise).rejects.toThrow("failed with status '503'"); }); + it('passes through errorCode from the API response when present', async () => { + const depositOrderId = `${STAGING_PROVIDER_PATH}/orders/order-abc-123`; + const orderWithErrorCode = { + ...MOCK_DEPOSIT_ORDER, + status: 'FAILED', + errorCode: '4005', + }; + + nock(STAGING_ORDERS_BASE) + .get(`${STAGING_PROVIDER_PATH}/orders/order-abc-123`) + .query(true) + .reply(200, orderWithErrorCode); + + const { service } = getService(); + + const promise = service.getOrder(depositOrderId, '0x1234'); + await jest.runAllTimersAsync(); + await flushPromises(); + const result = await promise; + + expect(result.errorCode).toBe('4005'); + expect(result.status).toBe('FAILED'); + }); + + it('returns undefined errorCode when not present in the API response', async () => { + const depositOrderId = `${STAGING_PROVIDER_PATH}/orders/order-abc-123`; + + nock(STAGING_ORDERS_BASE) + .get(`${STAGING_PROVIDER_PATH}/orders/order-abc-123`) + .query(true) + .reply(200, MOCK_DEPOSIT_ORDER); + + const { service } = getService(); + + const promise = service.getOrder(depositOrderId, '0x1234'); + await jest.runAllTimersAsync(); + await flushPromises(); + const result = await promise; + + expect(result.errorCode).toBeUndefined(); + }); + it('gracefully handles failure when fetching paymentDetails from Transak', async () => { const depositOrderId = `${STAGING_PROVIDER_PATH}/orders/order-abc-123`; const orderWithoutPaymentDetails = { diff --git a/packages/ramps-controller/src/TransakService.ts b/packages/ramps-controller/src/TransakService.ts index 9d3c41db42c..7c69b1a054a 100644 --- a/packages/ramps-controller/src/TransakService.ts +++ b/packages/ramps-controller/src/TransakService.ts @@ -183,6 +183,7 @@ export type TransakDepositOrder = { orderType: 'DEPOSIT'; exchangeRate?: number; statusDescription?: string; + errorCode?: string; paymentDetails: TransakOrderPaymentMethod[]; partnerFees?: number; networkFees?: number;