WC_Gateway_Calculation_AngellEYE

The PayPal for WooCommerce WC Gateway Calculation AngellEYE class.

Defined (1)

The class is defined in the following location(s).

/classes/wc-gateway-calculations-angelleye.php  
  1. class WC_Gateway_Calculation_AngellEYE { 
  2. public $order_total; 
  3. public $taxamt; 
  4. public $shippingamt; 
  5. public $order_items; 
  6. public $itemamt; 
  7. public $zdp_currencies = array('HUF', 'JPY', 'TWD'); 
  8. public $payment; 
  9. public $discount_amount; 
  10. public $decimals; 
  11. public $is_adjust; 
  12.  
  13. public function __construct() { 
  14. $this->is_adjust = false; 
  15. $is_zdp_currency = in_array(get_woocommerce_currency(), $this->zdp_currencies); 
  16. if ($is_zdp_currency) { 
  17. $this->decimals = 0; 
  18. } else { 
  19. $this->decimals = 2; 
  20.  
  21. public function cart_calculation() { 
  22. if (!defined('WOOCOMMERCE_CHECKOUT')) { 
  23. define('WOOCOMMERCE_CHECKOUT', true); 
  24. if (!defined('WOOCOMMERCE_CART')) { 
  25. define('WOOCOMMERCE_CART', true); 
  26. WC()->cart->calculate_totals(); 
  27. $this->payment = array(); 
  28. $this->itemamt = 0; 
  29. $this->order_items = array(); 
  30. $roundedPayPalTotal = 0; 
  31. $this->discount_amount = round(WC()->cart->get_cart_discount_total(), $this->decimals); 
  32. foreach (WC()->cart->cart_contents as $cart_item_key => $values) { 
  33. $amount = round($values['line_subtotal'] / $values['quantity'], $this->decimals); 
  34. if (version_compare(WC_VERSION, '3.0', '<')) { 
  35. $product = $values['data']; 
  36. $name = $values['data']->post->post_title; 
  37. } else { 
  38. $product = $values['data']; 
  39. $name = $product->get_name(); 
  40. $product_sku = null; 
  41. if (is_object($product)) { 
  42. $product_sku = $product->get_sku(); 
  43. $item = array( 
  44. 'name' => $name,  
  45. 'desc' => '',  
  46. 'qty' => $values['quantity'],  
  47. 'amt' => $amount,  
  48. 'number' => $product_sku 
  49. ); 
  50. $this->order_items[] = $item; 
  51. $roundedPayPalTotal += round($amount * $values['quantity'], $this->decimals); 
  52. $this->taxamt = round(WC()->cart->tax_total + WC()->cart->shipping_tax_total, $this->decimals); 
  53. $this->shippingamt = round(WC()->cart->shipping_total, $this->decimals); 
  54. $this->itemamt = round(WC()->cart->cart_contents_total, $this->decimals) + $this->discount_amount; 
  55. $this->order_total = round($this->itemamt + $this->taxamt + $this->shippingamt, $this->decimals); 
  56. if ($this->itemamt == $this->discount_amount) { 
  57. unset($this->order_items); 
  58. $this->itemamt -= $this->discount_amount; 
  59. $this->order_total -= $this->discount_amount; 
  60. } else { 
  61. if ($this->discount_amount > 0) { 
  62. $discLineItem = array( 
  63. 'name' => 'Discount',  
  64. 'desc' => 'Discount Amount',  
  65. 'qty' => 1,  
  66. 'number' => '',  
  67. 'amt' => '-' . $this->discount_amount 
  68. ); 
  69. $this->order_items[] = $discLineItem; 
  70. $this->itemamt -= $this->discount_amount; 
  71. $this->order_total -= $this->discount_amount; 
  72. if (!is_numeric($this->shippingamt)) { 
  73. $this->shippingamt = 0; 
  74. $this->cart_re_calculate(); 
  75. $this->payment['itemamt'] = round($this->itemamt, $this->decimals); 
  76. $this->payment['taxamt'] = round($this->taxamt, $this->decimals); 
  77. $this->payment['shippingamt'] = AngellEYE_Gateway_Paypal::number_format(round($this->shippingamt, $this->decimals)); 
  78. $this->payment['order_items'] = $this->order_items; 
  79. $this->payment['discount_amount'] = round($this->discount_amount, $this->decimals); 
  80. return $this->payment; 
  81.  
  82. public function order_calculation($order_id) { 
  83. $this->payment = array(); 
  84. $order = wc_get_order($order_id); 
  85. $this->itemamt = 0; 
  86. $this->discount_amount = 0; 
  87. $this->order_items = array(); 
  88. $roundedPayPalTotal = 0; 
  89. $this->discount_amount = round($order->get_total_discount(), $this->decimals); 
  90. foreach ($order->get_items() as $cart_item_key => $values) { 
  91. $product = $order->get_product_from_item($values); 
  92. $product_sku = null; 
  93. if (is_object($product)) { 
  94. $product_sku = $product->get_sku(); 
  95. $amount = round($values['line_subtotal'] / $values['qty'], $this->decimals); 
  96. $item = array( 
  97. 'name' => $values['name'],  
  98. 'desc' => '',  
  99. 'qty' => $values['qty'],  
  100. 'amt' => $amount,  
  101. 'number' => $product_sku,  
  102. ); 
  103. $this->order_items[] = $item; 
  104. $roundedPayPalTotal += round($amount * $values['qty'], $this->decimals); 
  105. $this->taxamt = round($order->get_total_tax(), $this->decimals); 
  106. $this->shippingamt = round(( version_compare(WC_VERSION, '3.0', '<') ? $order->get_total_shipping() : $order->get_shipping_total()), $this->decimals); 
  107. $this->itemamt = round($order->get_subtotal(), $this->decimals); 
  108. $this->order_total = round($this->itemamt + $this->taxamt + $this->shippingamt, $this->decimals); 
  109. if ($this->itemamt == $this->discount_amount) { 
  110. unset($this->order_items); 
  111. $this->itemamt -= $this->discount_amount; 
  112. $this->order_total -= $this->discount_amount; 
  113. } else { 
  114. if ($this->discount_amount > 0) { 
  115. $discLineItem = array( 
  116. 'name' => 'Discount',  
  117. 'desc' => 'Discount Amount',  
  118. 'number' => '',  
  119. 'qty' => 1,  
  120. 'amt' => '-' . $this->discount_amount 
  121. ); 
  122. $this->order_items[] = $discLineItem; 
  123. $this->itemamt -= $this->discount_amount; 
  124. $this->order_total -= $this->discount_amount; 
  125. if (!is_numeric($this->shippingamt)) { 
  126. $this->shippingamt = 0; 
  127. $this->order_re_calculate($order); 
  128. $this->payment['itemamt'] = round($this->itemamt, $this->decimals); 
  129. $this->payment['taxamt'] = round($this->taxamt, $this->decimals); 
  130. $this->payment['shippingamt'] = round($this->shippingamt, $this->decimals); 
  131. $this->payment['order_items'] = $this->order_items; 
  132. $this->payment['discount_amount'] = round($this->discount_amount, $this->decimals); 
  133. return $this->payment; 
  134.  
  135. public function cart_re_calculate() { 
  136. $temp_roundedPayPalTotal = 0; 
  137. if (!empty($this->order_items) && is_array($this->order_items)) { 
  138. foreach ($this->order_items as $key => $values) { 
  139. $temp_roundedPayPalTotal += round($values['amt'] * $values['qty'], $this->decimals); 
  140. $this->itemamt = round($temp_roundedPayPalTotal, $this->decimals); 
  141. if (round(WC()->cart->total, $this->decimals) != round($this->itemamt + $this->taxamt + $this->shippingamt, $this->decimals)) { 
  142. $cartItemAmountDifference = round(WC()->cart->total, $this->decimals) - round($this->itemamt + $this->taxamt + $this->shippingamt, $this->decimals); 
  143. if ($this->shippingamt > 0) { 
  144. $this->shippingamt += round($cartItemAmountDifference, $this->decimals); 
  145. } elseif ($this->taxamt > 0) { 
  146. $this->taxamt += round($cartItemAmountDifference, $this->decimals); 
  147. } else { 
  148. if (count($this->order_items) == 1 && (!empty($this->order_items[0]['qty']) && $this->order_items[0]['qty'] > 1 )) { 
  149. unset($this->order_items); 
  150. $this->order_total = WC()->cart->total; 
  151. $this->itemamt = WC()->cart->total; 
  152. } else { 
  153. foreach ($this->order_items as $key => $value) { 
  154. if ($value['qty'] == 1) { 
  155. $this->order_items[$key]['amt'] = $this->order_items[$key]['amt'] + round($cartItemAmountDifference, $this->decimals); 
  156. $this->order_total += round($cartItemAmountDifference, $this->decimals); 
  157. $this->itemamt += round($cartItemAmountDifference, $this->decimals); 
  158. $this->is_adjust = true; 
  159. if ($this->is_adjust == false ) { 
  160. unset($this->order_items); 
  161. $this->order_total = WC()->cart->total; 
  162. $this->itemamt = WC()->cart->total; 
  163.  
  164. public function order_re_calculate($order) { 
  165. $temp_roundedPayPalTotal = 0; 
  166. if (!empty($this->order_items) && is_array($this->order_items)) { 
  167. foreach ($this->order_items as $key => $values) { 
  168. $temp_roundedPayPalTotal += round($values['amt'] * $values['qty'], $this->decimals); 
  169. $this->itemamt = $temp_roundedPayPalTotal; 
  170. if (round($order->get_total(), $this->decimals) != round($this->itemamt + $this->taxamt + $this->shippingamt, $this->decimals)) { 
  171. $cartItemAmountDifference = round($order->get_total(), $this->decimals) - round($this->itemamt + $this->taxamt + $this->shippingamt, $this->decimals); 
  172. if ($this->shippingamt > 0) { 
  173. $this->shippingamt += round($cartItemAmountDifference, $this->decimals); 
  174. } elseif ($this->taxamt > 0) { 
  175. $this->taxamt += round($cartItemAmountDifference, $this->decimals); 
  176. } else { 
  177. if (count($this->order_items) == 1 && (!empty($this->order_items[0]['qty']) && $this->order_items[0]['qty'] > 1 )) { 
  178. unset($this->order_items); 
  179. $this->order_total = WC()->cart->total; 
  180. $this->itemamt = WC()->cart->total; 
  181. } else { 
  182. foreach ($this->order_items as $key => $value) { 
  183. if ($value['qty'] == 1) { 
  184. $this->order_items[$key]['amt'] = $this->order_items[$key]['amt'] + round($cartItemAmountDifference, $this->decimals); 
  185. $this->order_total += round($cartItemAmountDifference, $this->decimals); 
  186. $this->itemamt += round($cartItemAmountDifference, $this->decimals); 
  187. $this->is_adjust = true; 
  188. if ($this->is_adjust == false) { 
  189. unset($this->order_items); 
  190. $this->order_total = WC()->cart->total; 
  191. $this->itemamt = WC()->cart->total; 
  192.