feat: new compliance options

This commit is contained in:
Taranto 2020-09-14 23:25:35 +01:00 committed by Josh Harvey
parent ccf7eacfad
commit f2080c32e9
23 changed files with 161 additions and 121 deletions

View file

@ -62,7 +62,6 @@ function poll (req, res, next) {
const hasLightning = checkHasLightning(settings)
const triggers = configManager.getTriggers(settings.config)
const compatTriggers = complianceTriggers.getBackwardsCompatibleTriggers(triggers)
const operatorInfo = configManager.getOperatorInfo(settings.config)
const cashOutConfig = configManager.getCashOut(deviceId, settings.config)
@ -91,18 +90,6 @@ function poll (req, res, next) {
error: null,
locale,
version,
smsVerificationActive: !!compatTriggers.sms,
smsVerificationThreshold: compatTriggers.sms,
hardLimitVerificationActive: !!compatTriggers.block,
hardLimitVerificationThreshold: compatTriggers.block,
idCardDataVerificationActive: !!compatTriggers.idData,
idCardDataVerificationThreshold: compatTriggers.idData,
idCardPhotoVerificationActive: !!compatTriggers.idPhoto,
idCardPhotoVerificationThreshold: compatTriggers.idPhoto,
sanctionsVerificationActive: !!compatTriggers.sancations,
sanctionsVerificationThreshold: compatTriggers.sancations,
frontCameraVerificationActive: !!compatTriggers.facephoto,
frontCameraVerificationThreshold: compatTriggers.facephoto,
receiptPrintingActive: receipt.active === "on",
cassettes,
twoWayMode: cashOutConfig.active,
@ -111,7 +98,24 @@ function poll (req, res, next) {
restartServices,
hasLightning,
receipt,
operatorInfo
operatorInfo,
triggers
}
// BACKWARDS_COMPATIBILITY 7.5
// machines before 7.5 expect old compliance
if (!machineVersion || semver.lt(machineVersion, '7.5.0-beta.0')) {
const compatTriggers = complianceTriggers.getBackwardsCompatibleTriggers(triggers)
response.smsVerificationActive = !!compatTriggers.sms
response.smsVerificationThreshold = compatTriggers.sms
response.idCardDataVerificationActive = !!compatTriggers.idData
response.idCardDataVerificationThreshold = compatTriggers.idData
response.idCardPhotoVerificationActive = !!compatTriggers.idPhoto
response.idCardPhotoVerificationThreshold = compatTriggers.idPhoto
response.sanctionsVerificationActive = !!compatTriggers.sancations
response.sanctionsVerificationThreshold = compatTriggers.sancations
response.frontCameraVerificationActive = !!compatTriggers.facephoto
response.frontCameraVerificationThreshold = compatTriggers.facephoto
}
// BACKWARDS_COMPATIBILITY 7.4.9
@ -208,6 +212,7 @@ function verifyTx (req, res, next) {
function addOrUpdateCustomer (req) {
const customerData = req.body
const machineVersion = req.query.version
const triggers = configManager.getTriggers(req.settings.config)
const compatTriggers = complianceTriggers.getBackwardsCompatibleTriggers(triggers)
@ -218,11 +223,24 @@ function addOrUpdateCustomer (req) {
return customers.add(req.body)
})
.then(customer => {
// BACKWARDS_COMPATIBILITY 7.5
// machines before 7.5 expect customer with sanctions result
const isOlderMachineVersion = !machineVersion || semver.lt(machineVersion, '7.5.0-beta.0')
const shouldRunOfacCompat = !compatTriggers.sanctions && isOlderMachineVersion
if (!shouldRunOfacCompat) return customer
return compliance.validationPatch(req.deviceId, !!compatTriggers.sanctions, customer)
.then(patch => {
if (_.isEmpty(patch)) return customer
return customers.update(customer.id, patch)
})
}).then(customer => {
// TODO new-admin: only get customer history till max needed for triggers
return Tx.customerHistory(customer.id)
.then(result => {
customer.txHistory = result
return customer
})
})
}
@ -244,6 +262,7 @@ function getCustomerWithPhoneCode (req, res, next) {
function updateCustomer (req, res, next) {
const id = req.params.id
const machineVersion = req.query.version
const txId = req.query.txId
const patch = req.body
const triggers = configManager.getTriggers(req.settings.config)
@ -254,16 +273,57 @@ function updateCustomer (req, res, next) {
if (!customer) { throw httpError('Not Found', 404) }
const mergedCustomer = _.merge(customer, patch)
return compliance.validationPatch(req.deviceId, !!compatTriggers.sanctions, mergedCustomer)
// BACKWARDS_COMPATIBILITY 7.5
// machines before 7.5 expect customer with sanctions result
const isOlderMachineVersion = !machineVersion || semver.lt(machineVersion, '7.5.0-beta.0')
Promise.resolve({})
.then(emptyObj => {
if (!isOlderMachineVersion) return Promise.resolve(emptyObj)
return compliance.validationPatch(req.deviceId, !!compatTriggers.sanctions, mergedCustomer)
})
.then(_.merge(patch))
.then(newPatch => customers.updatePhotoCard(id, newPatch))
.then(newPatch => customers.updateFrontCamera(id, newPatch))
.then(newPatch => customers.update(id, newPatch, null, txId))
})
.then(customer => respond(req, res, { customer }))
.catch(next)
}
function triggerSanctions (req, res, next) {
const id = req.params.id
customers.getById(id)
.then(customer => {
if (!customer) { throw httpError('Not Found', 404) }
return compliance.validationPatch(req.deviceId, true, customer)
.then(patch => customers.update(id, patch))
})
.then(customer => respond(req, res, { customer }))
.catch(next)
}
function triggerBlock (req, res, next) {
const id = req.params.id
customers.update(id, { authorizedOverride: 'blocked' })
.then(customer => respond(req, res, { customer }))
.catch(next)
}
function triggerSuspend (req, res, next) {
const id = req.params.id
customers.update(id, { authorizedOverride: 'blocked' })
.then(customer => respond(req, res, { customer }))
.catch(next)
}
function getLastSeen (req, res, next) {
const deviceId = req.deviceId
const timestamp = Date.now()
@ -409,6 +469,9 @@ app.post('/verify_transaction', verifyTx)
app.post('/phone_code', getCustomerWithPhoneCode)
app.patch('/customer/:id', updateCustomer)
app.patch('/customer/:id/sanctions', triggerSanctions)
app.patch('/customer/:id/block', triggerBlock)
app.patch('/customer/:id/suspend', triggerSuspend)
app.post('/tx', postTx)
app.get('/tx/:id', getTx)