async function verifyCustomer(idImage: Buffer, selfie: Buffer) {
// 1. Scan the document
const doc = await client.document.scan({ image: idImage });
// 2. Check document quality
if (doc.confidence < 0.8) {
return { approved: false, reason: 'Low document quality' };
}
// Check expiration
const expiry = new Date(doc.expirationDate);
if (expiry < new Date()) {
return { approved: false, reason: 'Document expired' };
}
// 3. Compare faces
const match = await client.face.compare({
source: idImage,
target: selfie,
});
if (!match.isMatch) {
return { approved: false, reason: 'Face mismatch' };
}
// 4. Age check (optional)
const age = await client.face.estimateAge({ image: selfie });
if (age.estimatedAge < 18) {
return { approved: false, reason: 'Under 18' };
}
return {
approved: true,
name: doc.fullName,
documentNumber: doc.documentNumber,
faceConfidence: match.confidence,
};
}