Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/ramps-controller/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed

- Fix Transak Native deposits failing on staging/UAT with a 400 `paymentMethod is required parameter` error by mapping canonical payment method IDs supplied without the `/payments/` prefix (e.g. `apple-pay`) to their deposit-format equivalents, in addition to the prefixed forms (e.g. `/payments/apple-pay`) ([#8980](https://github.com/MetaMask/core/pull/8980))

## [14.1.0]

### Added
Expand Down
22 changes: 22 additions & 0 deletions packages/ramps-controller/src/TransakService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1172,6 +1172,28 @@ describe('TransakService', () => {
expect(await promise).toStrictEqual(MOCK_TRANSLATION);
});

it('normalizes canonical payment method IDs without the /payments/ prefix', async () => {
nock(STAGING_ORDERS_BASE)
.get(`${STAGING_PROVIDER_PATH}/native/translate`)
.query(
(query) =>
query.paymentMethod === 'apple_pay' &&
query.fiatCurrencyId === 'USD',
)
.reply(200, MOCK_TRANSLATION);

const { service } = getService();

const promise = service.getTranslation({
fiatCurrencyId: 'USD',
paymentMethod: 'apple-pay',
});
await jest.runAllTimersAsync();
await flushPromises();

expect(await promise).toStrictEqual(MOCK_TRANSLATION);
});

it('passes through payment methods already in deposit format', async () => {
nock(STAGING_ORDERS_BASE)
.get(`${STAGING_PROVIDER_PATH}/native/translate`)
Expand Down
17 changes: 14 additions & 3 deletions packages/ramps-controller/src/TransakService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,10 @@ export type TransakServiceMessenger = Messenger<
* (e.g., "credit_debit_card").
*
* The translation endpoint only understands the deposit-format IDs.
* If no mapping exists, the input is returned as-is (it may already be
* in the deposit format).
* Canonical IDs may arrive either with the "/payments/" prefix
* (e.g., "/payments/apple-pay") or without it (e.g., "apple-pay"), so both
* forms are accepted. If no mapping exists, the input is returned as-is (it
* may already be in the deposit format).
*/
const RAMPS_TO_DEPOSIT_PAYMENT_METHOD: Record<string, string> = {
'/payments/debit-credit-card': 'credit_debit_card',
Expand All @@ -366,13 +368,22 @@ const RAMPS_TO_DEPOSIT_PAYMENT_METHOD: Record<string, string> = {
'/payments/gbp-bank-transfer': 'gbp_bank_transfer',
};

const PAYMENTS_PREFIX = '/payments/';

function normalizePaymentMethodForTranslation(
paymentMethod: string | undefined,
): string | undefined {
if (!paymentMethod) {
return undefined;
}
return RAMPS_TO_DEPOSIT_PAYMENT_METHOD[paymentMethod] ?? paymentMethod;
const prefixed = paymentMethod.startsWith(PAYMENTS_PREFIX)
? paymentMethod
: `${PAYMENTS_PREFIX}${paymentMethod}`;
return (
RAMPS_TO_DEPOSIT_PAYMENT_METHOD[paymentMethod] ??
RAMPS_TO_DEPOSIT_PAYMENT_METHOD[prefixed] ??
paymentMethod
);
}

function getTransakApiBaseUrl(environment: TransakEnvironment): string {
Expand Down
Loading