Skip to content

Commit

Permalink
fix: Order refund
Browse files Browse the repository at this point in the history
  • Loading branch information
brtkwr committed Nov 29, 2024
1 parent 52cb974 commit 2e4fc2f
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions class/WC_Twoinc.php
Original file line number Diff line number Diff line change
Expand Up @@ -1608,9 +1608,10 @@ public function process_refund($order_id, $amount = null, $reason = '')
sprintf(__('Order has already been fully refunded with %s.', 'twoinc-payment-gateway'), self::PRODUCT_NAME)
);
}

$order_refunds = $order->get_refunds();
// Need to loop instead of getting the last element because the last element is not always the latest refund
$order_refund = null;
// Need to loop instead of getting the last element because the last element is not always the latest refund
foreach ($order_refunds as $refund) {
if (!$refund->get_refunded_payment()) {
if (!$order_refund || $refund->get_date_created() > $order_refund->get_date_created()) {
Expand All @@ -1619,11 +1620,8 @@ public function process_refund($order_id, $amount = null, $reason = '')
}
}

if (!$order_refund || !$twoinc_order_id) {
return new WP_Error(
'invalid_twoinc_refund',
sprintf(__('Could not initiate refund with %s', 'twoinc-payment-gateway'), self::PRODUCT_NAME)
);
if (!$order_refund) {
return false;
}

$refund_amount = $order_refund->get_amount();
Expand All @@ -1641,7 +1639,7 @@ public function process_refund($order_id, $amount = null, $reason = '')
"/v1/order/{$twoinc_order_id}/refund",
WC_Twoinc_Helper::compose_twoinc_refund(
$order_refund,
-$amount,
$amount,
$order->get_currency()
),
'POST'
Expand Down

0 comments on commit 2e4fc2f

Please sign in to comment.