fix: sms receipt data construction
This commit is contained in:
parent
9506b98b47
commit
154fe7affb
3 changed files with 47 additions and 45 deletions
45
lib/sms.js
45
lib/sms.js
|
|
@ -1,10 +1,5 @@
|
|||
const { BigNumber } = require('bignumber.js')
|
||||
const ph = require('./plugin-helper')
|
||||
const argv = require('minimist')(process.argv.slice(2))
|
||||
const { getTx } = require('./new-admin/services/transactions.js')
|
||||
const { getCustomerById } = require('./customers')
|
||||
const configManager = require('./new-config-manager')
|
||||
const machineLoader = require('./machine-loader')
|
||||
const { utils: coinUtils } = require('lamassu-coins')
|
||||
|
||||
function getPlugin (settings) {
|
||||
|
|
@ -32,43 +27,7 @@ function getLookup (settings, number) {
|
|||
}
|
||||
const toCryptoUnits = (cryptoAtoms, cryptoCode) => {
|
||||
const unitScale = coinUtils.getCryptoCurrency(cryptoCode).unitScale
|
||||
return cryptoAtoms.shift(-unitScale)
|
||||
}
|
||||
|
||||
function buildSms (data, receiptOptions) {
|
||||
return getTx(data.session, data.txClass)
|
||||
.then(tx => {
|
||||
Promise.all([getCustomerById(tx.customer_id), machineLoader.getConfig(), machineLoader.getMachine()])
|
||||
.then(([customer, config, deviceConfig]) => {
|
||||
const localeConfig = configManager.getLocale(tx.device_id, config)
|
||||
const timezone = localeConfig.timezone.split(':')
|
||||
const dstOffset = timezone[1]
|
||||
|
||||
const cashInCommission = BigNumber(1).add(BigNumber(tx.commissionPercentage))
|
||||
|
||||
const rate = BigNumber(tx.rawTickerPrice).mul(cashInCommission).round(2)
|
||||
const date = new Date()
|
||||
date.setMinutes(date.getMinutes() + parseInt(dstOffset))
|
||||
const dateString = `${date.toISOString().replace('T', ' ').slice(0, 19)}`
|
||||
|
||||
const data = {
|
||||
operatorInfo: configManager.getOperatorInfo(config),
|
||||
location: deviceConfig.machineLocation,
|
||||
customerName: customer.name,
|
||||
customerPhone: customer.phone,
|
||||
session: tx.id,
|
||||
time: dateString,
|
||||
direction: tx.direction === 'cashIn' ? 'Cash-in' : 'Cash-out',
|
||||
fiat: `${tx.fiat.toString()} ${tx.fiatCode}`,
|
||||
crypto: `${toCryptoUnits(tx.cryptoAtoms, tx.cryptoCode)} ${tx.cryptoCode}`,
|
||||
rate: `1 ${tx.cryptoCode} = ${rate} ${tx.fiatCode}`,
|
||||
address: tx.toAddress,
|
||||
txId: tx.txHash
|
||||
}
|
||||
|
||||
return formatSmsReceipt(data, receiptOptions)
|
||||
})
|
||||
})
|
||||
return cryptoAtoms.shiftedBy(-unitScale)
|
||||
}
|
||||
|
||||
function formatSmsReceipt (data, options) {
|
||||
|
|
@ -132,4 +91,4 @@ function formatSmsReceipt (data, options) {
|
|||
return request
|
||||
}
|
||||
|
||||
module.exports = { sendMessage, formatSmsReceipt, getLookup, buildSms }
|
||||
module.exports = { sendMessage, formatSmsReceipt, getLookup, toCryptoUnits }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue