mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2026-10-25 01:47:55 +00:00
feat: working on creating parent card
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
export const CARD_EMBOSSING_DETAILS_MOCK = {
|
||||
ResponseHeader: {
|
||||
Version: '1.0.0',
|
||||
MsgUid: 'adaa1893-9f95-48a8-b7a1-0422bcf629b5',
|
||||
Source: 'ZOD',
|
||||
ServiceId: 'GetEmbossingInformation',
|
||||
ReqDateTime: '2025-06-11T07:32:16.304Z',
|
||||
RspDateTime: '2025-08-14T10:01:14.205',
|
||||
ResponseCode: '000',
|
||||
ResponseType: 'Success',
|
||||
ProcessingTime: 67,
|
||||
EncryptionKey: null,
|
||||
ResponseDescription: 'Operation Successful',
|
||||
LocalizedResponseDescription: null,
|
||||
CustomerSpecificResponseDescriptionList: null,
|
||||
HeaderUserDataList: null,
|
||||
},
|
||||
GetEmbossingInformationResponseDetails: {
|
||||
icvv: '259',
|
||||
Track1: '%B4017786818471184^AMMAR/QAFFAF^31102261029800997000000?',
|
||||
Track2: ';4017786818471184=31102261029899700?',
|
||||
Track3: null,
|
||||
EmvTrack1: '1029800259000000',
|
||||
EmvTrack2: '4017786818471184D31102261029825900',
|
||||
ClearPan: '4017786818471184',
|
||||
PinBlock: '663B1A71D8112D97',
|
||||
Cvv: '997',
|
||||
Cvv2: '834',
|
||||
iCvv: '259',
|
||||
Pvv: '0298',
|
||||
EmbossingName: 'AMMAR QAFFAF',
|
||||
ExpiryDate: '20311031',
|
||||
OldPlasticExpiryDate: null,
|
||||
CardStatus: '30',
|
||||
OldPlasticCardStatus: ' ',
|
||||
EmbossingRecord: null,
|
||||
},
|
||||
};
|
||||
@@ -1,3 +1,4 @@
|
||||
export * from './card-embossing-details.mock';
|
||||
export * from './create-application.mock';
|
||||
export * from './initiate-kyc.mock';
|
||||
export * from './inquire-application.mock';
|
||||
|
||||
@@ -19,5 +19,11 @@ export const getKycCallbackMock = (nationalId: string) => {
|
||||
professionTitle: 'Software Engineer',
|
||||
professionType: 'Full-Time',
|
||||
isPep: 'N',
|
||||
country: '682',
|
||||
region: 'Mecca',
|
||||
city: 'At-Taif',
|
||||
neighborhood: 'Al-Hamra',
|
||||
street: 'Al-Masjid Al-Haram',
|
||||
building: '123',
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
import { Body, Controller, Post } from '@nestjs/common';
|
||||
import { ApiTags } from '@nestjs/swagger';
|
||||
import { ResponseFactory } from '~/core/utils';
|
||||
import {
|
||||
AccountCardStatusChangedWebhookRequest,
|
||||
AccountTransactionWebhookRequest,
|
||||
CardTransactionWebhookRequest,
|
||||
KycWebhookRequest,
|
||||
} from '../dtos/requests';
|
||||
import { NeoLeapWebhookService } from '../services';
|
||||
|
||||
@Controller('neoleap-webhooks')
|
||||
@ApiTags('Neoleap Webhooks')
|
||||
export class NeoLeapWebhooksController {
|
||||
constructor(private readonly neoleapWebhookService: NeoLeapWebhookService) {}
|
||||
|
||||
@Post('card-transaction')
|
||||
async handleCardTransactionWebhook(@Body() body: CardTransactionWebhookRequest) {
|
||||
await this.neoleapWebhookService.handleCardTransactionWebhook(body);
|
||||
return ResponseFactory.data({ message: 'Card transaction processed successfully', status: 'success' });
|
||||
}
|
||||
|
||||
@Post('account-transaction')
|
||||
async handleAccountTransactionWebhook(@Body() body: AccountTransactionWebhookRequest) {
|
||||
await this.neoleapWebhookService.handleAccountTransactionWebhook(body);
|
||||
return ResponseFactory.data({ message: 'Account transaction processed successfully', status: 'success' });
|
||||
}
|
||||
|
||||
@Post('account-card-status-changed')
|
||||
async handleAccountCardStatusChangedWebhook(@Body() body: AccountCardStatusChangedWebhookRequest) {
|
||||
await this.neoleapWebhookService.handleAccountCardStatusChangedWebhook(body);
|
||||
return ResponseFactory.data({ message: 'Card status updated successfully', status: 'success' });
|
||||
}
|
||||
|
||||
@Post('kyc')
|
||||
async handleKycWebhook(@Body() body: KycWebhookRequest) {
|
||||
await this.neoleapWebhookService.handleKycWebhook(body);
|
||||
return ResponseFactory.data({ message: 'KYC processed successfully', status: 'success' });
|
||||
}
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
import { Body, Controller, Post, UseGuards } from '@nestjs/common';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
||||
import { IJwtPayload } from '~/auth/interfaces';
|
||||
import { CardService } from '~/card/services';
|
||||
import { AuthenticatedUser } from '~/common/decorators';
|
||||
import { AccessTokenGuard } from '~/common/guards';
|
||||
import { ApiDataResponse } from '~/core/decorators';
|
||||
import { ResponseFactory } from '~/core/utils';
|
||||
import { CustomerResponseDto } from '~/customer/dtos/response';
|
||||
import { CustomerService } from '~/customer/services';
|
||||
import { UpdateCardControlsRequestDto } from '../dtos/requests';
|
||||
import { CreateApplicationResponse, InquireApplicationResponse } from '../dtos/response';
|
||||
import { NeoLeapService } from '../services/neoleap.service';
|
||||
|
||||
@Controller('neotest')
|
||||
@ApiTags('Neoleap Test API , for testing purposes only, will be removed in production')
|
||||
@UseGuards(AccessTokenGuard)
|
||||
@ApiBearerAuth()
|
||||
export class NeoTestController {
|
||||
constructor(
|
||||
private readonly neoleapService: NeoLeapService,
|
||||
private readonly customerService: CustomerService,
|
||||
private readonly cardService: CardService,
|
||||
private readonly configService: ConfigService,
|
||||
) {}
|
||||
|
||||
@Post('update-kys')
|
||||
@ApiDataResponse(CustomerResponseDto)
|
||||
async updateKys(@AuthenticatedUser() user: IJwtPayload) {
|
||||
const customer = await this.customerService.updateKyc(user.sub);
|
||||
|
||||
return ResponseFactory.data(new CustomerResponseDto(customer));
|
||||
}
|
||||
|
||||
@Post('inquire-application')
|
||||
@ApiDataResponse(InquireApplicationResponse)
|
||||
async inquireApplication(@AuthenticatedUser() user: IJwtPayload) {
|
||||
const customer = await this.customerService.findCustomerById(user.sub);
|
||||
const data = await this.neoleapService.inquireApplication(customer.applicationNumber.toString());
|
||||
return ResponseFactory.data(data);
|
||||
}
|
||||
|
||||
@Post('create-application')
|
||||
@ApiDataResponse(CreateApplicationResponse)
|
||||
async createApplication(@AuthenticatedUser() user: IJwtPayload) {
|
||||
const customer = await this.customerService.findCustomerById(user.sub);
|
||||
const data = await this.neoleapService.createApplication(customer);
|
||||
await this.cardService.createCard(customer.id, data);
|
||||
return ResponseFactory.data(data);
|
||||
}
|
||||
|
||||
@Post('update-card-controls')
|
||||
async updateCardControls(
|
||||
@AuthenticatedUser() user: IJwtPayload,
|
||||
@Body() { amount, count }: UpdateCardControlsRequestDto,
|
||||
) {
|
||||
const card = await this.cardService.getActiveCardForCustomer(user.sub);
|
||||
await this.neoleapService.updateCardControl(card.cardReference, amount, count);
|
||||
return ResponseFactory.data({ message: 'Card controls updated successfully' });
|
||||
}
|
||||
}
|
||||
@@ -96,4 +96,34 @@ export class KycWebhookRequest {
|
||||
@IsString()
|
||||
@ApiProperty({ example: 'N' })
|
||||
isPep!: string;
|
||||
|
||||
@Expose()
|
||||
@IsString()
|
||||
@ApiProperty({ example: '682' })
|
||||
country!: string;
|
||||
|
||||
@Expose()
|
||||
@IsString()
|
||||
@ApiProperty({ example: 'Mecca' })
|
||||
region!: string;
|
||||
|
||||
@Expose()
|
||||
@IsString()
|
||||
@ApiProperty({ example: 'At-Taif' })
|
||||
city!: string;
|
||||
|
||||
@Expose()
|
||||
@IsString()
|
||||
@ApiProperty({ example: 'Al-Hamra' })
|
||||
neighborhood!: string;
|
||||
|
||||
@Expose()
|
||||
@IsString()
|
||||
@ApiProperty({ example: 'Al-Masjid Al-Haram' })
|
||||
street!: string;
|
||||
|
||||
@Expose()
|
||||
@IsString()
|
||||
@ApiProperty({ example: '123' })
|
||||
building!: string;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { Expose } from 'class-transformer';
|
||||
|
||||
export class CardEmbossingDetailsResponseDto {
|
||||
@ApiProperty({
|
||||
example: '997',
|
||||
})
|
||||
@Expose({ name: 'Cvv' })
|
||||
cvv!: string;
|
||||
|
||||
@ApiProperty({ example: '4017786818471184' })
|
||||
@Expose({ name: 'ClearPan' })
|
||||
cardNumber!: string;
|
||||
|
||||
@ApiProperty({
|
||||
example: '20311031',
|
||||
})
|
||||
@Expose({ name: 'ExpiryDate' })
|
||||
expiryDate!: string;
|
||||
|
||||
@ApiProperty({
|
||||
example: 'AMMAR QAFFAF',
|
||||
})
|
||||
@Expose({ name: 'EmbossingName' })
|
||||
cardHolderName!: string;
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
export * from './card-embossing-details.response.dto';
|
||||
export * from './create-application.response.dto';
|
||||
export * from './initiate-kyc.response.dto';
|
||||
export * from './inquire-application.response';
|
||||
|
||||
@@ -1,16 +1,11 @@
|
||||
import { HttpModule } from '@nestjs/axios';
|
||||
import { forwardRef, Module } from '@nestjs/common';
|
||||
import { CardModule } from '~/card/card.module';
|
||||
import { CustomerModule } from '~/customer/customer.module';
|
||||
import { NeoLeapWebhooksController } from './controllers/neoleap-webhooks.controller';
|
||||
import { NeoTestController } from './controllers/neotest.controller';
|
||||
import { NeoLeapWebhookService } from './services';
|
||||
import { Module } from '@nestjs/common';
|
||||
import { NeoLeapService } from './services/neoleap.service';
|
||||
|
||||
@Module({
|
||||
imports: [HttpModule, CardModule, forwardRef(() => CustomerModule)],
|
||||
controllers: [NeoTestController, NeoLeapWebhooksController],
|
||||
providers: [NeoLeapService, NeoLeapWebhookService],
|
||||
imports: [HttpModule],
|
||||
controllers: [],
|
||||
providers: [NeoLeapService],
|
||||
exports: [NeoLeapService],
|
||||
})
|
||||
export class NeoLeapModule {}
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
export * from './neoleap-webook.service';
|
||||
export * from '../../../../webhook/services/neoleap-webook.service';
|
||||
export * from './neoleap.service';
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { CardService } from '~/card/services';
|
||||
import { TransactionService } from '~/card/services/transaction.service';
|
||||
import { CustomerService } from '~/customer/services';
|
||||
import {
|
||||
AccountCardStatusChangedWebhookRequest,
|
||||
AccountTransactionWebhookRequest,
|
||||
CardTransactionWebhookRequest,
|
||||
KycWebhookRequest,
|
||||
} from '../dtos/requests';
|
||||
|
||||
@Injectable()
|
||||
export class NeoLeapWebhookService {
|
||||
constructor(
|
||||
private readonly transactionService: TransactionService,
|
||||
private readonly cardService: CardService,
|
||||
private customerService: CustomerService,
|
||||
) {}
|
||||
|
||||
handleCardTransactionWebhook(body: CardTransactionWebhookRequest) {
|
||||
return this.transactionService.createCardTransaction(body);
|
||||
}
|
||||
|
||||
handleAccountTransactionWebhook(body: AccountTransactionWebhookRequest) {
|
||||
return this.transactionService.createAccountTransaction(body);
|
||||
}
|
||||
|
||||
handleAccountCardStatusChangedWebhook(body: AccountCardStatusChangedWebhookRequest) {
|
||||
return this.cardService.updateCardStatus(body);
|
||||
}
|
||||
|
||||
handleKycWebhook(body: KycWebhookRequest) {
|
||||
return this.customerService.updateCustomerKyc(body);
|
||||
}
|
||||
}
|
||||
@@ -4,13 +4,20 @@ import { ConfigService } from '@nestjs/config';
|
||||
import { ClassConstructor, plainToInstance } from 'class-transformer';
|
||||
import moment from 'moment';
|
||||
import { v4 as uuid } from 'uuid';
|
||||
import { Card } from '~/card/entities';
|
||||
import { CountriesNumericISO } from '~/common/constants';
|
||||
import { InitiateKycRequestDto } from '~/customer/dtos/request';
|
||||
import { Customer } from '~/customer/entities';
|
||||
import { Gender, KycStatus } from '~/customer/enums';
|
||||
import { CREATE_APPLICATION_MOCK, INITIATE_KYC_MOCK, INQUIRE_APPLICATION_MOCK } from '../__mocks__/';
|
||||
import { Gender } from '~/customer/enums';
|
||||
import {
|
||||
CARD_EMBOSSING_DETAILS_MOCK,
|
||||
CREATE_APPLICATION_MOCK,
|
||||
INITIATE_KYC_MOCK,
|
||||
INQUIRE_APPLICATION_MOCK,
|
||||
} from '../__mocks__/';
|
||||
import { getKycCallbackMock } from '../__mocks__/kyc-callback.mock';
|
||||
import {
|
||||
CardEmbossingDetailsResponseDto,
|
||||
CreateApplicationResponse,
|
||||
InitiateKycResponseDto,
|
||||
InquireApplicationResponse,
|
||||
@@ -85,14 +92,6 @@ export class NeoLeapService {
|
||||
async createApplication(customer: Customer) {
|
||||
const responseKey = 'CreateNewApplicationResponseDetails';
|
||||
|
||||
if (customer.kycStatus !== KycStatus.APPROVED) {
|
||||
throw new BadRequestException('CUSTOMER.KYC_NOT_APPROVED');
|
||||
}
|
||||
|
||||
if (customer.cards.length > 0) {
|
||||
throw new BadRequestException('CUSTOMER.ALREADY_HAS_CARD');
|
||||
}
|
||||
|
||||
if (!this.useGateway) {
|
||||
return plainToInstance(CreateApplicationResponse, CREATE_APPLICATION_MOCK[responseKey], {
|
||||
excludeExtraneousValues: true,
|
||||
@@ -225,6 +224,33 @@ export class NeoLeapService {
|
||||
);
|
||||
}
|
||||
|
||||
async getEmbossingInformation(card: Card) {
|
||||
const responseKey = 'GetEmbossingInformationResponseDetails';
|
||||
if (!this.useGateway) {
|
||||
return plainToInstance(CardEmbossingDetailsResponseDto, CARD_EMBOSSING_DETAILS_MOCK[responseKey], {
|
||||
excludeExtraneousValues: true,
|
||||
});
|
||||
}
|
||||
|
||||
const payload = {
|
||||
GetEmbossingInformationRequestDetails: {
|
||||
InstitutionCode: this.institutionCode,
|
||||
CardIdentifier: {
|
||||
InstitutionCode: this.institutionCode,
|
||||
Id: card.cardReference,
|
||||
},
|
||||
},
|
||||
RequestHeader: this.prepareHeaders('GetEmbossingInformation'),
|
||||
};
|
||||
|
||||
return this.sendRequestToNeoLeap<typeof payload, CardEmbossingDetailsResponseDto>(
|
||||
'cardembossing/CardEmbossingDetails',
|
||||
payload,
|
||||
responseKey,
|
||||
CardEmbossingDetailsResponseDto,
|
||||
);
|
||||
}
|
||||
|
||||
private prepareHeaders(serviceName: string): INeoleapHeaderRequest['RequestHeader'] {
|
||||
return {
|
||||
Version: '1.0.0',
|
||||
|
||||
Reference in New Issue
Block a user