mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2026-10-25 00:27:56 +00:00
feat: create card for children
This commit is contained in:
@@ -1,3 +1,11 @@
|
||||
function getRandomWithDigits(digits: number): string {
|
||||
const min = Math.pow(10, digits - 1); // e.g. 1000 for 4 digits
|
||||
const max = Math.pow(10, digits) - 1; // e.g. 9999 for 4 digits
|
||||
|
||||
const result = Math.floor(Math.random() * (max - min + 1)) + min;
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
export const CREATE_APPLICATION_MOCK = {
|
||||
ResponseHeader: {
|
||||
Version: '1.0.0',
|
||||
@@ -673,9 +681,9 @@ export const CREATE_APPLICATION_MOCK = {
|
||||
},
|
||||
AccountDetailsList: [
|
||||
{
|
||||
Id: 21017,
|
||||
Id: getRandomWithDigits(5),
|
||||
InstitutionCode: '1100',
|
||||
AccountNumber: '6899999999999999',
|
||||
AccountNumber: getRandomWithDigits(16),
|
||||
Currency: {
|
||||
CurrCode: '682',
|
||||
AlphaCode: 'SAR',
|
||||
@@ -704,10 +712,10 @@ export const CREATE_APPLICATION_MOCK = {
|
||||
{
|
||||
pvv: null,
|
||||
ResponseCardIdentifier: {
|
||||
Id: 28595,
|
||||
Id: getRandomWithDigits(5),
|
||||
Pan: 'DDDDDDDDDDDDDDDDDDD',
|
||||
MaskedPan: '999999_9999',
|
||||
VPan: '1100000000000000',
|
||||
VPan: getRandomWithDigits(16),
|
||||
Seqno: 0,
|
||||
},
|
||||
ExpiryDate: '2031-09-30',
|
||||
|
||||
@@ -48,7 +48,7 @@ export class NeoLeapService {
|
||||
this.useKycMock = [true, 'true'].includes(this.configService.get<boolean>('USE_KYC_MOCK', true));
|
||||
}
|
||||
|
||||
async initiateKyc(customerId: string, body: InitiateKycRequestDto) {
|
||||
initiateKyc(customerId: string, body: InitiateKycRequestDto) {
|
||||
const responseKey = 'InitiateKycResponseDetails';
|
||||
|
||||
if (this.useKycMock) {
|
||||
@@ -91,7 +91,7 @@ export class NeoLeapService {
|
||||
);
|
||||
}
|
||||
|
||||
async createApplication(customer: Customer) {
|
||||
createApplication(customer: Customer) {
|
||||
const responseKey = 'CreateNewApplicationResponseDetails';
|
||||
|
||||
if (!this.useGateway) {
|
||||
@@ -165,7 +165,82 @@ export class NeoLeapService {
|
||||
);
|
||||
}
|
||||
|
||||
async inquireApplication(externalApplicationNumber: string) {
|
||||
createChildCard(parent: Customer, child: Customer, cardPin: string) {
|
||||
const responseKey = 'CreateNewApplicationResponseDetails';
|
||||
|
||||
if (!this.useGateway) {
|
||||
return plainToInstance(CreateApplicationResponse, CREATE_APPLICATION_MOCK[responseKey], {
|
||||
excludeExtraneousValues: true,
|
||||
});
|
||||
}
|
||||
|
||||
const payload: ICreateApplicationRequest = {
|
||||
CreateNewApplicationRequestDetails: {
|
||||
ApplicationRequestDetails: {
|
||||
InstitutionCode: this.institutionCode,
|
||||
ExternalApplicationNumber: child.applicationNumber.toString(),
|
||||
ApplicationType: '01',
|
||||
Product: '1101',
|
||||
ApplicationDate: moment().format('YYYY-MM-DD'),
|
||||
BranchCode: '000',
|
||||
ApplicationSource: 'O',
|
||||
DeliveryMethod: 'V',
|
||||
},
|
||||
ApplicationProcessingDetails: {
|
||||
SuggestedLimit: 0,
|
||||
RequestedLimit: 0,
|
||||
AssignedLimit: 0,
|
||||
ProcessControl: 'STND',
|
||||
},
|
||||
ApplicationFinancialInformation: {
|
||||
Currency: {
|
||||
AlphaCode: 'SAR',
|
||||
},
|
||||
BillingCycle: 'C1',
|
||||
},
|
||||
ApplicationOtherInfo: {
|
||||
ParentAccountNumber: parent.cards[0].account.accountNumber,
|
||||
},
|
||||
ApplicationCustomerDetails: {
|
||||
FirstName: parent.firstName,
|
||||
LastName: parent.lastName,
|
||||
FullName: parent.fullName,
|
||||
DateOfBirth: moment(parent.dateOfBirth).format('YYYY-MM-DD'),
|
||||
EmbossName: child.fullName.toUpperCase(), // TODO Enter Emboss Name
|
||||
IdType: '01',
|
||||
IdNumber: parent.nationalId,
|
||||
IdExpiryDate: moment(parent.nationalIdExpiry).format('YYYY-MM-DD'),
|
||||
Title: parent.gender === Gender.MALE ? 'Mr' : 'Ms',
|
||||
Gender: parent.gender === Gender.MALE ? 'M' : 'F',
|
||||
LocalizedDateOfBirth: moment(parent.dateOfBirth).format('YYYY-MM-DD'),
|
||||
Nationality: CountriesNumericISO[parent.countryOfResidence],
|
||||
},
|
||||
ApplicationAddress: {
|
||||
City: parent.city,
|
||||
Country: CountriesNumericISO[parent.country],
|
||||
Region: parent.region,
|
||||
AddressLine1: `${parent.street} ${parent.building}`,
|
||||
AddressLine2: parent.neighborhood,
|
||||
AddressRole: 0,
|
||||
Email: child.user.email,
|
||||
Phone1: child.user.phoneNumber,
|
||||
CountryDetails: {
|
||||
DefaultCurrency: {},
|
||||
Description: [],
|
||||
},
|
||||
},
|
||||
},
|
||||
RequestHeader: this.prepareHeaders('CreateNewApplication'),
|
||||
};
|
||||
return this.sendRequestToNeoLeap<ICreateApplicationRequest, CreateApplicationResponse>(
|
||||
'application/CreateNewApplication',
|
||||
payload,
|
||||
responseKey,
|
||||
CreateApplicationResponse,
|
||||
);
|
||||
}
|
||||
|
||||
inquireApplication(externalApplicationNumber: string) {
|
||||
const responseKey = 'InquireApplicationResponseDetails';
|
||||
if (!this.useGateway) {
|
||||
return plainToInstance(InquireApplicationResponse, INQUIRE_APPLICATION_MOCK[responseKey], {
|
||||
@@ -197,7 +272,7 @@ export class NeoLeapService {
|
||||
);
|
||||
}
|
||||
|
||||
async updateCardControl(cardId: string, amount: number, count?: number) {
|
||||
updateCardControl(cardId: string, amount: number, count?: number) {
|
||||
const responseKey = 'UpdateCardControlResponseDetails';
|
||||
if (!this.useGateway) {
|
||||
return;
|
||||
@@ -226,7 +301,7 @@ export class NeoLeapService {
|
||||
);
|
||||
}
|
||||
|
||||
async getEmbossingInformation(card: Card) {
|
||||
getEmbossingInformation(card: Card) {
|
||||
const responseKey = 'GetEmbossingInformationResponseDetails';
|
||||
if (!this.useGateway) {
|
||||
return plainToInstance(CardEmbossingDetailsResponseDto, CARD_EMBOSSING_DETAILS_MOCK[responseKey], {
|
||||
|
||||
Reference in New Issue
Block a user