From d0e95dd500d4fc9e23d6ccb9220b1fcbb68a8a82 Mon Sep 17 00:00:00 2001 From: Gautam Garg <65900807+knit-pay@users.noreply.github.com> Date: Tue, 9 Jun 2026 01:54:18 +0530 Subject: [PATCH 1/4] EUR currency was getting saved in all refunds for non EUR currencies. Prevent the default Money currency (EUR) from leaking into the refunded amount for non-EUR payments. --- src/Plugin.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Plugin.php b/src/Plugin.php index de9971e2..94bc1a2a 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -1148,6 +1148,9 @@ public static function create_refund( Refund $refund ) { $refunded_amount = $payment->get_refunded_amount(); + // Prevent the default Money currency (EUR) from leaking into the refunded amount for non-EUR payments. + $refunded_amount->set_currency( $payment->get_total_amount()->get_currency() ); + $refunded_amount = $refunded_amount->add( $refund->get_amount() ); $payment->set_refunded_amount( $refunded_amount ); From fcce1210d3e0c3510f8b978f3ee1e7af28923790 Mon Sep 17 00:00:00 2001 From: Gautam Garg <65900807+knit-pay@users.noreply.github.com> Date: Tue, 9 Jun 2026 16:15:22 +0530 Subject: [PATCH 2/4] Updated code as per Gemini recomendation --- src/Payments/Payment.php | 4 ++++ src/Plugin.php | 3 --- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Payments/Payment.php b/src/Payments/Payment.php index c83f3a8e..adb7ba6f 100644 --- a/src/Payments/Payment.php +++ b/src/Payments/Payment.php @@ -265,6 +265,10 @@ public function set_total_amount( Money $total_amount ) { * @return Money */ public function get_refunded_amount() { + if ( $this->refunded_amount->get_currency() !== $this->get_total_amount()->get_currency() ) { + $this->refunded_amount->set_currency( $this->get_total_amount()->get_currency() ); + } + return $this->refunded_amount; } diff --git a/src/Plugin.php b/src/Plugin.php index 94bc1a2a..de9971e2 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -1148,9 +1148,6 @@ public static function create_refund( Refund $refund ) { $refunded_amount = $payment->get_refunded_amount(); - // Prevent the default Money currency (EUR) from leaking into the refunded amount for non-EUR payments. - $refunded_amount->set_currency( $payment->get_total_amount()->get_currency() ); - $refunded_amount = $refunded_amount->add( $refund->get_amount() ); $payment->set_refunded_amount( $refunded_amount ); From 2b9c6200c76b475e70ed4bf81c856e14426b35b2 Mon Sep 17 00:00:00 2001 From: Gautam Garg <65900807+knit-pay@users.noreply.github.com> Date: Sat, 13 Jun 2026 17:44:38 +0530 Subject: [PATCH 3/4] Improved Logic to fix refund currency missmatch. --- src/Payments/Payment.php | 4 ---- src/Plugin.php | 3 +++ views/meta-box-payment-lines.php | 8 ++++++++ 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/Payments/Payment.php b/src/Payments/Payment.php index adb7ba6f..c83f3a8e 100644 --- a/src/Payments/Payment.php +++ b/src/Payments/Payment.php @@ -265,10 +265,6 @@ public function set_total_amount( Money $total_amount ) { * @return Money */ public function get_refunded_amount() { - if ( $this->refunded_amount->get_currency() !== $this->get_total_amount()->get_currency() ) { - $this->refunded_amount->set_currency( $this->get_total_amount()->get_currency() ); - } - return $this->refunded_amount; } diff --git a/src/Plugin.php b/src/Plugin.php index de9971e2..84aee295 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -1147,6 +1147,9 @@ public static function create_refund( Refund $refund ) { $payment->refunds[] = $refund; $refunded_amount = $payment->get_refunded_amount(); + if ( $refunded_amount->is_zero() && $refunded_amount->get_currency() !== $refund->get_amount()->get_currency() ){ + $refunded_amount->set_currency( $refund->get_amount()->get_currency() ); + } $refunded_amount = $refunded_amount->add( $refund->get_amount() ); diff --git a/views/meta-box-payment-lines.php b/views/meta-box-payment-lines.php index 86d22afd..123e9f47 100644 --- a/views/meta-box-payment-lines.php +++ b/views/meta-box-payment-lines.php @@ -203,12 +203,20 @@ function ( PaymentLine $line ) { $line_total = $refund_line->get_total_amount(); + if ( $refunded_amount->is_zero() && $refunded_amount->get_currency() !== $line_total->get_currency() ) { + $refunded_amount->set_currency( $line_total->get_currency() ); + } + $refunded_amount = $refunded_amount->add( $line_total ); if ( $line_total instanceof TaxedMoney ) { $tax_amount = $line_total->get_tax_amount(); if ( null !== $tax_amount ) { + if ( $refunded_tax->is_zero() && $refunded_tax->get_currency() !== $tax_amount->get_currency() ) { + $refunded_tax->set_currency( $tax_amount->get_currency() ); + } + $refunded_tax = $refunded_tax->add( $tax_amount ); } } From 8a4a7db8165d83162f6c074d17f00585a89a081c Mon Sep 17 00:00:00 2001 From: Gautam Garg <65900807+knit-pay@users.noreply.github.com> Date: Sat, 13 Jun 2026 17:49:08 +0530 Subject: [PATCH 4/4] PHPCS Fix --- src/Plugin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Plugin.php b/src/Plugin.php index 84aee295..6f951daa 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -1147,7 +1147,7 @@ public static function create_refund( Refund $refund ) { $payment->refunds[] = $refund; $refunded_amount = $payment->get_refunded_amount(); - if ( $refunded_amount->is_zero() && $refunded_amount->get_currency() !== $refund->get_amount()->get_currency() ){ + if ( $refunded_amount->is_zero() && $refunded_amount->get_currency() !== $refund->get_amount()->get_currency() ) { $refunded_amount->set_currency( $refund->get_amount()->get_currency() ); }