UNPKG

@lomray/microservice-payment-stripe

Version:

Stripe payment microservice based on NodeJS & inverted json.

29 lines (25 loc) 973 B
'use strict'; var fromSmallestUnit = require('@lomray/microservices-client-api/helpers/parsers/from-smallest-unit'); var balanceType = require('../constants/balance-type.js'); /** * Convert unit balance from unit */ const convertBalanceFromUnit = (balance) => { const currencies = { usd: 0, eur: 0 }; const convertedInput = { [balanceType.INSTANT]: Object.assign({}, currencies), [balanceType.PENDING]: Object.assign({}, currencies), [balanceType.AVAILABLE]: Object.assign({}, currencies), }; Object.keys(balance).forEach((type) => { if (!convertedInput[type]) { convertedInput[type] = currencies; } Object.keys(balance[type]).forEach((currency) => { var _a; convertedInput[type][currency] = (_a = fromSmallestUnit(balance[type][currency])) !== null && _a !== void 0 ? _a : 0; }); }); return convertedInput; }; module.exports = convertBalanceFromUnit;