support sanctions compliance
This commit is contained in:
parent
80e851fb59
commit
d904c8391e
5 changed files with 108 additions and 25 deletions
|
|
@ -1,23 +1,64 @@
|
|||
const _ = require('lodash/fp')
|
||||
|
||||
const logger = require('./logger')
|
||||
const ofac = require('./ofac/index')
|
||||
|
||||
function matchOfac (customer) {
|
||||
const nameParts = _.flatMap(_.split(/\s+/), [customer.firstName, customer.lastName])
|
||||
const birthDate = customer.dateOfBirth
|
||||
|
||||
const result = ofac.match(nameParts, birthDate)
|
||||
console.log('DEBUG200: %s', result)
|
||||
|
||||
if (result > 0.8) throw new Error('Compliance error')
|
||||
}
|
||||
|
||||
function validateCustomer (config, customer) {
|
||||
if (config.sanctionsVerificationActive) {
|
||||
matchOfac(customer)
|
||||
// Probably because we haven't asked for ID yet
|
||||
if (!_.isPlainObject(customer.idCardData)) {
|
||||
return true
|
||||
}
|
||||
|
||||
return customer
|
||||
const nameParts = {
|
||||
firstName: customer.idCardData.firstName,
|
||||
lastName: customer.idCardData.lastName
|
||||
}
|
||||
|
||||
if (_.some(_.isNil, _.values(nameParts))) {
|
||||
logger.error(new Error(`Insufficient idCardData while matching OFAC for: ${customer.id}`))
|
||||
return true
|
||||
}
|
||||
|
||||
const birthDate = customer.idCardData.dateOfBirth
|
||||
|
||||
if (_.isNil(birthDate)) {
|
||||
logger.error(new Error(`No birth date while matching OFAC for: ${customer.id}`))
|
||||
return true
|
||||
}
|
||||
|
||||
const options = {
|
||||
threshold: 0.85,
|
||||
fullNameThreshold: 0.95,
|
||||
debug: false
|
||||
}
|
||||
|
||||
const results = ofac.match(nameParts, birthDate, options)
|
||||
console.log('DEBUG200: %j', results)
|
||||
|
||||
return !_.isEmpty(results)
|
||||
}
|
||||
|
||||
module.exports = {validateCustomer}
|
||||
function validateOfac (customer) {
|
||||
if (customer.sanctionsOverride === 'blocked') return false
|
||||
if (customer.sanctionsOverride === 'verified') return true
|
||||
|
||||
console.log('DEBUG400')
|
||||
return !matchOfac(customer)
|
||||
}
|
||||
|
||||
function validationPatch (config, customer) {
|
||||
return Promise.resolve()
|
||||
.then(() => {
|
||||
const ofacValidation = validateOfac(customer)
|
||||
|
||||
console.log('DEBUG401: %s, %j', ofacValidation, customer)
|
||||
|
||||
if (_.isNil(customer.sanctions) || customer.sanctions !== ofacValidation) {
|
||||
return {sanctions: ofacValidation}
|
||||
}
|
||||
|
||||
return {}
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = {validationPatch}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue