diff --git a/.gitignore b/.gitignore index 6732258..4cb3dae 100644 --- a/.gitignore +++ b/.gitignore @@ -53,3 +53,5 @@ pids # Diagnostic reports (https://nodejs.org/api/report.html) report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json + +zod-certs diff --git a/nest-cli.json b/nest-cli.json index 60e4148..87dfbbf 100644 --- a/nest-cli.json +++ b/nest-cli.json @@ -11,6 +11,7 @@ "exclude": "**/*.md" }, { "include": "common/modules/**/templates/**/*", "watchAssets": true }, + { "include": "common/modules/neoleap/zod-certs" }, "i18n", "files" ] diff --git a/src/common/modules/neoleap/controllers/neotest.controller.ts b/src/common/modules/neoleap/controllers/neotest.controller.ts index 5475442..b8a3250 100644 --- a/src/common/modules/neoleap/controllers/neotest.controller.ts +++ b/src/common/modules/neoleap/controllers/neotest.controller.ts @@ -11,7 +11,7 @@ export class NeoTestController { @Get('inquire-application') async inquireApplication() { - return this.neoleapService.inquireApplication('1234567890'); + return this.neoleapService.inquireApplication('1'); } @Get('create-application') diff --git a/src/common/modules/neoleap/services/neoleap.service.ts b/src/common/modules/neoleap/services/neoleap.service.ts index 0a68b68..fd9fbce 100644 --- a/src/common/modules/neoleap/services/neoleap.service.ts +++ b/src/common/modules/neoleap/services/neoleap.service.ts @@ -2,7 +2,10 @@ import { HttpService } from '@nestjs/axios'; import { BadRequestException, Injectable, InternalServerErrorException } from '@nestjs/common'; import { ConfigService } from '@nestjs/config'; import { ClassConstructor, plainToInstance } from 'class-transformer'; +import { readFileSync } from 'fs'; +import { Agent } from 'https'; import moment from 'moment'; +import path from 'path'; import { v4 as uuid } from 'uuid'; import { CountriesNumericISO } from '~/common/constants'; import { Customer } from '~/customer/entities'; @@ -16,10 +19,12 @@ export class NeoLeapService { private readonly apiKey: string; private readonly useMock: boolean; private readonly institutionCode = '1100'; + useLocalCert: boolean; constructor(private readonly httpService: HttpService, private readonly configService: ConfigService) { this.baseUrl = this.configService.getOrThrow('NEOLEAP_BASE_URL'); this.apiKey = this.configService.getOrThrow('NEOLEAP_API_KEY'); this.useMock = [true, 'true'].includes(this.configService.get('USE_MOCK', false)); + this.useLocalCert = this.configService.get('USE_LOCAL_CERT', false); } async createApplication(customer: Customer) { @@ -148,7 +153,16 @@ export class NeoLeapService { headers: { 'Content-Type': 'application/json', Authorization: `${this.apiKey}`, + Host: 'apigw-uat.neoleap.com.sa', }, + httpsAgent: new Agent({ + rejectUnauthorized: false, // Disable SSL verification for development purposes + ca: this.useLocalCert ? readFileSync(path.join(__dirname, '../zod-certs/My_CA_Bundle.ca-bundle')) : undefined, + cert: this.useLocalCert + ? readFileSync(path.join(__dirname, '../zod-certs/gw-dev_zodwallet_com.crt')) + : undefined, + key: this.useLocalCert ? readFileSync(path.join(__dirname, '../zod-certs/server.key')) : undefined, + }), }); if (response.data?.ResponseHeader.ResponseCode !== '000' || !response.data[responseKey]) {