Skip to content

Commit

Permalink
Merge pull request #114 from SwedbankPay/hotfix/full-refund-fixes
Browse files Browse the repository at this point in the history
Fix order lines of full refund
  • Loading branch information
olegisk authored Jan 17, 2022
2 parents 4cad275 + edf9141 commit d6cb552
Showing 1 changed file with 40 additions and 2 deletions.
42 changes: 40 additions & 2 deletions includes/class-wc-gateway-swedbank-pay-checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -1485,7 +1485,45 @@ public function process_refund( $order_id, $amount = null, $reason = '' ) {

// Refund without specific items
if ( 0 === count( $lines ) ) {
$lines = $order->get_items( array( 'line_item', 'shipping', 'fee', 'coupon' ) );
$line_items = $order->get_items( array( 'line_item', 'shipping', 'fee', 'coupon' ) );
foreach ($line_items as $item_id => $item) {
switch ( $item->get_type() ) {
case 'line_item':
/** @var WC_Order_Item_Product $item */
// Use subtotal to get amount without discounts
$lines[$item_id] = array(
'qty' => $item->get_quantity(),
'refund_total' => $item->get_subtotal(),
'refund_tax' => array(
$item->get_subtotal_tax()
)
);

break;
case 'fee':
case 'shipping':
/** @var WC_Order_Item_Fee|WC_Order_Item_Shipping $item */
$lines[$item_id] = array(
'qty' => $item->get_quantity(),
'refund_total' => $item->get_total(),
'refund_tax' => array(
$item->get_total_tax()
)
);

break;
case 'coupon':
/** @var WC_Order_Item_Coupon $item */
$lines[$item_id] = array(
'qty' => $item->get_quantity(),
'refund_total' => -1 * $item->get_discount(),
'refund_tax' => array(
-1 * $item->get_discount_tax()
)
);
break;
}
}
}

// Refund with specific items
Expand Down Expand Up @@ -1556,7 +1594,7 @@ public function process_refund( $order_id, $amount = null, $reason = '' ) {
$image = wc_placeholder_img_src( 'full' );
}

if (null === parse_url( $image, PHP_URL_SCHEME ) &&
if ( null === parse_url( $image, PHP_URL_SCHEME ) &&
mb_substr( $image, 0, mb_strlen(WP_CONTENT_URL), 'UTF-8' ) === WP_CONTENT_URL
) {
$image = wp_guess_url() . $image;
Expand Down

0 comments on commit d6cb552

Please sign in to comment.