From f6736d96616aaff51399b2733905f9e340efc8be Mon Sep 17 00:00:00 2001 From: "Carlos R. L. Rodrigues" <37986729+carlos-r-l-rodrigues@users.noreply.github.com> Date: Thu, 31 Jul 2025 09:06:20 -0300 Subject: [PATCH] fix(core-flows): refresh payment collection (#13103) --- .changeset/light-gorillas-play.md | 5 +++++ .../src/cart/workflows/refresh-payment-collection.ts | 2 +- packages/core/core-flows/src/order/utils/aggregate-status.ts | 4 ++-- 3 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 .changeset/light-gorillas-play.md diff --git a/.changeset/light-gorillas-play.md b/.changeset/light-gorillas-play.md new file mode 100644 index 0000000000..b7f7c19cc0 --- /dev/null +++ b/.changeset/light-gorillas-play.md @@ -0,0 +1,5 @@ +--- +"@medusajs/core-flows": patch +--- + +fix(core-flows): refresh payment collection using raw total diff --git a/packages/core/core-flows/src/cart/workflows/refresh-payment-collection.ts b/packages/core/core-flows/src/cart/workflows/refresh-payment-collection.ts index 6eb15c0295..e3c0d82c56 100644 --- a/packages/core/core-flows/src/cart/workflows/refresh-payment-collection.ts +++ b/packages/core/core-flows/src/cart/workflows/refresh-payment-collection.ts @@ -120,7 +120,7 @@ export const refreshPaymentCollectionForCartWorkflow = createWorkflow( return { selector: { id: cart.payment_collection.id }, update: { - amount: cart.total, + amount: cart.raw_total, currency_code: cart.currency_code, }, } 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 94abf727ae..d9afd14be0 100644 --- a/packages/core/core-flows/src/order/utils/aggregate-status.ts +++ b/packages/core/core-flows/src/order/utils/aggregate-status.ts @@ -26,7 +26,7 @@ export const getLastPaymentStatus = (order: OrderDetailDTO) => { (isDefined(paymentCollection.amount) && MathBN.eq(paymentCollection.amount, 0)) ) { - paymentStatus[PaymentStatus.CAPTURED] += MathBN.eq( + paymentStatus[PaymentStatus.CAPTURED] += MathBN.gte( paymentCollection.captured_amount as number, paymentCollection.amount ) @@ -35,7 +35,7 @@ export const getLastPaymentStatus = (order: OrderDetailDTO) => { } if (MathBN.gt(paymentCollection.refunded_amount ?? 0, 0)) { - paymentStatus[PaymentStatus.REFUNDED] += MathBN.eq( + paymentStatus[PaymentStatus.REFUNDED] += MathBN.gte( paymentCollection.refunded_amount as number, paymentCollection.amount )