From 7cb474ff3b9b2a87d4a6ba91e438ba9f4062113a Mon Sep 17 00:00:00 2001 From: Pond Date: Fri, 9 Aug 2024 16:54:31 +0700 Subject: [PATCH 01/10] Fix json encode send some value is wrong and Fix order amount of order items send wring to API with calculate vat --- includes/Gateways/ReepayGateway.php | 7 ++++--- includes/OrderFlow/OrderCapture.php | 3 +-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/includes/Gateways/ReepayGateway.php b/includes/Gateways/ReepayGateway.php index 318c0afa..9edce464 100644 --- a/includes/Gateways/ReepayGateway.php +++ b/includes/Gateways/ReepayGateway.php @@ -1058,7 +1058,6 @@ public function process_payment( $order_id ) { // If here's Subscription or zero payment. if ( ( $have_sub ) && ( abs( $order->get_total() ) < 0.01 || empty( $only_items_lines ) ) ) { - $result = reepay()->api( $this )->recurring( $this->payment_methods, $order, $data, false, $params['button_text'] ); if ( is_wp_error( $result ) ) { @@ -1429,7 +1428,7 @@ public function get_order_items( WC_Order $order, bool $only_not_settled = false $price = OrderCapture::get_item_price( $order_item, $order ); $tax_percent = $price['tax_percent']; - $unit_price = round( ( $prices_incl_tax ? $price['with_tax_and_discount'] : $price['original_with_discount'] ) / $order_item->get_quantity(), 2 ); + $unit_price = round( ( $prices_incl_tax ? $price['with_tax_and_discount'] : $price['subtotal'] ) / $order_item->get_quantity(), 2 ); if ( $only_not_settled && ! empty( $order_item->get_meta( 'settled' ) ) ) { continue; @@ -1500,10 +1499,12 @@ public function get_order_items( WC_Order $order, bool $only_not_settled = false $tax = $discount_with_tax - $discount; $tax_percent = ( $tax > 0 ) ? round( 100 / ( $discount / $tax ) ) : 0; + $discount_amount = round( - 1 * rp_prepare_amount( $prices_incl_tax ? $discount_with_tax : $discount, $order->get_currency() ) ) + ( $sub_amount_discount * 100 ); + $items[] = array( 'ordertext' => __( 'Discount', 'reepay-checkout-gateway' ), 'quantity' => 1, - 'amount' => round( - 1 * rp_prepare_amount( $prices_incl_tax ? $discount_with_tax : $discount, $order->get_currency() ) ) + ( $sub_amount_discount * 100 ), + 'amount' => round( $discount_amount, 2 ), 'vat' => round( $tax_percent / 100, 2 ), 'amount_incl_vat' => $prices_incl_tax, ); diff --git a/includes/OrderFlow/OrderCapture.php b/includes/OrderFlow/OrderCapture.php index 8f8b6949..8ba2e71d 100644 --- a/includes/OrderFlow/OrderCapture.php +++ b/includes/OrderFlow/OrderCapture.php @@ -475,9 +475,9 @@ public static function get_item_price( $order_item, WC_Order $order ): array { $discount = 0; } + $price['subtotal'] = floatval( $order->get_line_subtotal( $order_item, false, false ) ); $price['original'] = floatval( $order->get_line_total( $order_item, false, false ) ); $price['with_tax'] = floatval( $order->get_line_total( $order_item, true, false ) ); - if ( WPCProductBundlesWooCommerceIntegration::is_active_plugin() ) { $price_bundle = floatval( $order_item->get_meta( '_woosb_price' ) ); if ( ! empty( $price_bundle ) ) { @@ -486,7 +486,6 @@ public static function get_item_price( $order_item, WC_Order $order ): array { $price['with_tax'] += $price_bundle; } } - $tax = $price['with_tax'] - $price['original']; $price['tax_percent'] = ( $tax > 0 && $price['original'] > 0 ) ? round( 100 / ( $price['original'] / $tax ) ) : 0; From b14fac348cd73900d182ce7198265e1affcb5af7 Mon Sep 17 00:00:00 2001 From: Pond Date: Wed, 14 Aug 2024 09:54:32 +0700 Subject: [PATCH 02/10] Rollback source code to old version --- includes/Gateways/ReepayGateway.php | 2 +- includes/OrderFlow/OrderCapture.php | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/includes/Gateways/ReepayGateway.php b/includes/Gateways/ReepayGateway.php index 9edce464..c300d916 100644 --- a/includes/Gateways/ReepayGateway.php +++ b/includes/Gateways/ReepayGateway.php @@ -1428,7 +1428,7 @@ public function get_order_items( WC_Order $order, bool $only_not_settled = false $price = OrderCapture::get_item_price( $order_item, $order ); $tax_percent = $price['tax_percent']; - $unit_price = round( ( $prices_incl_tax ? $price['with_tax_and_discount'] : $price['subtotal'] ) / $order_item->get_quantity(), 2 ); + $unit_price = round( ( $prices_incl_tax ? $price['with_tax_and_discount'] : $price['original_with_discount'] ) / $order_item->get_quantity(), 2 ); if ( $only_not_settled && ! empty( $order_item->get_meta( 'settled' ) ) ) { continue; diff --git a/includes/OrderFlow/OrderCapture.php b/includes/OrderFlow/OrderCapture.php index 8ba2e71d..d93249fb 100644 --- a/includes/OrderFlow/OrderCapture.php +++ b/includes/OrderFlow/OrderCapture.php @@ -475,7 +475,6 @@ public static function get_item_price( $order_item, WC_Order $order ): array { $discount = 0; } - $price['subtotal'] = floatval( $order->get_line_subtotal( $order_item, false, false ) ); $price['original'] = floatval( $order->get_line_total( $order_item, false, false ) ); $price['with_tax'] = floatval( $order->get_line_total( $order_item, true, false ) ); if ( WPCProductBundlesWooCommerceIntegration::is_active_plugin() ) { From 84d9e5a99166fed6cbf89f8a6c0063193f79e5db Mon Sep 17 00:00:00 2001 From: Pond Date: Mon, 19 Aug 2024 09:31:21 +0700 Subject: [PATCH 03/10] Fix mix order with discount --- includes/Gateways/ReepayGateway.php | 35 ++++++++++++++++++++++++----- includes/OrderFlow/OrderCapture.php | 6 +++-- 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/includes/Gateways/ReepayGateway.php b/includes/Gateways/ReepayGateway.php index c300d916..19dacf04 100644 --- a/includes/Gateways/ReepayGateway.php +++ b/includes/Gateways/ReepayGateway.php @@ -1416,6 +1416,9 @@ public function get_order_items( WC_Order $order, bool $only_not_settled = false continue; } + $price = OrderCapture::get_item_price( $order_item, $order ); + $tax_percent = $price['tax_percent']; + if ( $order_item->get_product() && wcr_is_subscription_product( $order_item->get_product() ) ) { $fee = $order_item->get_product()->get_meta( '_reepay_subscription_fee' ); if ( ! empty( $fee ) && ! empty( $fee['enabled'] ) && 'yes' === $fee['enabled'] ) { @@ -1425,10 +1428,7 @@ public function get_order_items( WC_Order $order, bool $only_not_settled = false continue; } - $price = OrderCapture::get_item_price( $order_item, $order ); - - $tax_percent = $price['tax_percent']; - $unit_price = round( ( $prices_incl_tax ? $price['with_tax_and_discount'] : $price['original_with_discount'] ) / $order_item->get_quantity(), 2 ); + $unit_price = round( ( $prices_incl_tax ? $price['subtotal_with_tax'] : $price['subtotal'] ) / $order_item->get_quantity(), 2 ); if ( $only_not_settled && ! empty( $order_item->get_meta( 'settled' ) ) ) { continue; @@ -1499,12 +1499,35 @@ public function get_order_items( WC_Order $order, bool $only_not_settled = false $tax = $discount_with_tax - $discount; $tax_percent = ( $tax > 0 ) ? round( 100 / ( $discount / $tax ) ) : 0; - $discount_amount = round( - 1 * rp_prepare_amount( $prices_incl_tax ? $discount_with_tax : $discount, $order->get_currency() ) ) + ( $sub_amount_discount * 100 ); + // $discount_amount = round( - 1 * rp_prepare_amount( $prices_incl_tax ? $discount_with_tax : $discount, $order->get_currency() ) ) + ( $sub_amount_discount * 100 ); + + if($sub_amount_discount !== 0 && $discount !== 0){ + /** + * Discount for subscription + */ + if($prices_incl_tax || $tax_percent > 0){ + $simple_discount_amount = $discount_with_tax - $sub_amount_discount; + }else{ + $simple_discount_amount = $discount - $sub_amount_discount; + } + }else{ + /** + * Discount for simple product + */ + $simple_discount_amount = $discount; + } + + if($prices_incl_tax || $tax_percent > 0){ + $percentage_increase = round( 1 + ( $tax_percent / 100), 2); + $simple_discount_amount = $simple_discount_amount / $percentage_increase; + } + + $discount_amount = round( - 1 * rp_prepare_amount( $simple_discount_amount, $order->get_currency() ) ); $items[] = array( 'ordertext' => __( 'Discount', 'reepay-checkout-gateway' ), 'quantity' => 1, - 'amount' => round( $discount_amount, 2 ), + 'amount' => round( $discount_amount, 2), 'vat' => round( $tax_percent / 100, 2 ), 'amount_incl_vat' => $prices_incl_tax, ); diff --git a/includes/OrderFlow/OrderCapture.php b/includes/OrderFlow/OrderCapture.php index d93249fb..305d1fc0 100644 --- a/includes/OrderFlow/OrderCapture.php +++ b/includes/OrderFlow/OrderCapture.php @@ -475,6 +475,8 @@ public static function get_item_price( $order_item, WC_Order $order ): array { $discount = 0; } + $price['subtotal'] = floatval( $order->get_line_subtotal( $order_item, false, false ) ); + $price['subtotal_with_tax'] = floatval( $order->get_line_subtotal( $order_item, true, false ) ); $price['original'] = floatval( $order->get_line_total( $order_item, false, false ) ); $price['with_tax'] = floatval( $order->get_line_total( $order_item, true, false ) ); if ( WPCProductBundlesWooCommerceIntegration::is_active_plugin() ) { @@ -486,8 +488,8 @@ public static function get_item_price( $order_item, WC_Order $order ): array { } } $tax = $price['with_tax'] - $price['original']; - $price['tax_percent'] = ( $tax > 0 && $price['original'] > 0 ) ? round( 100 / ( $price['original'] / $tax ) ) : 0; - + $price_tax_percent = ( $tax > 0 && $price['original'] > 0 ) ? round( 100 / ( $price['original'] / $tax ) ) : 0; + $price['tax_percent'] = round($price_tax_percent, 2); $price['original_with_discount'] = $price['original'] + $discount; $price['with_tax_and_discount'] = $price['with_tax'] + $discount; From 8a706e965c1a1c0162efb6bf1fdc435ed3cf990d Mon Sep 17 00:00:00 2001 From: Pond Date: Mon, 19 Aug 2024 17:10:26 +0700 Subject: [PATCH 04/10] Fix allow use Billwerk+ Optimize only subscription product --- includes/Gateways/ReepayGateway.php | 36 ++++++----------------------- 1 file changed, 7 insertions(+), 29 deletions(-) diff --git a/includes/Gateways/ReepayGateway.php b/includes/Gateways/ReepayGateway.php index 19dacf04..d76a531b 100644 --- a/includes/Gateways/ReepayGateway.php +++ b/includes/Gateways/ReepayGateway.php @@ -1058,6 +1058,7 @@ public function process_payment( $order_id ) { // If here's Subscription or zero payment. if ( ( $have_sub ) && ( abs( $order->get_total() ) < 0.01 || empty( $only_items_lines ) ) ) { + $result = reepay()->api( $this )->recurring( $this->payment_methods, $order, $data, false, $params['button_text'] ); if ( is_wp_error( $result ) ) { @@ -1416,9 +1417,6 @@ public function get_order_items( WC_Order $order, bool $only_not_settled = false continue; } - $price = OrderCapture::get_item_price( $order_item, $order ); - $tax_percent = $price['tax_percent']; - if ( $order_item->get_product() && wcr_is_subscription_product( $order_item->get_product() ) ) { $fee = $order_item->get_product()->get_meta( '_reepay_subscription_fee' ); if ( ! empty( $fee ) && ! empty( $fee['enabled'] ) && 'yes' === $fee['enabled'] ) { @@ -1428,7 +1426,10 @@ public function get_order_items( WC_Order $order, bool $only_not_settled = false continue; } - $unit_price = round( ( $prices_incl_tax ? $price['subtotal_with_tax'] : $price['subtotal'] ) / $order_item->get_quantity(), 2 ); + $price = OrderCapture::get_item_price( $order_item, $order ); + $tax_percent = $price['tax_percent']; + + $unit_price = round( ( $prices_incl_tax ? $price['with_tax_and_discount'] : $price['original_with_discount'] ) / $order_item->get_quantity(), 2 ); if ( $only_not_settled && ! empty( $order_item->get_meta( 'settled' ) ) ) { continue; @@ -1499,31 +1500,8 @@ public function get_order_items( WC_Order $order, bool $only_not_settled = false $tax = $discount_with_tax - $discount; $tax_percent = ( $tax > 0 ) ? round( 100 / ( $discount / $tax ) ) : 0; - // $discount_amount = round( - 1 * rp_prepare_amount( $prices_incl_tax ? $discount_with_tax : $discount, $order->get_currency() ) ) + ( $sub_amount_discount * 100 ); - - if($sub_amount_discount !== 0 && $discount !== 0){ - /** - * Discount for subscription - */ - if($prices_incl_tax || $tax_percent > 0){ - $simple_discount_amount = $discount_with_tax - $sub_amount_discount; - }else{ - $simple_discount_amount = $discount - $sub_amount_discount; - } - }else{ - /** - * Discount for simple product - */ - $simple_discount_amount = $discount; - } - - if($prices_incl_tax || $tax_percent > 0){ - $percentage_increase = round( 1 + ( $tax_percent / 100), 2); - $simple_discount_amount = $simple_discount_amount / $percentage_increase; - } - - $discount_amount = round( - 1 * rp_prepare_amount( $simple_discount_amount, $order->get_currency() ) ); - + $discount_amount = round( - 1 * rp_prepare_amount( $prices_incl_tax ? $discount_with_tax : $discount, $order->get_currency() ) ) + ( $sub_amount_discount * 100 ); + $items[] = array( 'ordertext' => __( 'Discount', 'reepay-checkout-gateway' ), 'quantity' => 1, From 9fe8135a49823ea2fdce0a82ea5842d7a5588846 Mon Sep 17 00:00:00 2001 From: Pond Date: Mon, 19 Aug 2024 20:00:12 +0700 Subject: [PATCH 05/10] Fix skipt order lines with calculate discount for subscription --- includes/Gateways/ReepayGateway.php | 47 +++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 3 deletions(-) diff --git a/includes/Gateways/ReepayGateway.php b/includes/Gateways/ReepayGateway.php index d76a531b..98c925a8 100644 --- a/includes/Gateways/ReepayGateway.php +++ b/includes/Gateways/ReepayGateway.php @@ -828,7 +828,8 @@ public function process_payment( $order_id ) { ), 'order' => array( 'handle' => $order_handle, - 'amount' => 'yes' === $this->skip_order_lines ? rp_prepare_amount( $order->get_total(), $order->get_currency() ) : null, + // 'amount' => 'yes' === $this->skip_order_lines ? rp_prepare_amount( $order->get_total(), $order->get_currency() ) : null, + 'amount' => 'yes' === $this->skip_order_lines ? $this->get_skip_order_lines_amount( $order ) : null, 'order_lines' => 'no' === $this->skip_order_lines ? $this->get_order_items( $order ) : null, 'currency' => $order->get_currency(), 'customer' => array( @@ -1006,7 +1007,8 @@ public function process_payment( $order_id ) { return $this->process_session_charge( $params, $order ); } else { $order_lines = 'no' === $this->skip_order_lines ? $this->get_order_items( $order ) : null; - $amount = 'yes' === $this->skip_order_lines ? $order->get_total() : null; + // $amount = 'yes' === $this->skip_order_lines ? $order->get_total() : null; + $amount = 'yes' === $this->skip_order_lines ? $this->get_skip_order_lines_amount( $order ) : null; // Charge payment. $result = reepay()->api( $this )->charge( $order, $token->get_token(), $amount, $order_lines ); @@ -1500,8 +1502,32 @@ public function get_order_items( WC_Order $order, bool $only_not_settled = false $tax = $discount_with_tax - $discount; $tax_percent = ( $tax > 0 ) ? round( 100 / ( $discount / $tax ) ) : 0; - $discount_amount = round( - 1 * rp_prepare_amount( $prices_incl_tax ? $discount_with_tax : $discount, $order->get_currency() ) ) + ( $sub_amount_discount * 100 ); + // $discount_amount = round( - 1 * rp_prepare_amount( $prices_incl_tax ? $discount_with_tax : $discount, $order->get_currency() ) ) + ( $sub_amount_discount * 100 ); + + if($sub_amount_discount !== 0 && $discount !== 0){ + /** + * Discount for subscription + */ + if($prices_incl_tax || $tax_percent > 0){ + $simple_discount_amount = $discount_with_tax - $sub_amount_discount; + }else{ + $simple_discount_amount = $discount - $sub_amount_discount; + } + }else{ + /** + * Discount for simple product + */ + $simple_discount_amount = $discount; + } + + if($prices_incl_tax || $tax_percent > 0){ + $percentage_increase = round( 1 + ( $tax_percent / 100), 2); + $simple_discount_amount = $simple_discount_amount / $percentage_increase; + } + + $discount_amount = round( - 1 * rp_prepare_amount( $simple_discount_amount, $order->get_currency() ) ); + if($discount_amount < 0){ $items[] = array( 'ordertext' => __( 'Discount', 'reepay-checkout-gateway' ), 'quantity' => 1, @@ -1510,6 +1536,7 @@ public function get_order_items( WC_Order $order, bool $only_not_settled = false 'amount_incl_vat' => $prices_incl_tax, ); } + } // Add "PW Gift Cards" support. $items = array_merge( $items, PWGiftCardsIntegration::get_order_lines_for_reepay( $order, $prices_incl_tax ) ); @@ -1538,6 +1565,20 @@ public function get_order_items( WC_Order $order, bool $only_not_settled = false return $items; } + public function get_skip_order_lines_amount( WC_Order $order ){ + $total_amount = 0; + + $items = $this->get_order_items($order); + + if($items){ + foreach($items as $item){ + $total_amount += $item['amount']; + } + } + + return $total_amount; + } + /** * Get Language * From b5d447116ff58cec394f6c72dc125fb7c3a2c143 Mon Sep 17 00:00:00 2001 From: Pond Date: Tue, 20 Aug 2024 10:40:35 +0700 Subject: [PATCH 06/10] Fix standard code and function get order items --- includes/Gateways/ReepayGateway.php | 62 +++++++++++++++-------------- includes/OrderFlow/OrderCapture.php | 12 +++--- 2 files changed, 38 insertions(+), 36 deletions(-) diff --git a/includes/Gateways/ReepayGateway.php b/includes/Gateways/ReepayGateway.php index 98c925a8..8077e3c4 100644 --- a/includes/Gateways/ReepayGateway.php +++ b/includes/Gateways/ReepayGateway.php @@ -828,7 +828,6 @@ public function process_payment( $order_id ) { ), 'order' => array( 'handle' => $order_handle, - // 'amount' => 'yes' === $this->skip_order_lines ? rp_prepare_amount( $order->get_total(), $order->get_currency() ) : null, 'amount' => 'yes' === $this->skip_order_lines ? $this->get_skip_order_lines_amount( $order ) : null, 'order_lines' => 'no' === $this->skip_order_lines ? $this->get_order_items( $order ) : null, 'currency' => $order->get_currency(), @@ -1007,7 +1006,6 @@ public function process_payment( $order_id ) { return $this->process_session_charge( $params, $order ); } else { $order_lines = 'no' === $this->skip_order_lines ? $this->get_order_items( $order ) : null; - // $amount = 'yes' === $this->skip_order_lines ? $order->get_total() : null; $amount = 'yes' === $this->skip_order_lines ? $this->get_skip_order_lines_amount( $order ) : null; // Charge payment. @@ -1428,10 +1426,10 @@ public function get_order_items( WC_Order $order, bool $only_not_settled = false continue; } - $price = OrderCapture::get_item_price( $order_item, $order ); + $price = OrderCapture::get_item_price( $order_item, $order ); $tax_percent = $price['tax_percent']; - $unit_price = round( ( $prices_incl_tax ? $price['with_tax_and_discount'] : $price['original_with_discount'] ) / $order_item->get_quantity(), 2 ); + $unit_price = round( ( $prices_incl_tax ? $price['subtotal_with_tax'] : $price['subtotal'] ) / $order_item->get_quantity(), 2 ); if ( $only_not_settled && ! empty( $order_item->get_meta( 'settled' ) ) ) { continue; @@ -1502,40 +1500,39 @@ public function get_order_items( WC_Order $order, bool $only_not_settled = false $tax = $discount_with_tax - $discount; $tax_percent = ( $tax > 0 ) ? round( 100 / ( $discount / $tax ) ) : 0; - // $discount_amount = round( - 1 * rp_prepare_amount( $prices_incl_tax ? $discount_with_tax : $discount, $order->get_currency() ) ) + ( $sub_amount_discount * 100 ); - - if($sub_amount_discount !== 0 && $discount !== 0){ + if ( 0 !== $sub_amount_discount && 0 !== $discount ) { /** * Discount for subscription - */ - if($prices_incl_tax || $tax_percent > 0){ + */ + if ( $prices_incl_tax || $tax_percent > 0 ) { $simple_discount_amount = $discount_with_tax - $sub_amount_discount; - }else{ + } else { $simple_discount_amount = $discount - $sub_amount_discount; } - }else{ + } else { /** * Discount for simple product - */ + */ $simple_discount_amount = $discount; } - if($prices_incl_tax || $tax_percent > 0){ - $percentage_increase = round( 1 + ( $tax_percent / 100), 2); - $simple_discount_amount = $simple_discount_amount / $percentage_increase; + if ( $prices_incl_tax || $tax_percent > 0 ) { + // $percentage_increase = round( 1 + ( $tax_percent / 100 ), 2 ); + // $simple_discount_amount = $simple_discount_amount / $percentage_increase; + $discount_amount = round( - 1 * rp_prepare_amount( $prices_incl_tax ? $discount_with_tax : $discount, $order->get_currency() ) ); + }else{ + $discount_amount = round( - 1 * rp_prepare_amount( $simple_discount_amount, $order->get_currency() ) ); } - $discount_amount = round( - 1 * rp_prepare_amount( $simple_discount_amount, $order->get_currency() ) ); - - if($discount_amount < 0){ - $items[] = array( - 'ordertext' => __( 'Discount', 'reepay-checkout-gateway' ), - 'quantity' => 1, - 'amount' => round( $discount_amount, 2), - 'vat' => round( $tax_percent / 100, 2 ), - 'amount_incl_vat' => $prices_incl_tax, - ); - } + if ( $discount_amount < 0 ) { + $items[] = array( + 'ordertext' => __( 'Discount', 'reepay-checkout-gateway' ), + 'quantity' => 1, + 'amount' => round( $discount_amount, 2 ), + 'vat' => round( $tax_percent / 100, 2 ), + 'amount_incl_vat' => $prices_incl_tax, + ); + } } // Add "PW Gift Cards" support. @@ -1565,13 +1562,18 @@ public function get_order_items( WC_Order $order, bool $only_not_settled = false return $items; } - public function get_skip_order_lines_amount( WC_Order $order ){ + /** + * Get order amount from order item amount + * + * @param WC_Order $order order to get items. + */ + public function get_skip_order_lines_amount( WC_Order $order ) { $total_amount = 0; - $items = $this->get_order_items($order); + $items = $this->get_order_items( $order ); - if($items){ - foreach($items as $item){ + if ( $items ) { + foreach ( $items as $item ) { $total_amount += $item['amount']; } } diff --git a/includes/OrderFlow/OrderCapture.php b/includes/OrderFlow/OrderCapture.php index 305d1fc0..8d157e6d 100644 --- a/includes/OrderFlow/OrderCapture.php +++ b/includes/OrderFlow/OrderCapture.php @@ -475,10 +475,10 @@ public static function get_item_price( $order_item, WC_Order $order ): array { $discount = 0; } - $price['subtotal'] = floatval( $order->get_line_subtotal( $order_item, false, false ) ); + $price['subtotal'] = floatval( $order->get_line_subtotal( $order_item, false, false ) ); $price['subtotal_with_tax'] = floatval( $order->get_line_subtotal( $order_item, true, false ) ); - $price['original'] = floatval( $order->get_line_total( $order_item, false, false ) ); - $price['with_tax'] = floatval( $order->get_line_total( $order_item, true, false ) ); + $price['original'] = floatval( $order->get_line_total( $order_item, false, false ) ); + $price['with_tax'] = floatval( $order->get_line_total( $order_item, true, false ) ); if ( WPCProductBundlesWooCommerceIntegration::is_active_plugin() ) { $price_bundle = floatval( $order_item->get_meta( '_woosb_price' ) ); if ( ! empty( $price_bundle ) ) { @@ -487,9 +487,9 @@ public static function get_item_price( $order_item, WC_Order $order ): array { $price['with_tax'] += $price_bundle; } } - $tax = $price['with_tax'] - $price['original']; - $price_tax_percent = ( $tax > 0 && $price['original'] > 0 ) ? round( 100 / ( $price['original'] / $tax ) ) : 0; - $price['tax_percent'] = round($price_tax_percent, 2); + $tax = $price['with_tax'] - $price['original']; + $price_tax_percent = ( $tax > 0 && $price['original'] > 0 ) ? round( 100 / ( $price['original'] / $tax ) ) : 0; + $price['tax_percent'] = round( $price_tax_percent, 2 ); $price['original_with_discount'] = $price['original'] + $discount; $price['with_tax_and_discount'] = $price['with_tax'] + $discount; From 935298390fb7b0d5137b488700468db7b1e6f597 Mon Sep 17 00:00:00 2001 From: Pond Date: Tue, 20 Aug 2024 10:41:10 +0700 Subject: [PATCH 07/10] Fix unit test --- tests/unit/orderFlow/OrderCaptureTest.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/unit/orderFlow/OrderCaptureTest.php b/tests/unit/orderFlow/OrderCaptureTest.php index 2275f315..a53be30b 100644 --- a/tests/unit/orderFlow/OrderCaptureTest.php +++ b/tests/unit/orderFlow/OrderCaptureTest.php @@ -948,6 +948,8 @@ public function test_get_item_price_product() { 'tax_percent' => 0, 'original_with_discount' => $price * $qty, 'with_tax_and_discount' => $price * $qty, + 'subtotal' => $price * $qty, + 'subtotal_with_tax' => $price * $qty ), OrderCapture::get_item_price( WC_Order_Factory::get_order_item( $order_item_id ), $this->order_generator->order() ) ); @@ -979,6 +981,8 @@ public function test_get_item_price_product_with_discount() { 'tax_percent' => 0, 'original_with_discount' => $sale_price * $qty, 'with_tax_and_discount' => $sale_price * $qty, + 'subtotal' => $sale_price * $qty, + 'subtotal_with_tax' => $sale_price * $qty ), OrderCapture::get_item_price( WC_Order_Factory::get_order_item( $order_item_id ), $this->order_generator->order() ) ); @@ -1015,6 +1019,8 @@ public function test_get_item_price_product_with_taxes() { 'tax_percent' => round($tax_rate), 'original_with_discount' => $sale_price * $qty, 'with_tax_and_discount' => round(( $sale_price * $qty ) * ( 1 + $tax_rate / 100 ), 2), + 'subtotal' => $sale_price * $qty, + 'subtotal_with_tax' => round(( $sale_price * $qty ) * ( 1 + $tax_rate / 100 ), 2) ), OrderCapture::get_item_price( WC_Order_Factory::get_order_item( $order_item_id ), $this->order_generator->order() ) ); @@ -1039,6 +1045,8 @@ public function test_get_item_price_shipping() { 'tax_percent' => 0, 'original_with_discount' => $price, 'with_tax_and_discount' => $price, + 'subtotal' => 0, + 'subtotal_with_tax' => 0 ), OrderCapture::get_item_price( WC_Order_Factory::get_order_item( $order_item_id ), $this->order_generator->order() ) ); @@ -1063,6 +1071,8 @@ public function test_get_item_price_fee() { 'tax_percent' => 0, 'original_with_discount' => $price, 'with_tax_and_discount' => $price, + 'subtotal' => 0, + 'subtotal_with_tax' => 0 ), OrderCapture::get_item_price( WC_Order_Factory::get_order_item( $order_item_id ), $this->order_generator->order() ) ); From 353f1d14dc5914d9366c9400d1756cf84f254dde Mon Sep 17 00:00:00 2001 From: Pond Date: Tue, 20 Aug 2024 10:42:07 +0700 Subject: [PATCH 08/10] Change version to 1.7.7.2 and add changelog message --- Readme.txt | 5 ++++- composer.json | 1 + reepay-woocommerce-payment.php | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Readme.txt b/Readme.txt index 1695554a..c2844801 100755 --- a/Readme.txt +++ b/Readme.txt @@ -4,7 +4,7 @@ Tags: billwerk+, visa, mastercard, dankort, mobilepay Requires at least: 4.0 Tested up to: 6.5.3 Requires PHP: 7.4 -Stable tag: 1.7.7.1 +Stable tag: 1.7.7.2 License: GPL License URI: http://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html @@ -18,6 +18,9 @@ The Billwerk+ Pay plugin extends WooCommerce allowing you to take payments on yo See installation guide right here: https://docu.billwerk.plus/help/en/apps/woocommerce/setup-woocommerce-plugin.html == Changelog == +v 1.7.7.2 - +* [Fix] - Bug double amount calculated when using setting "skip order lines" + v 1.7.7.1 - * [Fix] - WP warning message The use statement with non-compound name WC_Reepay_Renewals has no effect. diff --git a/composer.json b/composer.json index 46f9b927..e3bd11e2 100644 --- a/composer.json +++ b/composer.json @@ -3,6 +3,7 @@ "description": "Get a plug-n-play payment solution for WooCommerce, that is easy to use, highly secure and is built to maximize the potential of your e-commerce.", "type": "wordpress-plugin", "license": "GPL", + "version": "1.7.7.2", "autoload": { "psr-4": { "Reepay\\Checkout\\": "includes/", diff --git a/reepay-woocommerce-payment.php b/reepay-woocommerce-payment.php index d0a19802..d3acaabe 100755 --- a/reepay-woocommerce-payment.php +++ b/reepay-woocommerce-payment.php @@ -4,7 +4,7 @@ * Description: Get a plug-n-play payment solution for WooCommerce, that is easy to use, highly secure and is built to maximize the potential of your e-commerce. * Author: Billwerk+ * Author URI: http://billwerk.plus - * Version: 1.7.7.1 + * Version: 1.7.7.2 * Text Domain: reepay-checkout-gateway * Domain Path: /languages * WC requires at least: 3.0.0 From cf335f0b0032b83a9343cf3d616ef29a314789fa Mon Sep 17 00:00:00 2001 From: Pond Date: Tue, 20 Aug 2024 10:43:56 +0700 Subject: [PATCH 09/10] Fix amount skipt order lines --- includes/Api.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/Api.php b/includes/Api.php index 5faaada4..6ffcb66c 100644 --- a/includes/Api.php +++ b/includes/Api.php @@ -722,7 +722,7 @@ public function settle( WC_Order $order, $amount = null, $items_data = false, $l } if ( ! empty( $amount ) && reepay()->get_setting( 'skip_order_lines' ) === 'yes' ) { - $request_data['amount'] = rp_prepare_amount( $amount, $order->get_currency() ); + $request_data['amount'] = $amount; } else { $request_data['order_lines'] = $items_data; } From 1b9d0b1117a408e40502a0b5176ca1be2999854c Mon Sep 17 00:00:00 2001 From: Pond Date: Tue, 20 Aug 2024 10:49:49 +0700 Subject: [PATCH 10/10] Fix code standard --- includes/Gateways/ReepayGateway.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/includes/Gateways/ReepayGateway.php b/includes/Gateways/ReepayGateway.php index 8077e3c4..8226f155 100644 --- a/includes/Gateways/ReepayGateway.php +++ b/includes/Gateways/ReepayGateway.php @@ -1517,10 +1517,8 @@ public function get_order_items( WC_Order $order, bool $only_not_settled = false } if ( $prices_incl_tax || $tax_percent > 0 ) { - // $percentage_increase = round( 1 + ( $tax_percent / 100 ), 2 ); - // $simple_discount_amount = $simple_discount_amount / $percentage_increase; $discount_amount = round( - 1 * rp_prepare_amount( $prices_incl_tax ? $discount_with_tax : $discount, $order->get_currency() ) ); - }else{ + } else { $discount_amount = round( - 1 * rp_prepare_amount( $simple_discount_amount, $order->get_currency() ) ); }