Skip to content

Commit e093f3d

Browse files
committed
add errorCode field to TransakService
1 parent a0dc078 commit e093f3d

2 files changed

Lines changed: 43 additions & 0 deletions

File tree

packages/ramps-controller/src/TransakService.test.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1686,6 +1686,48 @@ describe('TransakService', () => {
16861686
await expect(promise).rejects.toThrow("failed with status '503'");
16871687
});
16881688

1689+
it('passes through errorCode from the API response when present', async () => {
1690+
const depositOrderId = `${STAGING_PROVIDER_PATH}/orders/order-abc-123`;
1691+
const orderWithErrorCode = {
1692+
...MOCK_DEPOSIT_ORDER,
1693+
status: 'FAILED',
1694+
errorCode: '4005',
1695+
};
1696+
1697+
nock(STAGING_ORDERS_BASE)
1698+
.get(`${STAGING_PROVIDER_PATH}/orders/order-abc-123`)
1699+
.query(true)
1700+
.reply(200, orderWithErrorCode);
1701+
1702+
const { service } = getService();
1703+
1704+
const promise = service.getOrder(depositOrderId, '0x1234');
1705+
await jest.runAllTimersAsync();
1706+
await flushPromises();
1707+
const result = await promise;
1708+
1709+
expect(result.errorCode).toBe('4005');
1710+
expect(result.status).toBe('FAILED');
1711+
});
1712+
1713+
it('returns undefined errorCode when not present in the API response', async () => {
1714+
const depositOrderId = `${STAGING_PROVIDER_PATH}/orders/order-abc-123`;
1715+
1716+
nock(STAGING_ORDERS_BASE)
1717+
.get(`${STAGING_PROVIDER_PATH}/orders/order-abc-123`)
1718+
.query(true)
1719+
.reply(200, MOCK_DEPOSIT_ORDER);
1720+
1721+
const { service } = getService();
1722+
1723+
const promise = service.getOrder(depositOrderId, '0x1234');
1724+
await jest.runAllTimersAsync();
1725+
await flushPromises();
1726+
const result = await promise;
1727+
1728+
expect(result.errorCode).toBeUndefined();
1729+
});
1730+
16891731
it('gracefully handles failure when fetching paymentDetails from Transak', async () => {
16901732
const depositOrderId = `${STAGING_PROVIDER_PATH}/orders/order-abc-123`;
16911733
const orderWithoutPaymentDetails = {

packages/ramps-controller/src/TransakService.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ export type TransakDepositOrder = {
183183
orderType: 'DEPOSIT';
184184
exchangeRate?: number;
185185
statusDescription?: string;
186+
errorCode?: string;
186187
paymentDetails: TransakOrderPaymentMethod[];
187188
partnerFees?: number;
188189
networkFees?: number;

0 commit comments

Comments
 (0)