import NP from 'number-precision' ; import { PAYMENT_CURRENCY , PAYMENT_PROVIDER } from 'common/enums' ; NP . enableBoundaryChecking ( false ) ; export const numRound = ( num , decPlaces = 2 ) => { return NP . round ( num , decPlaces ) ; } ; export const numDivide = ( num1 , num2 ) => { return NP . divide ( num1 , num2 ) ; } ; export const numMinus = ( num1 , num2 ) => { return NP . minus ( num1 , num2 ) ; } ; see { url interface ToAmountArgs { amount : number ; currency ? : PAYMENT_CURRENCY ; provider ? : Exclude < PAYMENT_PROVIDER , PAYMENT_PROVIDER . likecoin | PAYMENT_PROVIDER . matters > ; } const PROVIDER_CURRENCY_RATE = { stripe : { HKD : 100 , USD : 100 , LIKE : 1 , } , } ; export const toProviderAmount = ( { amount , currency = PAYMENT_CURRENCY . HKD , provider = PAYMENT_PROVIDER . stripe , } ) => { const rate = PROVIDER_CURRENCY_RATE [ provider ] [ currency ] ; return NP . times ( amount , rate ) ; } ; /**
 * Convert provider amount to DB amount
 */ export const toDBAmount = ( { amount , currency = PAYMENT_CURRENCY . HKD , provider = PAYMENT_PROVIDER . stripe , } ) => { const rate = PROVIDER_CURRENCY_RATE [ provider ] [ currency ] ; return NP . divide ( amount , rate ) ; } ; see { url see { url const FEE_FIXED = 2.35 ; const FEE_PERCENT = 0.034 ; export const calcStripeFee = ( amount ) => { const charge = ( amount + FEE_FIXED ) / ( 1 - FEE_PERCENT ) ; const fee = charge - amount ; return numRound ( fee ) ; } ; const FEE_MATTERS = 0.2 ; export const calcMattersFee = ( amount ) => { return numRound ( amount * FEE_MATTERS ) ; } ;