diff --git a/CHANGELOG.md b/CHANGELOG.md index e9732974..483cb8de 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.0] +- Add support for the new PayPal Integration. + ## [3.7.9] - Support applying surcharge fee to order payments. diff --git a/altapay.php b/altapay.php index ec6eaa3f..ea94a0cf 100755 --- a/altapay.php +++ b/altapay.php @@ -7,10 +7,10 @@ * Author URI: https://altapay.com * Text Domain: altapay * Domain Path: /languages - * Version: 3.7.9 + * Version: 3.8.0 * Name: SDM_Altapay * WC requires at least: 3.9.0 - * WC tested up to: 9.8.1 + * WC tested up to: 9.8.5 * * @package Altapay */ @@ -41,7 +41,7 @@ } if ( ! defined( 'ALTAPAY_PLUGIN_VERSION' ) ) { - define( 'ALTAPAY_PLUGIN_VERSION', '3.7.9' ); + define( 'ALTAPAY_PLUGIN_VERSION', '3.8.0' ); } // Include the autoloader, so we can dynamically include the rest of the classes. diff --git a/classes/util/UtilMethods.php b/classes/util/UtilMethods.php index 9a24a57a..03e9eae6 100755 --- a/classes/util/UtilMethods.php +++ b/classes/util/UtilMethods.php @@ -41,9 +41,7 @@ public function createOrderLines( $order, $products = array(), $wcRefund = false // generate order lines product by product foreach ( $cartItems as $key => $item ) { - $total = $item->get_total(); - $subtotal = $item->get_subtotal(); - $discount = 0; + $total = $item->get_total(); if ( $total == 0 && $isSubscription ) { $total = (float) $item->get_product()->get_regular_price(); @@ -53,14 +51,6 @@ public function createOrderLines( $order, $products = array(), $wcRefund = false continue; } - $discountPercentage = 0; - if ( $subtotal > 0 ) { - $discount = $subtotal - $total; - $discountPercentage = ( $subtotal - $total ) / $subtotal * 100; - } - // get product details for each order line - $productDetails = $this->getProductDetails( $item, $discount, $discountPercentage, ( ( $i == 0 ) ? $isSubscription : 0 ) ); - if ( $wcRefund ) { $orderLines[ $key ] = array( 'qty' => $products['itemQty'][ $key ], @@ -68,7 +58,7 @@ public function createOrderLines( $order, $products = array(), $wcRefund = false 'refund_tax' => ( $item->get_total_tax() / $item->get_quantity() ) * $products['itemQty'][ $key ], ); } else { - $orderLines[] = $productDetails['product']; + $orderLines[] = $this->getOrderLine( $item, ( ( $i == 0 ) ? $isSubscription : 0 ) ); } $i ++; @@ -85,6 +75,20 @@ public function createOrderLines( $order, $products = array(), $wcRefund = false $orderLines [] = $shippingDetails; } + if ( $order->get_total_discount() ) { + $orderLine = new OrderLine( + 'Discount', + 'discount', + 1, + -abs( $order->get_total_discount() ) + ); + $orderLine->taxAmount = 0; + $orderLine->unitCode = 'unit'; + $orderLine->setGoodsType( 'handling' ); + + $orderLines [] = $orderLine; + } + if ( ! $wcRefund ) { // Calculate compensation amount $totalCompensationAmount = $this->totalCompensationAmount( $orderLines, $order->get_total() ); @@ -98,76 +102,36 @@ public function createOrderLines( $order, $products = array(), $wcRefund = false } /** - * Returns product Details based on product type and tax configuration settings + * Returns order line for the order item * * @param object $item - * @param float $discount - * @param float $discountPercentage + * @param bool $isSubscription * - * @return array + * @return OrderLine */ - private function getProductDetails( $item, $discount, $discountPercentage, $isSubscription = false ) { - $product = $item->get_product(); - $quantity = $item->get_quantity(); - $regularPrice = (float) $product->get_regular_price(); - $salePrice = (float) $product->get_sale_price(); - $subtotal = $item->get_subtotal(); - $taxRate = $subtotal > 0 ? $item->get_subtotal_tax() / $subtotal : 0; - $productId = $product->get_sku() ? $item->get_id() . '-' . $product->get_sku() : $item->get_id(); - $productData = array(); - $productDiscount = 0; - - if ( $product->get_type() === 'variable' || $product->get_type() === 'variable-subscription' ) { - $variationId = (int) $item->get_variation_id(); - $product_data = wc_get_product( $variationId ); - $regularPrice = (float) $product_data->get_regular_price(); - $salePrice = (float) $product_data->get_sale_price() ? $product_data->get_sale_price() : 0; - } - - // calculate discount if catalogue rule is applied on order line i.e. product sale price is set - if ( $product->is_on_sale() ) { - $productDiscount = $regularPrice - $salePrice; - // convert discount amount into percentage - $discountPercentage += round( ( $productDiscount / $regularPrice ) * 100, 2 ); - } - - if ( wc_prices_include_tax() ) { - $taxRate = 1 + $taxRate; - $productPrice = round( $regularPrice / $taxRate, 2 ); - $taxAmount = $regularPrice - $productPrice; - } else { - $productPrice = $regularPrice; - $taxAmount = $productPrice * $taxRate; - } - - $productPrice = $isSubscription ? ( $productPrice + ( $taxAmount * $quantity ) - ( $discount + $productDiscount ) ) : round( $productPrice, 2 ); - $taxPercent = $productPrice > 0 ? round( ( $taxAmount / $productPrice ) * 100, 2 ) : 0; - $taxAmount = round( $taxAmount * $quantity, 2 ); - $discount = round( $discountPercentage, 2 ); + private function getOrderLine( $item, $isSubscription = false ) { + $product = $item->get_product(); + $quantity = $item->get_quantity(); // generate line date with all the calculated parameters $orderLine = new OrderLine( $item->get_name(), - $productId, + $item->get_id(), $quantity, - round( $productPrice, 2 ) + round( $item->get_subtotal() / $quantity, 2 ) ); $orderLine->productUrl = $product->get_permalink(); $orderLine->imageUrl = wp_get_attachment_url( $product->get_image_id() ); $orderLine->unitCode = $quantity > 1 ? 'units' : 'unit'; if ( ! $isSubscription ) { - $orderLine->discount = $discount; - $orderLine->taxAmount = $taxAmount; - $orderLine->taxPercent = $taxPercent; + $orderLine->taxAmount = round( $item->get_total_tax(), 2 ); } $goodsType = ( $isSubscription ) ? 'subscription_model' : 'item'; $orderLine->setGoodsType( $goodsType ); - $productData['product'] = $orderLine; - - return $productData; + return $orderLine; } /** @@ -180,16 +144,14 @@ private function getProductDetails( $item, $discount, $discountPercentage, $isSu */ public function compensationAmountOrderline( $productId, $compensationAmount ) { // Generate compensation amount orderline for payment, capture and refund requests - $orderLine = new OrderLine( + $orderLine = new OrderLine( 'Compensation', 'comp-' . $productId, 1, $compensationAmount ); - $orderLine->taxAmount = 0.00; - $orderLine->taxPercent = 0.00; - $orderLine->unitCode = 'unit'; - $orderLine->discount = 0.00; + $orderLine->taxAmount = 0.00; + $orderLine->unitCode = 'unit'; $orderLine->setGoodsType( 'handling' ); return $orderLine; @@ -233,16 +195,14 @@ private function getShippingDetails( $order, $products, $wcRefund ) { 'refund_tax' => wc_format_decimal( $totalShippingTax ), ); } else { - $orderLine = new OrderLine( + $orderLine = new OrderLine( $order->get_shipping_method(), $shippingID, 1, round( $totalShipping, 2 ) ); - $orderLine->taxAmount = round( $totalShippingTax, 2 ); - $orderLine->taxPercent = round( ( $totalShippingTax / $totalShipping ) * 100, 2 ); - $goodsType = 'shipment'; - $orderLine->setGoodsType( $goodsType ); + $orderLine->taxAmount = round( $totalShippingTax, 2 ); + $orderLine->setGoodsType( 'shipment' ); $shippingDetails[] = $orderLine; } } diff --git a/readme.txt b/readme.txt index 4ff6ef19..2ae7d892 100644 --- a/readme.txt +++ b/readme.txt @@ -3,11 +3,11 @@ Contributors: altapay_integrations Tags: AltaPay, Gateway, Payments, WooCommerce, Payment Card Industry Requires PHP: 7.4 Requires at least: 5.0 -Tested up to: 6.8 -Stable tag: 3.7.9 +Tested up to: 6.8.1 +Stable tag: 3.8.0 License: MIT WC requires at least: 3.9.0 -WC tested up to: 9.8.1 +WC tested up to: 9.8.5 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.0 = +* Add support for the new PayPal Integration. + = 3.7.9 = * Support applying surcharge fee to order payments. diff --git a/wiki.md b/wiki.md index 7302a13d..6c1b6b33 100644 --- a/wiki.md +++ b/wiki.md @@ -298,14 +298,14 @@ The new credentials can now be used as the API Username and API Password in your ## Supported versions Minimum system requirements are: -- WordPress min. 5.0 – max. 6.8 -- WooCommerce min. 3.9.0 – max. 9.8.1 +- WordPress min. 5.0 – max. 6.8.1 +- WooCommerce min. 3.9.0 – max. 9.8.5 - PHP 7.4 and above - PHP-bcmath library installed. - PHP-curl MUST be enabled. The latest tested version is: -- WordPress 6.8, WooCommerce 9.8.1 and PHP 8.2 +- WordPress 6.8.1, WooCommerce 9.8.5 and PHP 8.2 ## Troubleshooting