@@ -257,46 +257,45 @@ export function processMoonpaySellTx(rawTx: unknown): StandardTx {
257
257
return standardTx
258
258
}
259
259
260
+ const paymentMethodMap = {
261
+ ach_bank_transfer : 'ach' ,
262
+ apple_pay : 'applepay' ,
263
+ credit_debit_card : 'credit' ,
264
+ gbp_open_banking_payment : 'fasterpayments' ,
265
+ google_pay : 'googlepay' ,
266
+ moonpay_balance : 'moonpaybalance' ,
267
+ paypal : 'paypal' ,
268
+ pix_instant_payment : 'pix' ,
269
+ revolut_pay : 'revolut' ,
270
+ sepa_bank_transfer : 'sepa' ,
271
+ venmo : 'venmo' ,
272
+ yellow_card_bank_transfer : 'yellowcard'
273
+ }
274
+
260
275
function getFiatPaymentType (
261
276
tx : MoonpayTx | MoonpaySellTx
262
277
) : FiatPaymentType | null {
278
+ let paymentMethod : FiatPaymentType | null = null
263
279
switch ( tx . paymentMethod ) {
264
280
case undefined :
265
281
return null
266
- case 'ach_bank_transfer' :
267
- return 'ach'
268
- case 'apple_pay' :
269
- return 'applepay'
270
- case 'credit_debit_card' :
271
- return 'credit'
272
- case 'gbp_open_banking_payment' :
273
- return 'fasterpayments'
274
- case 'google_pay' :
275
- return 'googlepay'
276
282
case 'mobile_wallet' :
277
283
// Older versions of Moonpay data had a separate cardType field.
278
- return 'cardType' in tx
279
- ? tx . cardType === 'apple_pay'
280
- ? 'applepay'
281
- : tx . cardType === 'google_pay'
282
- ? 'googlepay'
284
+ paymentMethod =
285
+ 'cardType' in tx
286
+ ? tx . cardType === 'apple_pay'
287
+ ? 'applepay'
288
+ : tx . cardType === 'google_pay'
289
+ ? 'googlepay'
290
+ : null
283
291
: null
284
- : null
285
- case 'moonpay_balance' :
286
- return 'moonpaybalance'
287
- case 'paypal' :
288
- return 'paypal'
289
- case 'pix_instant_payment' :
290
- return 'pix'
291
- case 'sepa_bank_transfer' :
292
- return 'sepa'
293
- case 'venmo' :
294
- return 'venmo'
295
- case 'yellow_card_bank_transfer' :
296
- return 'yellowcard'
292
+ break
297
293
default :
298
- throw new Error (
299
- `Unknown payment method: ${ tx . paymentMethod } for ${ tx . id } `
300
- )
294
+ paymentMethod = paymentMethodMap [ tx . paymentMethod ]
295
+ break
296
+ }
297
+ if ( paymentMethod == null ) {
298
+ throw new Error ( `Unknown payment method: ${ tx . paymentMethod } for ${ tx . id } ` )
301
299
}
300
+ return paymentMethod
302
301
}
0 commit comments