Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compatibility: Tax Decimal Values getting Ignored with Multi Currency : PFW-412 #1353

Merged
merged 2 commits into from
Sep 2, 2019
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
4 changes: 2 additions & 2 deletions classes/wc-gateway-braintree-angelleye.php
Original file line number Diff line number Diff line change
Expand Up @@ -1083,7 +1083,7 @@ public function angelleye_do_payment($order) {
} else {
$request_data['creditCard']['cardholderName'] = $order->get_formatted_billing_full_name();
}
$request_data['amount'] = number_format($order->get_total(), 2, '.', '');
$request_data['amount'] = AngellEYE_Gateway_Paypal::number_format($order->get_total(), $order);
$this->merchant_account_id = $this->angelleye_braintree_get_merchant_account_id($order_id);
if (isset($this->merchant_account_id) && !empty($this->merchant_account_id)) {
$request_data['merchantAccountId'] = $this->merchant_account_id;
Expand Down Expand Up @@ -2066,7 +2066,7 @@ public function process_subscription_payment($order, $amount, $payment_token = n
);
}
}
$request_data['amount'] = number_format($order->get_total(), 2, '.', '');
$request_data['amount'] = AngellEYE_Gateway_Paypal::number_format($order->get_total(), $order);
$this->merchant_account_id = $this->angelleye_braintree_get_merchant_account_id($order_id);
if (isset($this->merchant_account_id) && !empty($this->merchant_account_id)) {
$request_data['merchantAccountId'] = $this->merchant_account_id;
Expand Down
34 changes: 23 additions & 11 deletions classes/wc-gateway-calculations-angelleye.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,16 @@ public function __construct($payment_method = null, $subtotal_mismatch_behavior
if ($this->payment_method == 'paypal_pro_payflow' || $this->payment_method == 'paypal_advanced') {
$this->is_separate_discount = true;
}

}

public function cart_calculation() {
$is_zdp_currency = in_array(get_woocommerce_currency(), $this->zdp_currencies);
if ($is_zdp_currency) {
$this->decimals = 0;
} else {
$this->decimals = 2;
}
}

public function cart_calculation() {
if (!defined('WOOCOMMERCE_CHECKOUT')) {
define('WOOCOMMERCE_CHECKOUT', true);
}
Expand Down Expand Up @@ -182,6 +183,17 @@ public function cart_calculation() {

public function order_calculation($order_id) {
$order = wc_get_order($order_id);
if (is_object($order)) {
$woocommerce_currency = version_compare(WC_VERSION, '3.0', '<') ? $order->get_order_currency() : $order->get_currency();
} else {
$woocommerce_currency = get_woocommerce_currency();
}
$is_zdp_currency = in_array($woocommerce_currency, $this->zdp_currencies);
if ($is_zdp_currency) {
$this->decimals = 0;
} else {
$this->decimals = 2;
}
$this->itemamt = 0;
$this->discount_amount = 0;
$this->order_items = array();
Expand Down Expand Up @@ -238,7 +250,7 @@ public function order_calculation($order_id) {
'name' => html_entity_decode(wc_trim_string($name ? $name : __('Item', 'paypal-for-woocommerce'), 127), ENT_NOQUOTES, 'UTF-8'),
'desc' => html_entity_decode(wc_trim_string($desc, 127), ENT_NOQUOTES, 'UTF-8'),
'qty' => $values['qty'],
'amt' => AngellEYE_Gateway_Paypal::number_format($amount),
'amt' => AngellEYE_Gateway_Paypal::number_format($amount, $order),
'number' => $product_sku,
);
$this->order_items[] = $item;
Expand All @@ -255,7 +267,7 @@ public function order_calculation($order_id) {
'name' => html_entity_decode(wc_trim_string($fee_item_name ? $fee_item_name : __('Fee', 'paypal-for-woocommerce'), 127), ENT_NOQUOTES, 'UTF-8'),
'desc' => '',
'qty' => 1,
'amt' => AngellEYE_Gateway_Paypal::number_format($amount),
'amt' => AngellEYE_Gateway_Paypal::number_format($amount, $order),
'number' => ''
);
$this->order_items[] = $fee_item;
Expand All @@ -277,7 +289,7 @@ public function order_calculation($order_id) {
'desc' => 'Discount Amount',
'number' => '',
'qty' => 1,
'amt' => '-' . AngellEYE_Gateway_Paypal::number_format($this->discount_amount)
'amt' => '-' . AngellEYE_Gateway_Paypal::number_format($this->discount_amount, $order)
);
$this->order_items[] = $discLineItem;
$this->itemamt -= $this->discount_amount;
Expand All @@ -289,11 +301,11 @@ public function order_calculation($order_id) {
$this->shippingamt = 0;
}
$this->order_re_calculate($order);
$this->payment['itemamt'] = AngellEYE_Gateway_Paypal::number_format(round($this->itemamt, $this->decimals));
$this->payment['taxamt'] = AngellEYE_Gateway_Paypal::number_format(round($this->taxamt, $this->decimals));
$this->payment['shippingamt'] = AngellEYE_Gateway_Paypal::number_format(round($this->shippingamt, $this->decimals));
$this->payment['itemamt'] = AngellEYE_Gateway_Paypal::number_format(round($this->itemamt, $this->decimals), $order);
$this->payment['taxamt'] = AngellEYE_Gateway_Paypal::number_format(round($this->taxamt, $this->decimals), $order);
$this->payment['shippingamt'] = AngellEYE_Gateway_Paypal::number_format(round($this->shippingamt, $this->decimals), $order);
$this->payment['order_items'] = $this->order_items;
$this->payment['discount_amount'] = AngellEYE_Gateway_Paypal::number_format(round($this->discount_amount, $this->decimals));
$this->payment['discount_amount'] = AngellEYE_Gateway_Paypal::number_format(round($this->discount_amount, $this->decimals), $order);
if ($this->taxamt < 0 || $this->shippingamt < 0) {
$this->payment['is_calculation_mismatch'] = true;
}
Expand Down Expand Up @@ -356,7 +368,7 @@ public function order_re_calculate($order) {
'name' => 'Line Item Amount Offset',
'desc' => 'Adjust cart calculation discrepancy',
'qty' => 1,
'amt' => AngellEYE_Gateway_Paypal::number_format($cartItemAmountDifference)
'amt' => AngellEYE_Gateway_Paypal::number_format($cartItemAmountDifference, $order)
);
$this->order_items[] = $item;
$this->itemamt += round($cartItemAmountDifference, $this->decimals);
Expand Down
2 changes: 1 addition & 1 deletion classes/wc-gateway-paypal-pro-angelleye.php
Original file line number Diff line number Diff line change
Expand Up @@ -1832,7 +1832,7 @@ public function process_subscription_payment($order) {
}
$PaymentDetails['taxamt'] = $PaymentData['taxamt'];
$PaymentDetails['shippingamt'] = $PaymentData['shippingamt'];
$PaymentDetails['itemamt'] = AngellEYE_Gateway_Paypal::number_format($PaymentData['itemamt']);
$PaymentDetails['itemamt'] = AngellEYE_Gateway_Paypal::number_format($PaymentData['itemamt'], $order);
}
if( $order->get_total() != $PaymentData['shippingamt'] ) {
$PaymentDetails['shippingamt'] = $PaymentData['shippingamt'];
Expand Down
2 changes: 1 addition & 1 deletion paypal-for-woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -905,7 +905,7 @@ public static function round( $price, $order = null ) {
} else {
$woocommerce_currency = get_woocommerce_currency();
}
if ( !self::currency_has_decimals( get_woocommerce_currency() ) ) {
if ( !self::currency_has_decimals( $woocommerce_currency ) ) {
$precision = 0;
}

Expand Down