Skip to content

Commit 7edf7d5

Browse files
authored
Merge pull request #122 from AltaPay/fix-discount-calculations
Fix: Order line calculations when a cart discount is applied.
2 parents 4a1b6a0 + 5ba560b commit 7edf7d5

7 files changed

Lines changed: 23 additions & 13 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Changelog
22
All notable changes to this project will be documented in this file.
33

4+
## [3.8.1]
5+
- Fix: Order line calculations when a cart discount is applied.
6+
47
## [3.8.0]
58
- Add support for the new PayPal Integration.
69

altapay.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
* Author URI: https://altapay.com
88
* Text Domain: altapay
99
* Domain Path: /languages
10-
* Version: 3.8.0
10+
* Version: 3.8.1
1111
* Name: SDM_Altapay
1212
* WC requires at least: 3.9.0
13-
* WC tested up to: 9.8.5
13+
* WC tested up to: 9.9.4
1414
*
1515
* @package Altapay
1616
*/
@@ -41,7 +41,7 @@
4141
}
4242

4343
if ( ! defined( 'ALTAPAY_PLUGIN_VERSION' ) ) {
44-
define( 'ALTAPAY_PLUGIN_VERSION', '3.8.0' );
44+
define( 'ALTAPAY_PLUGIN_VERSION', '3.8.1' );
4545
}
4646

4747
// Include the autoloader, so we can dynamically include the rest of the classes.
@@ -734,7 +734,7 @@ function altapayRefundCallback() {
734734

735735
$refund = altapayRefundPayment( $orderID, $amount, null, true );
736736

737-
if ( $refund['success'] === true ) {
737+
if ( isset( $refund['success'] ) && $refund['success'] === true ) {
738738
wp_send_json_success( $refund );
739739
} else {
740740
$error = $refund['error'] ?? 'Error in the refund operation.';

assets/js/capture.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jQuery( document ).ready(
1414
capture: function (element) {
1515
var amount = parseFloat( $( '#capture-amount' ).val() );
1616
var productsArrData = [];
17-
if ($( "#ap-allow-orderlines" ).attr( "checked" ) === "checked") {
17+
if ($( "#ap-allow-orderlines" ).prop("checked")) {
1818
$( '.ap-orderlines-capture:has(input)' ).each(
1919
function () {
2020
var productArrData = [];

assets/js/refund.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jQuery( document ).ready(
1616
var goodwillrefund = 'no';
1717
var amount = parseFloat( $( '#refund-amount' ).val() );
1818
var productsArrData = [];
19-
if ($( "#ap-allow-refund-orderlines" ).attr( "checked" ) === "checked") {
19+
if ($("#ap-allow-refund-orderlines").prop("checked")) {
2020
$( '.ap-orderlines-refund:has(input)' ).each(
2121
function () {
2222
var productArrData = [];

classes/util/UtilMethods.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,16 @@ public function createOrderLines( $order, $products = array(), $wcRefund = false
7575
$orderLines [] = $shippingDetails;
7676
}
7777

78-
if ( $order->get_total_discount() ) {
78+
$discount_total = (float) $order->get_discount_total();
79+
$discount_tax = (float) $order->get_discount_tax();
80+
$total_discount = round( $discount_total + $discount_tax, 2 );
81+
82+
if ( $total_discount ) {
7983
$orderLine = new OrderLine(
8084
'Discount',
8185
'discount',
8286
1,
83-
-abs( $order->get_total_discount() )
87+
-abs( $total_discount )
8488
);
8589
$orderLine->taxAmount = 0;
8690
$orderLine->unitCode = 'unit';
@@ -125,7 +129,7 @@ private function getOrderLine( $item, $isSubscription = false ) {
125129
$orderLine->unitCode = $quantity > 1 ? 'units' : 'unit';
126130

127131
if ( ! $isSubscription ) {
128-
$orderLine->taxAmount = round( $item->get_total_tax(), 2 );
132+
$orderLine->taxAmount = round( $item->get_subtotal_tax(), 2 );
129133
}
130134

131135
$goodsType = ( $isSubscription ) ? 'subscription_model' : 'item';

readme.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ Tags: AltaPay, Gateway, Payments, WooCommerce, Payment Card Industry
44
Requires PHP: 7.4
55
Requires at least: 5.0
66
Tested up to: 6.8.1
7-
Stable tag: 3.8.0
7+
Stable tag: 3.8.1
88
License: MIT
99
WC requires at least: 3.9.0
10-
WC tested up to: 9.8.5
10+
WC tested up to: 9.9.4
1111
License URI: http://www.gnu.org/licenses/gpl-2.0.html
1212

1313
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
3939

4040
== Changelog ==
4141

42+
= 3.8.1 =
43+
* Fix: Order line calculations when a cart discount is applied.
44+
4245
= 3.8.0 =
4346
* Add support for the new PayPal Integration.
4447

wiki.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,13 +299,13 @@ The new credentials can now be used as the API Username and API Password in your
299299

300300
Minimum system requirements are:
301301
- WordPress min. 5.0 – max. 6.8.1
302-
- WooCommerce min. 3.9.0 – max. 9.8.5
302+
- WooCommerce min. 3.9.0 – max. 9.9.4
303303
- PHP 7.4 and above
304304
- PHP-bcmath library installed.
305305
- PHP-curl MUST be enabled.
306306

307307
The latest tested version is:
308-
- WordPress 6.8.1, WooCommerce 9.8.5 and PHP 8.2
308+
- WordPress 6.8.1, WooCommerce 9.9.4 and PHP 8.2
309309

310310

311311
## Troubleshooting

0 commit comments

Comments
 (0)