From a0423470de4e23a5c5f549f461afff1493e6c3e0 Mon Sep 17 00:00:00 2001 From: Shahbaz Date: Thu, 19 Jun 2025 11:52:18 +0500 Subject: [PATCH 1/5] Fix Order line calculations when a cart discount is applied --- CHANGELOG.md | 3 +++ altapay.php | 8 ++++---- assets/js/capture.js | 3 ++- assets/js/refund.js | 2 +- classes/util/UtilMethods.php | 10 +++++++--- readme.txt | 7 +++++-- wiki.md | 4 ++-- 7 files changed, 24 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 483cb8de..bce1eaa2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ # Changelog All notable changes to this project will be documented in this file. +## [3.8.1] +- Fix: Order line calculations when a cart discount is applied. + ## [3.8.0] - Add support for the new PayPal Integration. diff --git a/altapay.php b/altapay.php index ea94a0cf..2a67e95f 100755 --- a/altapay.php +++ b/altapay.php @@ -7,10 +7,10 @@ * Author URI: https://altapay.com * Text Domain: altapay * Domain Path: /languages - * Version: 3.8.0 + * Version: 3.8.1 * Name: SDM_Altapay * WC requires at least: 3.9.0 - * WC tested up to: 9.8.5 + * WC tested up to: 9.9.4 * * @package Altapay */ @@ -41,7 +41,7 @@ } if ( ! defined( 'ALTAPAY_PLUGIN_VERSION' ) ) { - define( 'ALTAPAY_PLUGIN_VERSION', '3.8.0' ); + define( 'ALTAPAY_PLUGIN_VERSION', '3.8.1' ); } // Include the autoloader, so we can dynamically include the rest of the classes. @@ -734,7 +734,7 @@ function altapayRefundCallback() { $refund = altapayRefundPayment( $orderID, $amount, null, true ); - if ( $refund['success'] === true ) { + if ( isset( $refund['success'] ) && $refund['success'] === true ) { wp_send_json_success( $refund ); } else { $error = $refund['error'] ?? 'Error in the refund operation.'; diff --git a/assets/js/capture.js b/assets/js/capture.js index 6e5afb44..027e6abe 100755 --- a/assets/js/capture.js +++ b/assets/js/capture.js @@ -14,7 +14,8 @@ jQuery( document ).ready( capture: function (element) { var amount = parseFloat( $( '#capture-amount' ).val() ); var productsArrData = []; - if ($( "#ap-allow-orderlines" ).attr( "checked" ) === "checked") { + if ($( "#ap-allow-orderlines" ).prop("checked")) { + console.log("#ap-allow-orderlines checked"); $( '.ap-orderlines-capture:has(input)' ).each( function () { var productArrData = []; diff --git a/assets/js/refund.js b/assets/js/refund.js index 8a857449..c26ee3f8 100755 --- a/assets/js/refund.js +++ b/assets/js/refund.js @@ -16,7 +16,7 @@ jQuery( document ).ready( var goodwillrefund = 'no'; var amount = parseFloat( $( '#refund-amount' ).val() ); var productsArrData = []; - if ($( "#ap-allow-refund-orderlines" ).attr( "checked" ) === "checked") { + if ($("#ap-allow-refund-orderlines").prop("checked")) { $( '.ap-orderlines-refund:has(input)' ).each( function () { var productArrData = []; diff --git a/classes/util/UtilMethods.php b/classes/util/UtilMethods.php index 03e9eae6..7d90f951 100755 --- a/classes/util/UtilMethods.php +++ b/classes/util/UtilMethods.php @@ -75,12 +75,16 @@ public function createOrderLines( $order, $products = array(), $wcRefund = false $orderLines [] = $shippingDetails; } - if ( $order->get_total_discount() ) { + $discount_total = (float) $order->get_discount_total(); + $discount_tax = (float) $order->get_discount_tax(); + $total_discount = round( $discount_total + $discount_tax, 2 ); + + if ( $total_discount ) { $orderLine = new OrderLine( 'Discount', 'discount', 1, - -abs( $order->get_total_discount() ) + -$total_discount ); $orderLine->taxAmount = 0; $orderLine->unitCode = 'unit'; @@ -125,7 +129,7 @@ private function getOrderLine( $item, $isSubscription = false ) { $orderLine->unitCode = $quantity > 1 ? 'units' : 'unit'; if ( ! $isSubscription ) { - $orderLine->taxAmount = round( $item->get_total_tax(), 2 ); + $orderLine->taxAmount = round( $item->get_subtotal_tax(), 2 ); } $goodsType = ( $isSubscription ) ? 'subscription_model' : 'item'; diff --git a/readme.txt b/readme.txt index 2ae7d892..cd62d9c1 100644 --- a/readme.txt +++ b/readme.txt @@ -4,10 +4,10 @@ Tags: AltaPay, Gateway, Payments, WooCommerce, Payment Card Industry Requires PHP: 7.4 Requires at least: 5.0 Tested up to: 6.8.1 -Stable tag: 3.8.0 +Stable tag: 3.8.1 License: MIT WC requires at least: 3.9.0 -WC tested up to: 9.8.5 +WC tested up to: 9.9.4 License URI: http://www.gnu.org/licenses/gpl-2.0.html A plugin that integrates your WooCommerce web shop to the AltaPay payments gateway. @@ -39,6 +39,9 @@ AltaPay's Payment Gateway for WooCommerce provides merchants with access to a fu == Changelog == += 3.8.1 = +* Fix: Order line calculations when a cart discount is applied. + = 3.8.0 = * Add support for the new PayPal Integration. diff --git a/wiki.md b/wiki.md index 6c1b6b33..8bf00f2d 100644 --- a/wiki.md +++ b/wiki.md @@ -299,13 +299,13 @@ The new credentials can now be used as the API Username and API Password in your Minimum system requirements are: - WordPress min. 5.0 – max. 6.8.1 -- WooCommerce min. 3.9.0 – max. 9.8.5 +- WooCommerce min. 3.9.0 – max. 9.9.4 - PHP 7.4 and above - PHP-bcmath library installed. - PHP-curl MUST be enabled. The latest tested version is: -- WordPress 6.8.1, WooCommerce 9.8.5 and PHP 8.2 +- WordPress 6.8.1, WooCommerce 9.9.4 and PHP 8.2 ## Troubleshooting From 83428fc97d04ff28d99c94d7686aaea988fce039 Mon Sep 17 00:00:00 2001 From: Shahbaz Date: Thu, 19 Jun 2025 11:53:57 +0500 Subject: [PATCH 2/5] Remove log --- assets/js/capture.js | 1 - 1 file changed, 1 deletion(-) diff --git a/assets/js/capture.js b/assets/js/capture.js index 027e6abe..0e9063a3 100755 --- a/assets/js/capture.js +++ b/assets/js/capture.js @@ -15,7 +15,6 @@ jQuery( document ).ready( var amount = parseFloat( $( '#capture-amount' ).val() ); var productsArrData = []; if ($( "#ap-allow-orderlines" ).prop("checked")) { - console.log("#ap-allow-orderlines checked"); $( '.ap-orderlines-capture:has(input)' ).each( function () { var productArrData = []; From 224740af23d2b96a2784e6429c796d959fe28210 Mon Sep 17 00:00:00 2001 From: Shahbaz Date: Thu, 19 Jun 2025 18:29:31 +0500 Subject: [PATCH 3/5] Switch branch to update-ubuntu-22.04 --- .github/workflows/deployment.yml | 2 +- .github/workflows/support-deployment.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deployment.yml b/.github/workflows/deployment.yml index 80a3c2dd..892e4209 100644 --- a/.github/workflows/deployment.yml +++ b/.github/workflows/deployment.yml @@ -35,7 +35,7 @@ jobs: with: repository: AltaPay/plugin-infrastructure token: ${{ secrets.ACCESS_TOKEN }} - ref: 'main' + ref: 'update-ubuntu-22.04' # Install version 1.0.8 of Terraform CLI - name: Setup Terraform diff --git a/.github/workflows/support-deployment.yml b/.github/workflows/support-deployment.yml index cb777b1c..ec229dd0 100644 --- a/.github/workflows/support-deployment.yml +++ b/.github/workflows/support-deployment.yml @@ -28,7 +28,7 @@ jobs: with: repository: AltaPay/plugin-infrastructure token: ${{ secrets.ACCESS_TOKEN }} - ref: 'main' + ref: 'update-ubuntu-22.04' # Install version 1.0.8 of Terraform CLI - name: Setup Terraform From 35e9d8e9e4b0f2a50579e695f3f372a29a73e85d Mon Sep 17 00:00:00 2001 From: Shahbaz Date: Mon, 23 Jun 2025 18:25:46 +0500 Subject: [PATCH 4/5] Revert branch name to main --- .github/workflows/deployment.yml | 2 +- .github/workflows/support-deployment.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deployment.yml b/.github/workflows/deployment.yml index 892e4209..80a3c2dd 100644 --- a/.github/workflows/deployment.yml +++ b/.github/workflows/deployment.yml @@ -35,7 +35,7 @@ jobs: with: repository: AltaPay/plugin-infrastructure token: ${{ secrets.ACCESS_TOKEN }} - ref: 'update-ubuntu-22.04' + ref: 'main' # Install version 1.0.8 of Terraform CLI - name: Setup Terraform diff --git a/.github/workflows/support-deployment.yml b/.github/workflows/support-deployment.yml index ec229dd0..cb777b1c 100644 --- a/.github/workflows/support-deployment.yml +++ b/.github/workflows/support-deployment.yml @@ -28,7 +28,7 @@ jobs: with: repository: AltaPay/plugin-infrastructure token: ${{ secrets.ACCESS_TOKEN }} - ref: 'update-ubuntu-22.04' + ref: 'main' # Install version 1.0.8 of Terraform CLI - name: Setup Terraform From 5ba560bbe1167ee794f57a246ed1ff3a635cc0e5 Mon Sep 17 00:00:00 2001 From: Shahbaz Date: Mon, 23 Jun 2025 18:37:01 +0500 Subject: [PATCH 5/5] Use absolute value --- classes/util/UtilMethods.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes/util/UtilMethods.php b/classes/util/UtilMethods.php index 7d90f951..6eb4410e 100755 --- a/classes/util/UtilMethods.php +++ b/classes/util/UtilMethods.php @@ -84,7 +84,7 @@ public function createOrderLines( $order, $products = array(), $wcRefund = false 'Discount', 'discount', 1, - -$total_discount + -abs( $total_discount ) ); $orderLine->taxAmount = 0; $orderLine->unitCode = 'unit';