Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
6 changes: 3 additions & 3 deletions altapay.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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.
Expand Down
104 changes: 32 additions & 72 deletions classes/util/UtilMethods.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -53,22 +51,14 @@ 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 ],
'refund_total' => ( $item['line_total'] / $item->get_quantity() ) * $products['itemQty'][ $key ],
'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 ++;
Expand All @@ -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() );
Expand All @@ -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;
}

/**
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
}
Expand Down
9 changes: 6 additions & 3 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.

Expand Down
6 changes: 3 additions & 3 deletions wiki.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down