Skip to content

Commit 4a1b6a0

Browse files
authored
Merge pull request #121 from AltaPay/new-paypal-integration
Update orderlines for the new PayPal integration
2 parents ef85d52 + 366bb48 commit 4a1b6a0

5 files changed

Lines changed: 47 additions & 81 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.0]
5+
- Add support for the new PayPal Integration.
6+
47
## [3.7.9]
58
- Support applying surcharge fee to order payments.
69

altapay.php

Lines changed: 3 additions & 3 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.7.9
10+
* Version: 3.8.0
1111
* Name: SDM_Altapay
1212
* WC requires at least: 3.9.0
13-
* WC tested up to: 9.8.1
13+
* WC tested up to: 9.8.5
1414
*
1515
* @package Altapay
1616
*/
@@ -41,7 +41,7 @@
4141
}
4242

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

4747
// Include the autoloader, so we can dynamically include the rest of the classes.

classes/util/UtilMethods.php

Lines changed: 32 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@ public function createOrderLines( $order, $products = array(), $wcRefund = false
4141

4242
// generate order lines product by product
4343
foreach ( $cartItems as $key => $item ) {
44-
$total = $item->get_total();
45-
$subtotal = $item->get_subtotal();
46-
$discount = 0;
44+
$total = $item->get_total();
4745

4846
if ( $total == 0 && $isSubscription ) {
4947
$total = (float) $item->get_product()->get_regular_price();
@@ -53,22 +51,14 @@ public function createOrderLines( $order, $products = array(), $wcRefund = false
5351
continue;
5452
}
5553

56-
$discountPercentage = 0;
57-
if ( $subtotal > 0 ) {
58-
$discount = $subtotal - $total;
59-
$discountPercentage = ( $subtotal - $total ) / $subtotal * 100;
60-
}
61-
// get product details for each order line
62-
$productDetails = $this->getProductDetails( $item, $discount, $discountPercentage, ( ( $i == 0 ) ? $isSubscription : 0 ) );
63-
6454
if ( $wcRefund ) {
6555
$orderLines[ $key ] = array(
6656
'qty' => $products['itemQty'][ $key ],
6757
'refund_total' => ( $item['line_total'] / $item->get_quantity() ) * $products['itemQty'][ $key ],
6858
'refund_tax' => ( $item->get_total_tax() / $item->get_quantity() ) * $products['itemQty'][ $key ],
6959
);
7060
} else {
71-
$orderLines[] = $productDetails['product'];
61+
$orderLines[] = $this->getOrderLine( $item, ( ( $i == 0 ) ? $isSubscription : 0 ) );
7262
}
7363

7464
$i ++;
@@ -85,6 +75,20 @@ public function createOrderLines( $order, $products = array(), $wcRefund = false
8575
$orderLines [] = $shippingDetails;
8676
}
8777

78+
if ( $order->get_total_discount() ) {
79+
$orderLine = new OrderLine(
80+
'Discount',
81+
'discount',
82+
1,
83+
-abs( $order->get_total_discount() )
84+
);
85+
$orderLine->taxAmount = 0;
86+
$orderLine->unitCode = 'unit';
87+
$orderLine->setGoodsType( 'handling' );
88+
89+
$orderLines [] = $orderLine;
90+
}
91+
8892
if ( ! $wcRefund ) {
8993
// Calculate compensation amount
9094
$totalCompensationAmount = $this->totalCompensationAmount( $orderLines, $order->get_total() );
@@ -98,76 +102,36 @@ public function createOrderLines( $order, $products = array(), $wcRefund = false
98102
}
99103

100104
/**
101-
* Returns product Details based on product type and tax configuration settings
105+
* Returns order line for the order item
102106
*
103107
* @param object $item
104-
* @param float $discount
105-
* @param float $discountPercentage
108+
* @param bool $isSubscription
106109
*
107-
* @return array
110+
* @return OrderLine
108111
*/
109-
private function getProductDetails( $item, $discount, $discountPercentage, $isSubscription = false ) {
110-
$product = $item->get_product();
111-
$quantity = $item->get_quantity();
112-
$regularPrice = (float) $product->get_regular_price();
113-
$salePrice = (float) $product->get_sale_price();
114-
$subtotal = $item->get_subtotal();
115-
$taxRate = $subtotal > 0 ? $item->get_subtotal_tax() / $subtotal : 0;
116-
$productId = $product->get_sku() ? $item->get_id() . '-' . $product->get_sku() : $item->get_id();
117-
$productData = array();
118-
$productDiscount = 0;
119-
120-
if ( $product->get_type() === 'variable' || $product->get_type() === 'variable-subscription' ) {
121-
$variationId = (int) $item->get_variation_id();
122-
$product_data = wc_get_product( $variationId );
123-
$regularPrice = (float) $product_data->get_regular_price();
124-
$salePrice = (float) $product_data->get_sale_price() ? $product_data->get_sale_price() : 0;
125-
}
126-
127-
// calculate discount if catalogue rule is applied on order line i.e. product sale price is set
128-
if ( $product->is_on_sale() ) {
129-
$productDiscount = $regularPrice - $salePrice;
130-
// convert discount amount into percentage
131-
$discountPercentage += round( ( $productDiscount / $regularPrice ) * 100, 2 );
132-
}
133-
134-
if ( wc_prices_include_tax() ) {
135-
$taxRate = 1 + $taxRate;
136-
$productPrice = round( $regularPrice / $taxRate, 2 );
137-
$taxAmount = $regularPrice - $productPrice;
138-
} else {
139-
$productPrice = $regularPrice;
140-
$taxAmount = $productPrice * $taxRate;
141-
}
142-
143-
$productPrice = $isSubscription ? ( $productPrice + ( $taxAmount * $quantity ) - ( $discount + $productDiscount ) ) : round( $productPrice, 2 );
144-
$taxPercent = $productPrice > 0 ? round( ( $taxAmount / $productPrice ) * 100, 2 ) : 0;
145-
$taxAmount = round( $taxAmount * $quantity, 2 );
146-
$discount = round( $discountPercentage, 2 );
112+
private function getOrderLine( $item, $isSubscription = false ) {
113+
$product = $item->get_product();
114+
$quantity = $item->get_quantity();
147115

148116
// generate line date with all the calculated parameters
149117
$orderLine = new OrderLine(
150118
$item->get_name(),
151-
$productId,
119+
$item->get_id(),
152120
$quantity,
153-
round( $productPrice, 2 )
121+
round( $item->get_subtotal() / $quantity, 2 )
154122
);
155123
$orderLine->productUrl = $product->get_permalink();
156124
$orderLine->imageUrl = wp_get_attachment_url( $product->get_image_id() );
157125
$orderLine->unitCode = $quantity > 1 ? 'units' : 'unit';
158126

159127
if ( ! $isSubscription ) {
160-
$orderLine->discount = $discount;
161-
$orderLine->taxAmount = $taxAmount;
162-
$orderLine->taxPercent = $taxPercent;
128+
$orderLine->taxAmount = round( $item->get_total_tax(), 2 );
163129
}
164130

165131
$goodsType = ( $isSubscription ) ? 'subscription_model' : 'item';
166132
$orderLine->setGoodsType( $goodsType );
167133

168-
$productData['product'] = $orderLine;
169-
170-
return $productData;
134+
return $orderLine;
171135
}
172136

173137
/**
@@ -180,16 +144,14 @@ private function getProductDetails( $item, $discount, $discountPercentage, $isSu
180144
*/
181145
public function compensationAmountOrderline( $productId, $compensationAmount ) {
182146
// Generate compensation amount orderline for payment, capture and refund requests
183-
$orderLine = new OrderLine(
147+
$orderLine = new OrderLine(
184148
'Compensation',
185149
'comp-' . $productId,
186150
1,
187151
$compensationAmount
188152
);
189-
$orderLine->taxAmount = 0.00;
190-
$orderLine->taxPercent = 0.00;
191-
$orderLine->unitCode = 'unit';
192-
$orderLine->discount = 0.00;
153+
$orderLine->taxAmount = 0.00;
154+
$orderLine->unitCode = 'unit';
193155
$orderLine->setGoodsType( 'handling' );
194156

195157
return $orderLine;
@@ -233,16 +195,14 @@ private function getShippingDetails( $order, $products, $wcRefund ) {
233195
'refund_tax' => wc_format_decimal( $totalShippingTax ),
234196
);
235197
} else {
236-
$orderLine = new OrderLine(
198+
$orderLine = new OrderLine(
237199
$order->get_shipping_method(),
238200
$shippingID,
239201
1,
240202
round( $totalShipping, 2 )
241203
);
242-
$orderLine->taxAmount = round( $totalShippingTax, 2 );
243-
$orderLine->taxPercent = round( ( $totalShippingTax / $totalShipping ) * 100, 2 );
244-
$goodsType = 'shipment';
245-
$orderLine->setGoodsType( $goodsType );
204+
$orderLine->taxAmount = round( $totalShippingTax, 2 );
205+
$orderLine->setGoodsType( 'shipment' );
246206
$shippingDetails[] = $orderLine;
247207
}
248208
}

readme.txt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ Contributors: altapay_integrations
33
Tags: AltaPay, Gateway, Payments, WooCommerce, Payment Card Industry
44
Requires PHP: 7.4
55
Requires at least: 5.0
6-
Tested up to: 6.8
7-
Stable tag: 3.7.9
6+
Tested up to: 6.8.1
7+
Stable tag: 3.8.0
88
License: MIT
99
WC requires at least: 3.9.0
10-
WC tested up to: 9.8.1
10+
WC tested up to: 9.8.5
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.0 =
43+
* Add support for the new PayPal Integration.
44+
4245
= 3.7.9 =
4346
* Support applying surcharge fee to order payments.
4447

wiki.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -298,14 +298,14 @@ The new credentials can now be used as the API Username and API Password in your
298298
## Supported versions
299299

300300
Minimum system requirements are:
301-
- WordPress min. 5.0 – max. 6.8
302-
- WooCommerce min. 3.9.0 – max. 9.8.1
301+
- WordPress min. 5.0 – max. 6.8.1
302+
- WooCommerce min. 3.9.0 – max. 9.8.5
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, WooCommerce 9.8.1 and PHP 8.2
308+
- WordPress 6.8.1, WooCommerce 9.8.5 and PHP 8.2
309309

310310

311311
## Troubleshooting

0 commit comments

Comments
 (0)