This commit is contained in:
marshal
2026-06-29 15:04:01 +03:00
parent 9fe90c8ef7
commit 1491db304b
5 changed files with 40 additions and 27 deletions

View File

@@ -19,7 +19,8 @@ export class PaymentClientService {
private readonly logger = new Logger(PaymentClientService.name); private readonly logger = new Logger(PaymentClientService.name);
private readonly baseUrl = ( private readonly baseUrl = (
// process.env.PAYMENT_API_URL ?? // process.env.PAYMENT_API_URL ??
"https://paymentcallback.triaplc.com" // "https://paymentcallback.triaplc.com"
"http://localhost:3003"
).replace(/\/$/, ""); ).replace(/\/$/, "");
private readonly serviceToken = process.env.SERVICE_AUTH_TOKEN ?? ""; private readonly serviceToken = process.env.SERVICE_AUTH_TOKEN ?? "";

View File

@@ -398,34 +398,46 @@ export class PaymentService {
failureCode?: string; failureCode?: string;
failureMessage?: string; failureMessage?: string;
}): Promise<{ processed: boolean; alreadyFinalized?: boolean; reason?: string }> { }): Promise<{ processed: boolean; alreadyFinalized?: boolean; reason?: string }> {
if (event.eventType === "payment.succeeded") { const { alreadyFinalized } = await this.finalizePaymentSuccess({
const intent = await this.paymentRepo.findOneBy({ refId: event.referenceId, type: "booking" }); intentId:event.intentId,
if (!intent) {
return { processed: false, reason: `No local intent for booking ${event.referenceId}` };
}
const { alreadyFinalized } = await this.finalizePaymentSuccess({
intentId: intent.id,
bookingId: event.referenceId, bookingId: event.referenceId,
providerTxnId: event.providerTxnId, providerTxnId: event.providerTxnId,
paidAt: event.paidAt ? new Date(event.paidAt) : undefined, 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 }; 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") { // if (event.eventType === "payment.failed") {
const intent = await this.paymentRepo.findOneBy({ refId: event.referenceId, type: "booking" }); // const intent = await this.paymentRepo.findOneBy({ refId: event.referenceId, type: "booking" });
if (!intent) { // if (!intent) {
return { processed: false, reason: `No local intent for booking ${event.referenceId}` }; // return { processed: false, reason: `No local intent for booking ${event.referenceId}` };
} // }
await this.markPaymentFailed({ // await this.markPaymentFailed({
intentId: intent.id, // intentId: intent.id,
failureCode: event.failureCode, // failureCode: event.failureCode,
failureMessage: event.failureMessage, // failureMessage: event.failureMessage,
}); // });
return { processed: true }; // 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"] { private toLocalStatus(status: ProviderPaymentStatus): PaymentEntity["status"] {

View File

@@ -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 * URL that streams an uploaded file through the API by its UUID. Routes the

View File

@@ -1,5 +1,5 @@
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 * URL that streams an uploaded file through the API by its UUID. Routes the

View File

@@ -6,7 +6,7 @@ import {
FileCheck2, FileCheck2,
FileText, FileText,
Info, Info,
PackageCheck, // PackageCheck,
ShieldCheck, ShieldCheck,
TrainFront, TrainFront,
Truck, Truck,