From 24bcb10d76e34e3ec11c59cbd9ddc0fc388f269f Mon Sep 17 00:00:00 2001 From: Abdalhamid Alhamad Date: Wed, 17 Dec 2025 12:51:20 +0300 Subject: [PATCH] feat: enhance KYC process with external customer ID validation - Added validation to ensure customer has a neoleapExternalCustomerId before card creation. - Updated KYC status update to include neoleapExternalCustomerId in the customer record. - Enhanced application info to include ExternalCorporateId for better integration with Neoleap. --- src/card/services/card.service.ts | 4 ++++ src/common/modules/neoleap/services/neoleap.service.ts | 4 +++- src/customer/services/customer.service.ts | 7 ++++--- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/card/services/card.service.ts b/src/card/services/card.service.ts index 92df9ab..5138824 100644 --- a/src/card/services/card.service.ts +++ b/src/card/services/card.service.ts @@ -34,6 +34,10 @@ export class CardService { throw new BadRequestException('CUSTOMER.KYC_NOT_APPROVED'); } + if (!customer.neoleapExternalCustomerId) { + throw new BadRequestException('CUSTOMER.KYC_NOT_COMPLETED'); + } + if (customer.cards.length > 0) { throw new BadRequestException('CUSTOMER.ALREADY_HAS_CARD'); } diff --git a/src/common/modules/neoleap/services/neoleap.service.ts b/src/common/modules/neoleap/services/neoleap.service.ts index bd881cc..463a72f 100644 --- a/src/common/modules/neoleap/services/neoleap.service.ts +++ b/src/common/modules/neoleap/services/neoleap.service.ts @@ -188,7 +188,9 @@ export class NeoLeapService { }, BillingCycle: 'C1', }, - ApplicationOtherInfo: {}, + ApplicationOtherInfo: { + ExternalCorporateId: customer.neoleapExternalCustomerId, + }, ApplicationCustomerDetails: { FirstName: customer.firstName, LastName: customer.lastName, diff --git a/src/customer/services/customer.service.ts b/src/customer/services/customer.service.ts index a7b8694..5fc67fb 100644 --- a/src/customer/services/customer.service.ts +++ b/src/customer/services/customer.service.ts @@ -163,14 +163,15 @@ export class CustomerService { completedAt: new Date(), }); - // Update customer KYC status + // Update customer KYC status and external customer ID const kycStatus = body.status === 'ONBOARDING_SUCCESS' ? KycStatus.APPROVED : KycStatus.REJECTED; - + await this.customerRepository.updateCustomer(customer.id, { kycStatus, + neoleapExternalCustomerId: body.entity.externalId, }); - this.logger.log(`KYC updated successfully for customer ${customer.id}, status: ${body.status}`); + this.logger.log(`KYC updated successfully for customer ${customer.id}, status: ${body.status}, externalId: ${body.entity.externalId}`); } // TO BE REMOVED: This function is for testing only and will be removed