From a8eec1612254d76ebb9dbce7da106f60c616cae6 Mon Sep 17 00:00:00 2001 From: "Carlos R. L. Rodrigues" <37986729+carlos-r-l-rodrigues@users.noreply.github.com> Date: Tue, 26 Nov 2024 12:23:53 -0300 Subject: [PATCH] fix(core-flows): aggregate payment status (#10278) --- .../src/order/utils/__tests__/aggregate-status.spec.ts | 10 ++++++++++ .../core-flows/src/order/utils/aggregate-status.ts | 6 +++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/packages/core/core-flows/src/order/utils/__tests__/aggregate-status.spec.ts b/packages/core/core-flows/src/order/utils/__tests__/aggregate-status.spec.ts index e095a3016b..111675ac8b 100644 --- a/packages/core/core-flows/src/order/utils/__tests__/aggregate-status.spec.ts +++ b/packages/core/core-flows/src/order/utils/__tests__/aggregate-status.spec.ts @@ -100,6 +100,16 @@ describe("Aggregate Order Status", () => { } as any) ).toEqual("captured") + expect( + getLastPaymentStatus({ + payment_collections: [ + { status: "authorized", captured_amount: 0, amount: 0 }, + { status: "authorized", captured_amount: 12, amount: 12 }, + { status: "canceled" }, + ], + } as any) + ).toEqual("captured") + expect( getLastPaymentStatus({ payment_collections: [ diff --git a/packages/core/core-flows/src/order/utils/aggregate-status.ts b/packages/core/core-flows/src/order/utils/aggregate-status.ts index 1b3e7a9e64..3b5585dfa5 100644 --- a/packages/core/core-flows/src/order/utils/aggregate-status.ts +++ b/packages/core/core-flows/src/order/utils/aggregate-status.ts @@ -21,7 +21,11 @@ export const getLastPaymentStatus = (order: OrderDetailDTO) => { } for (const paymentCollection of order.payment_collections) { - if (MathBN.gt(paymentCollection.captured_amount ?? 0, 0)) { + if ( + MathBN.gt(paymentCollection.captured_amount ?? 0, 0) || + (isDefined(paymentCollection.amount) && + MathBN.eq(paymentCollection.amount, 0)) + ) { paymentStatus[PaymentStatus.CAPTURED] += MathBN.eq( paymentCollection.captured_amount as number, paymentCollection.amount