initiate-payment api modified for dynamic amount from UI
This commit is contained in:
parent
0e59a652b0
commit
45d57cee8d
@ -46,6 +46,27 @@ export class ORDERID_DTO {
|
||||
P_ORDERID: string;
|
||||
}
|
||||
|
||||
export class PRICE_DTO {
|
||||
@ApiProperty({ required: true })
|
||||
// @Max(999999999, {
|
||||
// message: 'Property P_PRICE must not exceed 999999999',
|
||||
// })
|
||||
@Min(0.1, { message: 'Property P_PRICE must be greater than zero' })
|
||||
// @IsInt({ message: 'Property P_PRICE allows only whole numbers' })
|
||||
@IsNumber({}, { message: 'Property P_PRICE must be a number' })
|
||||
@Transform(({ value }) => Number(value))
|
||||
@IsDefined({ message: 'Property P_PRICE is required' })
|
||||
P_PRICE: number;
|
||||
}
|
||||
|
||||
export class DESCRIPTION_DTO {
|
||||
@ApiProperty({ required: true })
|
||||
@IsString()
|
||||
@IsDefined({ message: 'Property P_DESCRIPTION is required' })
|
||||
P_DESCRIPTION: string;
|
||||
}
|
||||
|
||||
|
||||
export class HEADERID_DTO {
|
||||
@ApiProperty({ required: true })
|
||||
@Max(999999999, {
|
||||
|
||||
@ -3,8 +3,10 @@ import { IntersectionType, PartialType } from "@nestjs/swagger";
|
||||
import {
|
||||
APPLICATIONNAME_DTO, AUTHREP_DTO, AUTO_FLAG_DTO, CARNETNO_DTO, COMMERCIAL_SAMPLE_FLAG_DTO,
|
||||
COUNTRYTABLE_DTO, CUSTCOURIERNO_DTO, DELIVERYMETHOD_DTO, DELIVERYTYPE_DTO,
|
||||
DESCRIPTION_DTO,
|
||||
EXIBITIONS_FAIR_FLAG_DTO, EXTENSION_PERIOD_DTO, FORMOFSECURITY_DTO, GLTABLE_DTO, GLTABLE_ITEMNO_OPTIONAL_DTO, GOODS_COUNTRY_DTO, GOODS_PORT_DTO, HEADERID_DTO,
|
||||
HORSE_FLAG_DTO, INSPROTECTION_DTO, ITEMNO_DTO, LDIPROTECTION_DTO, ORDERID_DTO, ORDERTYPE_DTO, PAYMENTMETHOD_DTO,
|
||||
PRICE_DTO,
|
||||
PRINTGL_DTO,
|
||||
PROF_EQUIPMENT_FLAG_DTO, REASON_CODE_DTO, REFNO_DTO, SHIPADDRID_DTO, SHIPCONTACTID_DTO, SHIPNAME_DTO, SHIPTOTYPE_DTO, USSETS_DTO
|
||||
} from "./carnet-application-property.dto";
|
||||
@ -69,6 +71,7 @@ export class SaveExtensionApplicationDTO extends (IntersectionType(
|
||||
export class PrintCarnetDTO extends (IntersectionType(SPID_DTO, HEADERID_DTO, PRINTGL_DTO)) { }
|
||||
export class PrintGLDTO extends (IntersectionType(SPID_DTO, HEADERID_DTO)) { }
|
||||
export class CapturePaymentDTO extends (IntersectionType(ORDERID_DTO)) { }
|
||||
export class InitiatePaymentDTO extends (IntersectionType(PRICE_DTO, DESCRIPTION_DTO)){}
|
||||
|
||||
export class CreateApplicationDTO extends IntersectionType(
|
||||
SPID_DTO, CLIENTID_DTO, LOCATIONID_DTO, USERID_DTO, APPLICATIONNAME_DTO,
|
||||
|
||||
@ -8,7 +8,7 @@ import {
|
||||
AddGenerallistItemsDTO,
|
||||
CA_UpdateHolderDTO,
|
||||
CapturePaymentDTO,
|
||||
CarnetProcessingCenterDTO, CarnetProcessingCenterDTO2, CopyCarnetDTO, CreateApplicationDTO, DeleteGenerallistItemsDTO, EditGenerallistItemsDTO, GetCarnetControlCenterDTO, GetExtendedSectionDTO, PrintCarnetDTO, PrintGLDTO, SaveCarnetApplicationDTO, SaveExtensionApplicationDTO, TransmitApplicationtoProcessDTO,
|
||||
CarnetProcessingCenterDTO, CarnetProcessingCenterDTO2, CopyCarnetDTO, CreateApplicationDTO, DeleteGenerallistItemsDTO, EditGenerallistItemsDTO, GetCarnetControlCenterDTO, GetExtendedSectionDTO, InitiatePaymentDTO, PrintCarnetDTO, PrintGLDTO, SaveCarnetApplicationDTO, SaveExtensionApplicationDTO, TransmitApplicationtoProcessDTO,
|
||||
UpdateExpGoodsAuthRepDTO,
|
||||
UpdateShippingDetailsDTO
|
||||
} from 'src/dto/property.dto';
|
||||
@ -276,8 +276,8 @@ export class CarnetApplicationController {
|
||||
|
||||
@Post('InitiatePayment')
|
||||
@UseGuards()
|
||||
async InitiatePayment() {
|
||||
return this.carnetApplicationService.InitiatePayment();
|
||||
async InitiatePayment(@Body() body: InitiatePaymentDTO) {
|
||||
return this.carnetApplicationService.InitiatePayment(body);
|
||||
}
|
||||
|
||||
@Post('CompletePayment')
|
||||
|
||||
@ -21,7 +21,8 @@ import {
|
||||
GetExtendedSectionDTO,
|
||||
SaveExtensionApplicationDTO,
|
||||
CarnetProcessingCenterDTO2,
|
||||
CapturePaymentDTO
|
||||
CapturePaymentDTO,
|
||||
InitiatePaymentDTO
|
||||
} from 'src/dto/property.dto';
|
||||
import { OracleService } from '../oracle.service';
|
||||
import { BadRequestException } from 'src/exceptions/badRequest.exception';
|
||||
@ -1589,8 +1590,26 @@ export class CarnetApplicationService {
|
||||
|
||||
// [payment]
|
||||
|
||||
async formatAmount(amount) {
|
||||
if (typeof amount !== 'number' || isNaN(amount)) {
|
||||
throw new Error('Amount must be a valid number');
|
||||
}
|
||||
|
||||
if (amount < 0) {
|
||||
throw new BadRequestException('Amount must be non-negative');
|
||||
}
|
||||
|
||||
return amount.toFixed(2); // Always returns a string with 2 decimal places
|
||||
}
|
||||
|
||||
|
||||
|
||||
async InitiatePayment(body: InitiatePaymentDTO) {
|
||||
|
||||
const quantity = 1;
|
||||
|
||||
const formattedAmount = await this.formatAmount(body.P_PRICE * quantity);
|
||||
|
||||
async InitiatePayment() {
|
||||
try {
|
||||
const accessToken = await this.payPalService.generateAccessToken();
|
||||
|
||||
@ -1609,22 +1628,22 @@ export class CarnetApplicationService {
|
||||
{
|
||||
items: [
|
||||
{
|
||||
name: 'carnet',
|
||||
description: 'carnet',
|
||||
quantity: 1,
|
||||
name: 'Carnet',
|
||||
description: body.P_DESCRIPTION,
|
||||
quantity: quantity,
|
||||
unit_amount: {
|
||||
currency_code: 'USD',
|
||||
value: '100.00'
|
||||
value: formattedAmount
|
||||
}
|
||||
}
|
||||
],
|
||||
amount: {
|
||||
currency_code: 'USD',
|
||||
value: '100.00',
|
||||
value: formattedAmount,
|
||||
breakdown: {
|
||||
item_total: {
|
||||
currency_code: 'USD',
|
||||
value: '100.00'
|
||||
value: formattedAmount
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user