From 1491db304b0cd0fd218d31e67d52fdd9b8cd3fc8 Mon Sep 17 00:00:00 2001 From: marshal Date: Mon, 29 Jun 2026 15:04:01 +0300 Subject: [PATCH 1/2] payemnt --- .../modules/payment/payment-client.service.ts | 3 +- .../src/modules/payment/payment.service.ts | 54 +++++++++++-------- .../backoffice/src/constants/apiConfig.ts | 4 +- .../portal/src/constants/apiConfig.ts | 4 +- .../new-contract-form/step2-service-type.tsx | 2 +- 5 files changed, 40 insertions(+), 27 deletions(-) diff --git a/apps/edr-freight-api/src/modules/payment/payment-client.service.ts b/apps/edr-freight-api/src/modules/payment/payment-client.service.ts index bcfa643b6..68ed249a5 100644 --- a/apps/edr-freight-api/src/modules/payment/payment-client.service.ts +++ b/apps/edr-freight-api/src/modules/payment/payment-client.service.ts @@ -19,7 +19,8 @@ export class PaymentClientService { private readonly logger = new Logger(PaymentClientService.name); private readonly baseUrl = ( // process.env.PAYMENT_API_URL ?? - "https://paymentcallback.triaplc.com" + // "https://paymentcallback.triaplc.com" + "http://localhost:3003" ).replace(/\/$/, ""); private readonly serviceToken = process.env.SERVICE_AUTH_TOKEN ?? ""; diff --git a/apps/edr-freight-api/src/modules/payment/payment.service.ts b/apps/edr-freight-api/src/modules/payment/payment.service.ts index dbd635d86..247b6cf62 100644 --- a/apps/edr-freight-api/src/modules/payment/payment.service.ts +++ b/apps/edr-freight-api/src/modules/payment/payment.service.ts @@ -398,34 +398,46 @@ export class PaymentService { failureCode?: string; failureMessage?: string; }): Promise<{ processed: boolean; alreadyFinalized?: boolean; reason?: string }> { - if (event.eventType === "payment.succeeded") { - const intent = await this.paymentRepo.findOneBy({ refId: event.referenceId, type: "booking" }); - if (!intent) { - return { processed: false, reason: `No local intent for booking ${event.referenceId}` }; - } - const { alreadyFinalized } = await this.finalizePaymentSuccess({ - intentId: intent.id, + const { alreadyFinalized } = await this.finalizePaymentSuccess({ + intentId:event.intentId, bookingId: event.referenceId, providerTxnId: event.providerTxnId, paidAt: event.paidAt ? new Date(event.paidAt) : undefined, }); + // console.log(`Payment finalized for booking ${event.referenceId}, intent ${intent.id}, alreadyFinalized: ${alreadyFinalized}`); return { processed: true, alreadyFinalized }; - } + // console.log(`Received payment event: ${JSON.stringify(event)}`); + // if (event.eventType === "payment.succeeded") { + // console.log(`Received payment.succeeded event for booking ${event.referenceId}, intent ${event.intentId}`); + // const intent = await this.paymentRepo.findOneBy({ refId: event.referenceId, type: "booking" }); + // if (!intent) { + // return { processed: false, reason: `No local intent for booking ${event.referenceId}` }; + // } + // console.log(`Processing payment.succeeded event for booking ${event.referenceId}, intent ${intent.id}`); + // const { alreadyFinalized } = await this.finalizePaymentSuccess({ + // intentId: intent.id, + // bookingId: event.referenceId, + // providerTxnId: event.providerTxnId, + // paidAt: event.paidAt ? new Date(event.paidAt) : undefined, + // }); + // console.log(`Payment finalized for booking ${event.referenceId}, intent ${intent.id}, alreadyFinalized: ${alreadyFinalized}`); + // return { processed: true, alreadyFinalized }; + // } - if (event.eventType === "payment.failed") { - const intent = await this.paymentRepo.findOneBy({ refId: event.referenceId, type: "booking" }); - if (!intent) { - return { processed: false, reason: `No local intent for booking ${event.referenceId}` }; - } - await this.markPaymentFailed({ - intentId: intent.id, - failureCode: event.failureCode, - failureMessage: event.failureMessage, - }); - return { processed: true }; - } + // if (event.eventType === "payment.failed") { + // const intent = await this.paymentRepo.findOneBy({ refId: event.referenceId, type: "booking" }); + // if (!intent) { + // return { processed: false, reason: `No local intent for booking ${event.referenceId}` }; + // } + // await this.markPaymentFailed({ + // intentId: intent.id, + // failureCode: event.failureCode, + // failureMessage: event.failureMessage, + // }); + // return { processed: true }; + // } - return { processed: false, reason: `Unknown event type: ${event.eventType}` }; + // return { processed: false, reason: `Unknown event type: ${event.eventType}` }; } private toLocalStatus(status: ProviderPaymentStatus): PaymentEntity["status"] { diff --git a/apps/edr-freight-web/backoffice/src/constants/apiConfig.ts b/apps/edr-freight-web/backoffice/src/constants/apiConfig.ts index 1217b8762..7a7604cc7 100644 --- a/apps/edr-freight-web/backoffice/src/constants/apiConfig.ts +++ b/apps/edr-freight-web/backoffice/src/constants/apiConfig.ts @@ -1,6 +1,6 @@ -export const API_BASE_URL = 'https://edrfreightapi.triaplc.com'; +// export const API_BASE_URL = 'https://edrfreightapi.triaplc.com'; -// export const API_BASE_URL = 'http://localhost:3001'; +export const API_BASE_URL = 'http://localhost:3001'; /** * URL that streams an uploaded file through the API by its UUID. Routes the diff --git a/apps/edr-freight-web/portal/src/constants/apiConfig.ts b/apps/edr-freight-web/portal/src/constants/apiConfig.ts index 1b070d87d..a24cb4a6d 100644 --- a/apps/edr-freight-web/portal/src/constants/apiConfig.ts +++ b/apps/edr-freight-web/portal/src/constants/apiConfig.ts @@ -1,5 +1,5 @@ -export const API_BASE_URL = 'https://edrfreightapi.triaplc.com'; -// export const API_BASE_URL = 'http://localhost:3001'; +// export const API_BASE_URL = 'https://edrfreightapi.triaplc.com'; +export const API_BASE_URL = 'http://localhost:3001'; /** * URL that streams an uploaded file through the API by its UUID. Routes the diff --git a/apps/edr-freight-web/portal/src/pages/contracts/new-contract-form/step2-service-type.tsx b/apps/edr-freight-web/portal/src/pages/contracts/new-contract-form/step2-service-type.tsx index ff8b847b9..3d9bd4ec1 100644 --- a/apps/edr-freight-web/portal/src/pages/contracts/new-contract-form/step2-service-type.tsx +++ b/apps/edr-freight-web/portal/src/pages/contracts/new-contract-form/step2-service-type.tsx @@ -6,7 +6,7 @@ import { FileCheck2, FileText, Info, - PackageCheck, + // PackageCheck, ShieldCheck, TrainFront, Truck, From b688a765503fbb4d73189f41d1481348cc8e26cd Mon Sep 17 00:00:00 2001 From: marshal Date: Mon, 29 Jun 2026 15:05:50 +0300 Subject: [PATCH 2/2] payemnt --- .../src/modules/payment/payment.service.ts | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/apps/edr-freight-api/src/modules/payment/payment.service.ts b/apps/edr-freight-api/src/modules/payment/payment.service.ts index 247b6cf62..1d56cb1cf 100644 --- a/apps/edr-freight-api/src/modules/payment/payment.service.ts +++ b/apps/edr-freight-api/src/modules/payment/payment.service.ts @@ -289,20 +289,21 @@ export class PaymentService { providerTxnId?: string; paidAt?: Date; }): Promise<{ alreadyFinalized: boolean }> { - const intent = await this.paymentRepo.findOneBy({ id: input.intentId }); - if (!intent) throw new NotFoundException("PaymentIntent not found"); - if (intent.status === "success") return { alreadyFinalized: true }; + // const intent = await this.paymentRepo.findOneBy({ id: input.intentId }); + // if (!intent) throw new NotFoundException("PaymentIntent not found"); + // if (intent.status === "success") return { alreadyFinalized: true }; const paidAt = input.paidAt ?? new Date(); // Every booking is a real shipment now (contracts are a separate aggregate), // so payment always settles the booking to PAID and enters allocation. await this.datasource.transaction(async (mg) => { - await mg.update( - PaymentEntity, - { id: intent.id }, - { status: "success", paidAt, transactionId: input.providerTxnId ?? intent.transactionId }, - ); + // await mg.update( + // PaymentEntity, + // // { id: intent.id }, + // {id:input.intentId}, + // { status: "success", paidAt, transactionId: input.providerTxnId ?? intent.transactionId }, + // ); await mg.update( Booking, { id: input.bookingId },