mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-09-07 14:15:44 +00:00
Merge branch 'freight_feature/contrat' of github.com:Tria-plc/edr-platform into freight_feature/contrat
This commit is contained in:
@@ -20,6 +20,7 @@ export class PaymentClientService {
|
|||||||
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 ?? "";
|
||||||
|
|
||||||
|
|||||||
@@ -163,6 +163,10 @@ export class PaymentService {
|
|||||||
failureUrl: 'https://edrfreight.triaplc.com/payment/failure',
|
failureUrl: 'https://edrfreight.triaplc.com/payment/failure',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
await this.datasource.getRepository(Booking).update(
|
||||||
|
{ id: dto.bookingId },
|
||||||
|
{ paymentStatus: "PAID", status: "PAID" },
|
||||||
|
);
|
||||||
const intent = await this.syncIntentProjection(booking.id, booking, snapshot);
|
const intent = await this.syncIntentProjection(booking.id, booking, snapshot);
|
||||||
|
|
||||||
if (snapshot.status === ProviderPaymentStatus.SUCCEEDED) {
|
if (snapshot.status === ProviderPaymentStatus.SUCCEEDED) {
|
||||||
@@ -289,20 +293,21 @@ export class PaymentService {
|
|||||||
providerTxnId?: string;
|
providerTxnId?: string;
|
||||||
paidAt?: Date;
|
paidAt?: Date;
|
||||||
}): Promise<{ alreadyFinalized: boolean }> {
|
}): Promise<{ alreadyFinalized: boolean }> {
|
||||||
const intent = await this.paymentRepo.findOneBy({ id: input.intentId });
|
// const intent = await this.paymentRepo.findOneBy({ id: input.intentId });
|
||||||
if (!intent) throw new NotFoundException("PaymentIntent not found");
|
// if (!intent) throw new NotFoundException("PaymentIntent not found");
|
||||||
if (intent.status === "success") return { alreadyFinalized: true };
|
// if (intent.status === "success") return { alreadyFinalized: true };
|
||||||
|
|
||||||
const paidAt = input.paidAt ?? new Date();
|
const paidAt = input.paidAt ?? new Date();
|
||||||
|
|
||||||
// Every booking is a real shipment now (contracts are a separate aggregate),
|
// Every booking is a real shipment now (contracts are a separate aggregate),
|
||||||
// so payment always settles the booking to PAID and enters allocation.
|
// so payment always settles the booking to PAID and enters allocation.
|
||||||
await this.datasource.transaction(async (mg) => {
|
await this.datasource.transaction(async (mg) => {
|
||||||
await mg.update(
|
// await mg.update(
|
||||||
PaymentEntity,
|
// PaymentEntity,
|
||||||
{ id: intent.id },
|
// // { id: intent.id },
|
||||||
{ status: "success", paidAt, transactionId: input.providerTxnId ?? intent.transactionId },
|
// {id:input.intentId},
|
||||||
);
|
// { status: "success", paidAt, transactionId: input.providerTxnId ?? intent.transactionId },
|
||||||
|
// );
|
||||||
await mg.update(
|
await mg.update(
|
||||||
Booking,
|
Booking,
|
||||||
{ id: input.bookingId },
|
{ id: input.bookingId },
|
||||||
@@ -398,34 +403,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"] {
|
||||||
|
|||||||
Reference in New Issue
Block a user