@@ -13,6 +13,7 @@ import { Response } from 'node-fetch'
1313
1414import {
1515 EDGE_APP_START_DATE ,
16+ FiatPaymentType ,
1617 PartnerPlugin ,
1718 PluginParams ,
1819 PluginResult ,
@@ -32,6 +33,7 @@ export const asBanxaParams = asObject({
3233 } )
3334} )
3435
36+ type BanxaStatus = ReturnType < typeof asBanxaStatus >
3537const asBanxaStatus = asMaybe (
3638 asValue (
3739 'complete' ,
@@ -44,15 +46,18 @@ const asBanxaStatus = asMaybe(
4446 'other'
4547)
4648
49+ type BanxaTx = ReturnType < typeof asBanxaTx >
4750const asBanxaTx = asObject ( {
4851 id : asString ,
4952 status : asBanxaStatus ,
5053 created_at : asString ,
54+ country : asString ,
5155 fiat_amount : asNumber ,
5256 fiat_code : asString ,
5357 coin_amount : asNumber ,
5458 coin_code : asString ,
5559 order_type : asString ,
60+ payment_type : asString ,
5661 wallet_address : asMaybe ( asString , '' )
5762} )
5863
@@ -67,9 +72,6 @@ const PAGE_LIMIT = 100
6772const ONE_DAY_MS = 1000 * 60 * 60 * 24
6873const ROLLBACK = ONE_DAY_MS * 7 // 7 days
6974
70- type BanxaTx = ReturnType < typeof asBanxaTx >
71- type BanxaStatus = ReturnType < typeof asBanxaStatus >
72-
7375const statusMap : { [ key in BanxaStatus ] : Status } = {
7476 complete : 'complete' ,
7577 expired : 'expired' ,
@@ -263,13 +265,21 @@ export function processBanxaTx(rawTx: unknown): StandardTx {
263265 payoutAddress = banxaTx . wallet_address
264266 }
265267
268+ const direction = banxaTx . order_type === 'CRYPTO-SELL' ? 'sell' : 'buy'
269+
270+ const paymentType = getFiatPaymentType ( banxaTx )
271+
266272 const standardTx : StandardTx = {
267273 status : statusMap [ banxaTx . status ] ,
268274 orderId : banxaTx . id ,
275+ countryCode : banxaTx . country ,
269276 depositTxid : undefined ,
270277 depositAddress : undefined ,
271278 depositCurrency : inputCurrency ,
272279 depositAmount : inputAmount ,
280+ direction,
281+ exchangeType : 'fiat' ,
282+ paymentType,
273283 payoutTxid : undefined ,
274284 payoutAddress,
275285 payoutCurrency : outputCurrency ,
@@ -282,3 +292,40 @@ export function processBanxaTx(rawTx: unknown): StandardTx {
282292
283293 return standardTx
284294}
295+
296+ function getFiatPaymentType ( tx : BanxaTx ) : FiatPaymentType {
297+ switch ( tx . payment_type ) {
298+ case 'AusPost Retail' :
299+ case 'BPay' :
300+ case 'Blueshyft Online' :
301+ case 'POLi Transfer' :
302+ case 'Sofort Transfer' :
303+ return 'directtobank'
304+ case 'Checkout Credit Card' :
305+ case 'WorldPay Credit Card' :
306+ return 'credit'
307+ case 'ClearJunction Fast Pay' :
308+ case 'ClearJunction Sell Fast Pay' :
309+ return 'fasterpayments'
310+ case 'ClearJunction Sepa' :
311+ case 'Ten31 Sepa' :
312+ return 'sepa'
313+ case 'DCBank Interac' :
314+ case 'DCBank Interac Sell' :
315+ return 'interac'
316+ case 'Enumis Transfer' :
317+ return 'wire'
318+ case 'Monoova Sell' :
319+ case 'NPP PayID' :
320+ case 'PayID via Monoova' :
321+ return 'payid'
322+ case 'WorldPay ApplePay' :
323+ return 'applepay'
324+ case 'WorldPay GooglePay' :
325+ return 'googlepay'
326+ case 'iDEAL Transfer' :
327+ return 'ideal'
328+ default :
329+ throw new Error ( `Unknown payment method: ${ tx . payment_type } for ${ tx . id } ` )
330+ }
331+ }
0 commit comments