AngellEYE_Utility

The PayPal for WooCommerce AngellEYE Utility class.

Defined (1)

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

/angelleye-includes/angelleye-utility.php  
  1. class AngellEYE_Utility { 
  2.  
  3. public $plugin_name; 
  4. public $version; 
  5. public $paypal; 
  6. public $testmode; 
  7. public $api_username; 
  8. public $api_password; 
  9. public $api_signature; 
  10. public $ec_debug; 
  11. public $payment_method; 
  12. public $error_email_notify; 
  13. public $angelleye_woocommerce_order_actions; 
  14. public $total_Order; 
  15. public $total_DoVoid; 
  16. public $total_DoCapture; 
  17. public $total_Pending_DoAuthorization; 
  18. public $total_Completed_DoAuthorization; 
  19. public $total_DoReauthorization; 
  20. public $max_authorize_amount; 
  21. public $remain_authorize_amount; 
  22.  
  23. public function __construct($plugin_name, $version) { 
  24. $this->plugin_name = $plugin_name; 
  25. $this->version = $version; 
  26. $this->load_dependencies(); 
  27.  
  28. public function add_ec_angelleye_paypal_php_library() { 
  29. if (!class_exists('WC_Payment_Gateway')) { 
  30. return false; 
  31. if (!class_exists('Angelleye_PayPal')) { 
  32. require_once( PAYPAL_FOR_WOOCOMMERCE_PLUGIN_DIR . '/classes/lib/angelleye/paypal-php-library/includes/paypal.class.php' ); 
  33. if( empty($this->payment_method) || $this->payment_method == false) { 
  34. $this->angelleye_set_payment_method(); 
  35. if( empty($this->payment_method) || $this->payment_method == false) { 
  36. return false; 
  37. if ($this->payment_method == 'paypal_express') { 
  38. $gateway_obj = new WC_Gateway_PayPal_Express_AngellEYE(); 
  39. $this->testmode = 'yes' === $gateway_obj->get_option('testmode', 'yes'); 
  40. } else if($this->payment_method == 'paypal_pro') { 
  41. $gateway_obj = new WC_Gateway_PayPal_Pro_AngellEYE(); 
  42. $this->testmode = 'yes' === $gateway_obj->get_option('testmode', 'no'); 
  43. } else { 
  44. return false; 
  45. if ($this->testmode == false) { 
  46. $this->testmode = AngellEYE_Utility::angelleye_paypal_for_woocommerce_is_set_sandbox_product(); 
  47. if ($this->testmode == true) { 
  48. $this->api_username = $gateway_obj->get_option('sandbox_api_username'); 
  49. $this->api_password = $gateway_obj->get_option('sandbox_api_password'); 
  50. $this->api_signature = $gateway_obj->get_option('sandbox_api_signature'); 
  51. } else { 
  52. $this->api_username = $gateway_obj->get_option('api_username'); 
  53. $this->api_password = $gateway_obj->get_option('api_password'); 
  54. $this->api_signature = $gateway_obj->get_option('api_signature'); 
  55. $this->error_email_notify = $gateway_obj->get_option('error_email_notify'); 
  56. $this->ec_debug = $gateway_obj->get_option('debug'); 
  57. $PayPalConfig = array( 
  58. 'Sandbox' => $this->testmode,  
  59. 'APIUsername' => $this->api_username,  
  60. 'APIPassword' => $this->api_password,  
  61. 'APISignature' => $this->api_signature 
  62. ); 
  63. $this->paypal = new Angelleye_PayPal($PayPalConfig); 
  64.  
  65. public function load_dependencies() { 
  66. add_action('init', array($this, 'paypal_for_woocommerce_paypal_transaction_history'), 5); 
  67. if (is_admin() && !defined('DOING_AJAX')) { 
  68. add_action('add_meta_boxes', array($this, 'angelleye_paypal_for_woocommerce_order_action_meta_box'), 10, 2); 
  69. $hook_name = ''; 
  70. $payment_action_with_gateway = array('paypal_express' => array('DoAuthorization', 'DoCapture', 'DoVoid', 'DoReauthorization'), 'paypal_pro' => array('DoAuthorization', 'DoCapture', 'DoVoid')); 
  71. foreach ($payment_action_with_gateway as $payment_method_name => $payment_action_name) { 
  72. foreach ($payment_action_name as $action_name) { 
  73. $hook_name = 'wc_' . $payment_method_name . '_' . strtolower($action_name); 
  74. add_action('woocommerce_order_action_' . $hook_name, array($this, 'angelleye_' . $hook_name)); 
  75. add_filter('woocommerce_payment_gateway_supports', array($this, 'angelleye_woocommerce_payment_gateway_supports'), 10, 3); 
  76.  
  77. add_action( 'woocommerce_process_shop_order_meta', array($this, 'save' ), 50, 2); 
  78. add_action( 'woocommerce_admin_order_data_after_shipping_address', array($this, 'angelleye_paypal_for_woocommerce_billing_agreement_details'), 10, 1); 
  79.  
  80. public function angelleye_woocommerce_order_actions($order_actions = array()) { 
  81. global $post; 
  82. $order_id = $post->ID; 
  83. if (!is_object($order_id)) { 
  84. $order = wc_get_order($order_id); 
  85. $paypal_payment_action = array(); 
  86. $old_wc = version_compare(WC_VERSION, '3.0', '<'); 
  87. $this->payment_method = $old_wc ? get_post_meta($order_id, '_payment_method', true) : get_post_meta($order->get_id(), '_payment_method', true); 
  88. $payment_action = $old_wc ? get_post_meta($order_id, '_payment_action', true) : get_post_meta($order->get_id(), '_payment_action', true); 
  89. if ((isset($this->payment_method) && !empty($this->payment_method)) && (isset($payment_action) && !empty($payment_action)) && !$this->has_authorization_expired($post->ID)) { 
  90. switch ($this->payment_method) { 
  91. case 'paypal_express': { 
  92. $paypal_payment_action = array(); 
  93. $this->total_Order = self::get_total('Order', 'Pending', $order_id); 
  94. $this->total_DoVoid = self::get_total('DoVoid', '', $order_id); 
  95. $this->total_DoCapture = self::get_total('DoCapture', 'Completed', $order_id); 
  96. $this->total_Pending_DoAuthorization = self::get_total('DoAuthorization', 'Pending', $order_id); 
  97. $this->total_Completed_DoAuthorization = self::get_total('DoAuthorization', 'Completed', $order_id); 
  98. $this->total_DoReauthorization = self::get_total('DoReauthorization', '', $order_id); 
  99. switch ($payment_action) { 
  100. case ($payment_action == 'Order'): 
  101. $this->angelleye_max_authorize_amount($order_id); 
  102. $this->angelleye_remain_authorize_amount(); 
  103. if ($this->max_authorize_amount == $this->total_DoVoid || $this->max_authorize_amount == $this->total_DoCapture) { 
  104. return $paypal_payment_action; 
  105. } else { 
  106. $paypal_payment_action = array('DoCapture' => 'Capture Authorization', 'DoVoid' => 'Void Authorization', 'DoAuthorization' => 'Authorization'); 
  107. if ($this->total_Completed_DoAuthorization == $this->total_Pending_DoAuthorization || $this->total_Pending_DoAuthorization == 0 || $this->total_Pending_DoAuthorization == $this->total_DoCapture || $this->total_DoCapture == $order->get_total() - $order->get_total_refunded()) { 
  108. unset($paypal_payment_action['DoCapture']); 
  109. if ($this->total_Pending_DoAuthorization == 0 && $this->total_Completed_DoAuthorization > 0 || $this->total_Pending_DoAuthorization == $this->total_DoCapture) { 
  110. unset($paypal_payment_action['DoVoid']); 
  111. if ($this->max_authorize_amount == self::round($this->total_Pending_DoAuthorization + $this->total_Completed_DoAuthorization)) { 
  112. unset($paypal_payment_action['DoAuthorization']); 
  113. return $paypal_payment_action; 
  114. break; 
  115. case ($payment_action == 'Authorization'): 
  116. $paypal_payment_action = array('DoCapture' => 'Capture Authorization', 'DoReauthorization' => 'Authorization', 'DoVoid' => 'Void Authorization'); 
  117. $transaction_id = $old_wc ? get_post_meta($order_id, '_first_transaction_id', true) : get_post_meta($order->get_id(), '_first_transaction_id', true); 
  118. if (!$this->has_authorization_inside_honor_period($transaction_id)) { 
  119. unset($paypal_payment_action['DoReauthorization']); 
  120. if (!is_object($order_id)) { 
  121. $order = wc_get_order($order_id); 
  122. if ($order->get_total() == $this->total_DoVoid || $this->total_Completed_DoAuthorization == $order->get_total() || $order->get_total() == $this->total_DoCapture || $this->total_DoCapture == $order->get_total() - $order->get_total_refunded()) { 
  123. unset($paypal_payment_action['DoCapture']); 
  124. unset($paypal_payment_action['DoVoid']); 
  125. return $paypal_payment_action; 
  126. case 'paypal_pro': { 
  127. switch ($payment_action) { 
  128. case ($payment_action == 'Authorization'): 
  129. $this->total_DoVoid = self::get_total('DoVoid', '', $order_id); 
  130. $this->total_DoCapture = self::get_total('DoCapture', 'Completed', $order_id); 
  131. if ($payment_action == 'Order') { 
  132. $Authorization = 'DoAuthorization'; 
  133. } else { 
  134. $Authorization = 'authorization'; 
  135. $this->total_Pending_DoAuthorization = self::get_total($Authorization, 'Pending', $order_id); 
  136. $this->total_Completed_DoAuthorization = self::get_total($Authorization, 'Completed', $order_id); 
  137. $this->total_DoReauthorization = self::get_total('DoReauthorization', '', $order_id); 
  138. $paypal_payment_action = array('DoCapture' => 'Capture Authorization', 'DoReauthorization' => 'Reauthorization', 'DoVoid' => 'Void Authorization'); 
  139. $this->angelleye_max_authorize_amount($order_id); 
  140. $this->angelleye_remain_authorize_amount(); 
  141. $transaction_id = $old_wc ? get_post_meta($order_id, '_first_transaction_id', true) : get_post_meta($order->get_id(), '_first_transaction_id', true); 
  142. if (!$this->has_authorization_inside_honor_period($transaction_id)) { 
  143. unset($paypal_payment_action['DoReauthorization']); 
  144. if (!is_object($order_id)) { 
  145. $order = wc_get_order($order_id); 
  146. if ($order->get_total() == $this->total_DoVoid || $this->total_Completed_DoAuthorization == $order->get_total() - $order->get_total_refunded() || $this->total_DoCapture == $order->get_total() - $order->get_total_refunded()) { 
  147. unset($paypal_payment_action['DoCapture']); 
  148. unset($paypal_payment_action['DoVoid']); 
  149. return $paypal_payment_action; 
  150. if (isset($paypal_payment_action) && !empty($paypal_payment_action)) { 
  151. foreach ($paypal_payment_action as $key => $value) { 
  152. $order_actions['wc_' . $this->payment_method . '_' . strtolower($value)] = _x($value, $value, $this->plugin_name); 
  153. return $order_actions; 
  154.  
  155. /** 
  156. * $_transaction_id, $payment_action, $gateway_name 
  157. * @param type $order_id 
  158. */ 
  159. public static function angelleye_add_order_meta($order_id, $payment_order_meta) { 
  160. $old_wc = version_compare(WC_VERSION, '3.0', '<'); 
  161. $order = wc_get_order($order_id); 
  162. foreach ($payment_order_meta as $key => $value) { 
  163. if ($old_wc) { 
  164. update_post_meta($order_id, $key, $value); 
  165. } else { 
  166. update_post_meta( $order->get_id(), $key, $value ); 
  167. if ($old_wc) { 
  168. update_post_meta($order_id, '_trans_date', current_time('mysql')); 
  169. } else { 
  170. update_post_meta( $order->get_id(), '_trans_date', current_time('mysql') ); 
  171.  
  172. /** 
  173. * @param type $order_id 
  174. * @return type 
  175. */ 
  176. public function has_authorization_expired($order_id) { 
  177. $old_wc = version_compare(WC_VERSION, '3.0', '<'); 
  178. $order = wc_get_order($order_id); 
  179. $transaction_time = $old_wc ? get_post_meta($order_id, '_trans_date', true) : get_post_meta($order->get_id(), '_trans_date', true); 
  180. return floor(( time() - strtotime($transaction_time) ) / 3600) > 720; 
  181.  
  182. public function has_authorization_inside_honor_period($transaction_id) { 
  183. $transaction_post_is = $this->get_post_by_title($transaction_id); 
  184. $transaction_time = get_post_meta($transaction_post_is, '_trans_date', true); 
  185. return floor(( time() - strtotime($transaction_time) ) / 3600) > 72; 
  186.  
  187. /** 
  188. * @param type $order 
  189. */ 
  190. public function angelleye_wc_paypal_express_docapture($order) { 
  191. if (!is_object($order)) { 
  192. $order = wc_get_order($order); 
  193. // ensure the authorization is still valid for capture 
  194. $order_id = version_compare( WC_VERSION, '3.0', '<' ) ? $order->id : $order->get_id(); 
  195. if ($this->has_authorization_expired($order_id)) { 
  196. return; 
  197. if (isset($_POST['angelleye_paypal_capture_transaction_dropdown']) && !empty($_POST['angelleye_paypal_capture_transaction_dropdown'])) { 
  198. $transaction_id = $_POST['angelleye_paypal_capture_transaction_dropdown']; 
  199. } else { 
  200. $old_wc = version_compare(WC_VERSION, '3.0', '<'); 
  201. $transaction_id = $old_wc ? get_post_meta($order_id, '_transaction_id', true) : get_post_meta($order->get_id(), '_transaction_id', true); 
  202. remove_action('woocommerce_order_action_wc_paypal_express_docapture', array($this, 'angelleye_wc_paypal_express_docapture')); 
  203. remove_action('woocommerce_process_shop_order_meta', 'WC_Meta_Box_Order_Data::save', 40, 2); 
  204. $this->pfw_do_capture($order, $transaction_id, $order->get_total()); 
  205.  
  206. /** 
  207. * @param type $order 
  208. */ 
  209. public function angelleye_wc_paypal_pro_docapture($order) { 
  210. if (!is_object($order)) { 
  211. $order = wc_get_order($order); 
  212. // ensure the authorization is still valid for capture 
  213. $order_id = version_compare( WC_VERSION, '3.0', '<' ) ? $order->id : $order->get_id(); 
  214. if ($this->has_authorization_expired($order_id)) { 
  215. return; 
  216. $old_wc = version_compare(WC_VERSION, '3.0', '<'); 
  217. $order_id = version_compare( WC_VERSION, '3.0', '<' ) ? $order->id : $order->get_id(); 
  218. $transaction_id = $old_wc ? get_post_meta($order_id, '_transaction_id', true) : get_post_meta($order->get_id(), '_transaction_id', true); 
  219. remove_action('woocommerce_order_action_wc_paypal_pro_docapture', array($this, 'angelleye_wc_paypal_pro_docapture')); 
  220. remove_action('woocommerce_process_shop_order_meta', 'WC_Meta_Box_Order_Data::save', 40, 2); 
  221. $this->pfw_do_capture($order, $transaction_id, $order->get_total()); 
  222.  
  223. public function pfw_do_capture($order, $transaction_id = null, $capture_total = null) { 
  224. $this->add_ec_angelleye_paypal_php_library(); 
  225. $this->ec_add_log('DoCapture API call'); 
  226. $order_id = version_compare( WC_VERSION, '3.0', '<' ) ? $order->id : $order->get_id(); 
  227. if($capture_total == null) 
  228. $AMT = $this->get_amount_by_transaction_id($transaction_id); 
  229. else 
  230. $AMT = $capture_total; 
  231.  
  232. $AMT = self::round($AMT - $order->get_total_refunded()); 
  233. $DataArray = array( 
  234. 'AUTHORIZATIONID' => $transaction_id,  
  235. 'AMT' => $AMT,  
  236. 'CURRENCYCODE' => version_compare(WC_VERSION, '3.0', '<') ? $order->get_order_currency() : $order->get_currency(),  
  237. 'COMPLETETYPE' => 'NotComplete',  
  238. ); 
  239. $PayPalRequest = array( 
  240. 'DCFields' => $DataArray 
  241. ); 
  242. $do_capture_result = $this->paypal->DoCapture($PayPalRequest); 
  243. $this->angelleye_write_request_response_api_log($do_capture_result); 
  244. $ack = strtoupper($do_capture_result["ACK"]); 
  245. if ($ack == "SUCCESS" || $ack == "SUCCESSWITHWARNING") { 
  246. $order->add_order_note(__('PayPal DoCapture', 'paypal-for-woocommerce') . 
  247. ' ( Response Code: ' . $do_capture_result["ACK"] . ", " . 
  248. ' DoCapture TransactionID: ' . $do_capture_result['TRANSACTIONID'] . ' )' . 
  249. ' Authorization ID: ' . $do_capture_result['AUTHORIZATIONID'] . ' )' 
  250. ); 
  251. $order->add_order_note('Payment Action: DoCapture'); 
  252. $payerstatus_note = __('Payment Status: ', 'paypal-for-woocommerce'); 
  253. $payerstatus_note .= ucfirst($do_capture_result['PAYMENTSTATUS']); 
  254. $order->add_order_note($payerstatus_note); 
  255. if ($do_capture_result['PAYMENTSTATUS'] == 'Completed') { 
  256. $AUTHORIZATIONID = $this->get_post_by_title($transaction_id); 
  257. if ($AUTHORIZATIONID != null) { 
  258. update_post_meta($AUTHORIZATIONID, 'PAYMENTSTATUS', $do_capture_result['PAYMENTSTATUS']); 
  259. $payment_order_meta = array('_transaction_id' => $do_capture_result['TRANSACTIONID']); 
  260. self::angelleye_add_order_meta($order_id, $payment_order_meta); 
  261. self::angelleye_paypal_for_woocommerce_add_paypal_transaction($do_capture_result, $order, 'DoCapture'); 
  262. $this->angelleye_paypal_for_woocommerce_order_status_handler($order); 
  263. } else { 
  264. $ErrorCode = urldecode($do_capture_result["L_ERRORCODE0"]); 
  265. $ErrorShortMsg = urldecode($do_capture_result["L_SHORTMESSAGE0"]); 
  266. $ErrorLongMsg = urldecode($do_capture_result["L_LONGMESSAGE0"]); 
  267. $ErrorSeverityCode = urldecode($do_capture_result["L_SEVERITYCODE0"]); 
  268. $this->ec_add_log(__('PayPal DoCapture API call failed. ', 'paypal-for-woocommerce')); 
  269. $this->ec_add_log(__('Detailed Error Message: ', 'paypal-for-woocommerce') . $ErrorLongMsg); 
  270. $this->ec_add_log(__('Short Error Message: ', 'paypal-for-woocommerce') . $ErrorShortMsg); 
  271. $this->ec_add_log(__('Error Code: ', 'paypal-for-woocommerce') . $ErrorCode); 
  272. $this->ec_add_log(__('Error Severity Code: ', 'paypal-for-woocommerce') . $ErrorSeverityCode); 
  273. $order->add_order_note(__('PayPal DoCapture API call failed. ', 'paypal-for-woocommerce') . 
  274. ' ( Detailed Error Message: ' . $ErrorLongMsg . ", " . 
  275. ' Short Error Message: ' . $ErrorShortMsg . ' )' . 
  276. ' Error Code: ' . $ErrorCode . ' )' . 
  277. ' Error Severity Code: ' . $ErrorSeverityCode . ' )' 
  278. ); 
  279. $this->call_error_email_notifications($subject = 'DoCapture failed', $method_name = 'DoCapture', $resArray = $do_capture_result); 
  280.  
  281. /** 
  282. * @param type $order 
  283. */ 
  284. public function angelleye_wc_paypal_express_dovoid($order) { 
  285. $this->add_ec_angelleye_paypal_php_library(); 
  286. if (!is_object($order)) { 
  287. $order = wc_get_order($order); 
  288. $order_id = version_compare( WC_VERSION, '3.0', '<' ) ? $order->id : $order->get_id(); 
  289. // ensure the authorization is still valid for capture 
  290. if ($this->has_authorization_expired($order_id)) { 
  291. return; 
  292. remove_action('woocommerce_order_action_wc_paypal_express_dovoid', array($this, 'angelleye_wc_paypal_express_dovoid')); 
  293. remove_action('woocommerce_process_shop_order_meta', 'WC_Meta_Box_Order_Data::save', 40, 2); 
  294. $this->call_do_void($order); 
  295.  
  296. /** 
  297. * @param type $order 
  298. */ 
  299. public function angelleye_wc_paypal_pro_dovoid($order) { 
  300. $this->add_ec_angelleye_paypal_php_library(); 
  301. if (!is_object($order)) { 
  302. $order = wc_get_order($order); 
  303. // ensure the authorization is still valid for capture 
  304. $order_id = version_compare( WC_VERSION, '3.0', '<' ) ? $order->id : $order->get_id(); 
  305. if ($this->has_authorization_expired($order_id)) { 
  306. return; 
  307. remove_action('woocommerce_order_action_wc_paypal_express_dovoid', array($this, 'angelleye_wc_paypal_pro_dovoid')); 
  308. remove_action('woocommerce_process_shop_order_meta', 'WC_Meta_Box_Order_Data::save', 40, 2); 
  309. $this->call_do_void($order); 
  310.  
  311. public function call_do_void($order) { 
  312. $this->add_ec_angelleye_paypal_php_library(); 
  313. $this->ec_add_log('DoVoid API call'); 
  314. $order_id = version_compare( WC_VERSION, '3.0', '<' ) ? $order->id : $order->get_id(); 
  315. if (isset($_POST['angelleye_paypal_dovoid_transaction_dropdown']) && !empty($_POST['angelleye_paypal_dovoid_transaction_dropdown'])) { 
  316. $transaction_id = $_POST['angelleye_paypal_dovoid_transaction_dropdown']; 
  317. } else { 
  318. $old_wc = version_compare(WC_VERSION, '3.0', '<'); 
  319. $transaction_id = $old_wc ? get_post_meta($order_id, '_first_transaction_id', true) : get_post_meta($order->get_id(), '_first_transaction_id', true); 
  320. if (isset($transaction_id) && !empty($transaction_id)) { 
  321. $DVFields = array( 
  322. 'authorizationid' => $transaction_id,  
  323. 'note' => '',  
  324. 'msgsubid' => '' 
  325. ); 
  326. $PayPalRequestData = array('DVFields' => $DVFields); 
  327. $do_void_result = $this->paypal->DoVoid($PayPalRequestData); 
  328. $this->angelleye_write_request_response_api_log($do_void_result); 
  329. $ack = strtoupper($do_void_result["ACK"]); 
  330. if ($ack == "SUCCESS" || $ack == "SUCCESSWITHWARNING") { 
  331. $order->add_order_note(__('PayPal DoVoid', 'paypal-for-woocommerce') . 
  332. ' ( Response Code: ' . $do_void_result["ACK"] . ", " . 
  333. ' DoVoid AUTHORIZATIONID: ' . $do_void_result['AUTHORIZATIONID'] . ' )' 
  334. ); 
  335. $this->angelleye_get_transactionDetails($do_void_result['AUTHORIZATIONID']); 
  336. $payment_order_meta = array('_transaction_id' => $do_void_result['AUTHORIZATIONID']); 
  337. self::angelleye_add_order_meta($order_id, $payment_order_meta); 
  338. self::angelleye_paypal_for_woocommerce_add_paypal_transaction($do_void_result, $order, 'DoVoid'); 
  339. $this->angelleye_paypal_for_woocommerce_order_status_handler($order); 
  340. } else { 
  341. $ErrorCode = urldecode($do_void_result["L_ERRORCODE0"]); 
  342. $ErrorShortMsg = urldecode($do_void_result["L_SHORTMESSAGE0"]); 
  343. $ErrorLongMsg = urldecode($do_void_result["L_LONGMESSAGE0"]); 
  344. $ErrorSeverityCode = urldecode($do_void_result["L_SEVERITYCODE0"]); 
  345. $this->ec_add_log(__('PayPal DoVoid API call failed. ', 'paypal-for-woocommerce')); 
  346. $this->ec_add_log(__('Detailed Error Message: ', 'paypal-for-woocommerce') . $ErrorLongMsg); 
  347. $this->ec_add_log(__('Short Error Message: ', 'paypal-for-woocommerce') . $ErrorShortMsg); 
  348. $this->ec_add_log(__('Error Code: ', 'paypal-for-woocommerce') . $ErrorCode); 
  349. $this->ec_add_log(__('Error Severity Code: ', 'paypal-for-woocommerce') . $ErrorSeverityCode); 
  350. $order->add_order_note(__('PayPal DoVoid API call failed. ', 'paypal-for-woocommerce') . 
  351. ' ( Detailed Error Message: ' . $ErrorLongMsg . ", " . 
  352. ' Short Error Message: ' . $ErrorShortMsg . ' )' . 
  353. ' Error Code: ' . $ErrorCode . ' )' . 
  354. ' Error Severity Code: ' . $ErrorSeverityCode . ' )' 
  355. ); 
  356. $this->call_error_email_notifications($subject = 'DoVoid failed', $method_name = 'DoVoid', $resArray = $do_void_result); 
  357.  
  358. /** 
  359. * @param type $order 
  360. */ 
  361. public function angelleye_wc_paypal_express_doreauthorization($order) { 
  362. if (!is_object($order)) { 
  363. $order = wc_get_order($order); 
  364. $old_wc = version_compare(WC_VERSION, '3.0', '<'); 
  365. $order_id = version_compare( WC_VERSION, '3.0', '<' ) ? $order->id : $order->get_id(); 
  366. $this->payment_method = $old_wc ? get_post_meta($order_id, '_payment_method', true) : get_post_meta($order->get_id(), '_payment_method', true); 
  367. remove_action('woocommerce_order_action_wc_paypal_express_doreauthorization', array($this, 'angelleye_wc_paypal_express_doreauthorization')); 
  368. remove_action('woocommerce_process_shop_order_meta', 'WC_Meta_Box_Order_Data::save', 40, 2); 
  369. $this->call_do_reauthorization($order); 
  370.  
  371. public function call_do_reauthorization($order) { 
  372. $this->add_ec_angelleye_paypal_php_library(); 
  373. $this->ec_add_log('DoReauthorization API call'); 
  374. $order_id = version_compare( WC_VERSION, '3.0', '<' ) ? $order->id : $order->get_id(); 
  375. if (isset($_POST['angelleye_paypal_doreauthorization_transaction_dropdown']) && !empty($_POST['angelleye_paypal_doreauthorization_transaction_dropdown'])) { 
  376. $transaction_id = $_POST['angelleye_paypal_doreauthorization_transaction_dropdown']; 
  377. } else { 
  378. $old_wc = version_compare(WC_VERSION, '3.0', '<'); 
  379. $transaction_id = $old_wc ? get_post_meta($order_id, '_first_transaction_id', true) : get_post_meta($order->get_id(), '_first_transaction_id', true); 
  380. $AMT = $this->get_amount_by_transaction_id($transaction_id); 
  381. if (isset($transaction_id) && !empty($transaction_id)) { 
  382. $DRFields = array( 
  383. 'authorizationid' => $transaction_id, // Required. The value of a previously authorized transaction ID returned by PayPal. 
  384. 'amt' => self::number_format($AMT), // Required. Must have two decimal places. Decimal separator must be a period (.) and optional thousands separator must be a comma (, ) 
  385. 'currencycode' => version_compare(WC_VERSION, '3.0', '<') ? $order->get_order_currency() : $order->get_currency(), // Three-character currency code. 
  386. 'msgsubid' => '' // A message ID used for idempotence to uniquely identify a message. 
  387. ); 
  388. $PayPalRequestData = array('DRFields' => $DRFields); 
  389. $do_reauthorization_result = $this->paypal->DoReauthorization($PayPalRequestData); 
  390. $this->angelleye_write_request_response_api_log($do_reauthorization_result); 
  391. $ack = strtoupper($do_reauthorization_result["ACK"]); 
  392. if ($ack == "SUCCESS" || $ack == "SUCCESSWITHWARNING") { 
  393. $order->add_order_note(__('PayPal DoReauthorization', 'paypal-for-woocommerce') . 
  394. ' ( Response Code: ' . $do_reauthorization_result["ACK"] . ", " . 
  395. ' DoReauthorization AUTHORIZATIONID: ' . $do_reauthorization_result['AUTHORIZATIONID'] . ' )' 
  396. ); 
  397. $payment_order_meta = array('_transaction_id' => $do_reauthorization_result['AUTHORIZATIONID']); 
  398. self::angelleye_add_order_meta($order_id, $payment_order_meta); 
  399. self::angelleye_paypal_for_woocommerce_add_paypal_transaction($do_reauthorization_result, $order, 'DoReauthorization'); 
  400. } else { 
  401. $ErrorCode = urldecode($do_reauthorization_result["L_ERRORCODE0"]); 
  402. $ErrorShortMsg = urldecode($do_reauthorization_result["L_SHORTMESSAGE0"]); 
  403. $ErrorLongMsg = urldecode($do_reauthorization_result["L_LONGMESSAGE0"]); 
  404. $ErrorSeverityCode = urldecode($do_reauthorization_result["L_SEVERITYCODE0"]); 
  405. $this->ec_add_log(__('PayPal DoReauthorization API call failed. ', 'paypal-for-woocommerce')); 
  406. $this->ec_add_log(__('Detailed Error Message: ', 'paypal-for-woocommerce') . $ErrorLongMsg); 
  407. $this->ec_add_log(__('Short Error Message: ', 'paypal-for-woocommerce') . $ErrorShortMsg); 
  408. $this->ec_add_log(__('Error Code: ', 'paypal-for-woocommerce') . $ErrorCode); 
  409. $this->ec_add_log(__('Error Severity Code: ', 'paypal-for-woocommerce') . $ErrorSeverityCode); 
  410. $order->add_order_note(__('PayPal DoReauthorization API call failed. ', $this->plugin_name) . 
  411. ' ( Detailed Error Message: ' . $ErrorLongMsg . ", " . 
  412. ' Short Error Message: ' . $ErrorShortMsg . ' )' . 
  413. ' Error Code: ' . $ErrorCode . ' )' . 
  414. ' Error Severity Code: ' . $ErrorSeverityCode . ' )' 
  415. ); 
  416. $this->call_error_email_notifications($subject = 'DoReauthorization failed', $method_name = 'DoReauthorization', $resArray = $do_reauthorization_result); 
  417.  
  418. /** 
  419. * @param type $order 
  420. */ 
  421. public function angelleye_wc_paypal_pro_doreauthorization($order) { 
  422. $this->add_ec_angelleye_paypal_php_library(); 
  423. if (!is_object($order)) { 
  424. $order = wc_get_order($order); 
  425. remove_action('woocommerce_order_action_wc_paypal_pro_doreauthorization', array($this, 'angelleye_wc_paypal_pro_doreauthorization')); 
  426. remove_action('woocommerce_process_shop_order_meta', 'WC_Meta_Box_Order_Data::save', 40, 2); 
  427. $this->call_do_reauthorization($order); 
  428.  
  429. /** 
  430. * @param type $order 
  431. */ 
  432. public function angelleye_wc_paypal_express_doauthorization($order) { 
  433. $this->add_ec_angelleye_paypal_php_library(); 
  434. if (!is_object($order)) { 
  435. $order = wc_get_order($order); 
  436. remove_action('woocommerce_order_action_wc_paypal_express_doauthorization', array($this, 'angelleye_wc_paypal_express_doauthorization')); 
  437. remove_action('woocommerce_process_shop_order_meta', 'WC_Meta_Box_Order_Data::save', 40, 2); 
  438. $this->call_do_authorization($order); 
  439.  
  440. public function call_do_authorization($order) { 
  441. $this->add_ec_angelleye_paypal_php_library(); 
  442. $this->ec_add_log('DoAuthorization API call'); 
  443. $order_id = version_compare( WC_VERSION, '3.0', '<' ) ? $order->id : $order->get_id(); 
  444. $old_wc = version_compare(WC_VERSION, '3.0', '<'); 
  445. $transaction_id = $old_wc ? get_post_meta($order_id, '_first_transaction_id', true) : get_post_meta($order->get_id(), '_first_transaction_id', true); 
  446. if (isset($transaction_id) && !empty($transaction_id)) { 
  447. $DRFields = array( 
  448. 'TRANSACTIONID' => $transaction_id, // Required. The value of a previously authorized transaction ID returned by PayPal. 
  449. 'AMT' => self::number_format($_POST['_regular_price']), // Required. Must have two decimal places. Decimal separator must be a period (.) and optional thousands separator must be a comma (, ) 
  450. 'CURRENCYCODE' => version_compare(WC_VERSION, '3.0', '<') ? $order->get_order_currency() : $order->get_currency() 
  451. ); 
  452. $PayPalRequestData = array('DAFields' => $DRFields); 
  453. $do_authorization_result = $this->paypal->DoAuthorization($PayPalRequestData); 
  454. $this->angelleye_write_request_response_api_log($do_authorization_result); 
  455. $ack = strtoupper($do_authorization_result["ACK"]); 
  456. if ($ack == "SUCCESS" || $ack == "SUCCESSWITHWARNING") { 
  457. $order->add_order_note(__('PayPal authorization', 'paypal-for-woocommerce') . 
  458. ' ( Response Code: ' . $do_authorization_result["ACK"] . ", " . 
  459. ' DoAuthorization AUTHORIZATIONID: ' . $do_authorization_result['TRANSACTIONID'] . ' )' 
  460. ); 
  461. $payment_order_meta = array('_transaction_id' => $do_authorization_result['TRANSACTIONID']); 
  462. self::angelleye_add_order_meta($order_id, $payment_order_meta); 
  463. self::angelleye_paypal_for_woocommerce_add_paypal_transaction($do_authorization_result, $order, 'DoAuthorization'); 
  464. } else { 
  465. $ErrorCode = urldecode($do_authorization_result["L_ERRORCODE0"]); 
  466. $ErrorShortMsg = urldecode($do_authorization_result["L_SHORTMESSAGE0"]); 
  467. $ErrorLongMsg = urldecode($do_authorization_result["L_LONGMESSAGE0"]); 
  468. $ErrorSeverityCode = urldecode($do_authorization_result["L_SEVERITYCODE0"]); 
  469. $this->ec_add_log(__('PayPal DoAuthorization API call failed. ', 'paypal-for-woocommerce')); 
  470. $this->ec_add_log(__('Detailed Error Message: ', 'paypal-for-woocommerce') . $ErrorLongMsg); 
  471. $this->ec_add_log(__('Short Error Message: ', 'paypal-for-woocommerce') . $ErrorShortMsg); 
  472. $this->ec_add_log(__('Error Code: ', 'paypal-for-woocommerce') . $ErrorCode); 
  473. $this->ec_add_log(__('Error Severity Code: ', 'paypal-for-woocommerce') . $ErrorSeverityCode); 
  474. $order->add_order_note(__('PayPal DoAuthorization API call failed. ', 'paypal-for-woocommerce') . 
  475. ' ( Detailed Error Message: ' . $ErrorLongMsg . ", " . 
  476. ' Short Error Message: ' . $ErrorShortMsg . ' )' . 
  477. ' Error Code: ' . $ErrorCode . ' )' . 
  478. ' Error Severity Code: ' . $ErrorSeverityCode . ' )' 
  479. ); 
  480. $this->call_error_email_notifications($subject = 'DoAuthorization failed', $method_name = 'DoAuthorization', $resArray = $do_authorization_result); 
  481.  
  482. public function ec_add_log($message) { 
  483. if ($this->ec_debug == 'yes') { 
  484. if (empty($this->log)) { 
  485. $this->log = new WC_Logger(); 
  486. $this->log->add(str_replace("_", "-", $this->payment_method) , $message); 
  487.  
  488. public function call_error_email_notifications($subject = null, $method_name = null, $resArray = null) { 
  489. if ((isset($resArray["L_ERRORCODE0"]) && !empty($resArray["L_ERRORCODE0"])) && ( isset($resArray["L_SHORTMESSAGE0"]) && !empty($resArray["L_SHORTMESSAGE0"]))) { 
  490. $ErrorCode = urldecode($resArray["L_ERRORCODE0"]); 
  491. $ErrorShortMsg = urldecode($resArray["L_SHORTMESSAGE0"]); 
  492. $ErrorLongMsg = urldecode($resArray["L_LONGMESSAGE0"]); 
  493. $ErrorSeverityCode = urldecode($resArray["L_SEVERITYCODE0"]); 
  494. $this->ec_add_log(__($method_name . ' API call failed. ', 'paypal-for-woocommerce')); 
  495. $this->ec_add_log(__('Detailed Error Message: ', 'paypal-for-woocommerce') . $ErrorLongMsg); 
  496. $this->ec_add_log(__('Short Error Message: ', 'paypal-for-woocommerce') . $ErrorShortMsg); 
  497. $this->ec_add_log(__('Error Code: ', 'paypal-for-woocommerce') . $ErrorCode); 
  498. $this->ec_add_log(__('Error Severity Code: ', 'paypal-for-woocommerce') . $ErrorSeverityCode); 
  499. $message = ''; 
  500. if ($this->error_email_notify) { 
  501. $admin_email = get_option("admin_email"); 
  502. $message .= __($method_name, "paypal-for-woocommerce") . "\n\n"; 
  503. $message .= __('Error Code: ', 'paypal-for-woocommerce') . $ErrorCode . "\n"; 
  504. $message .= __('Error Severity Code: ', 'paypal-for-woocommerce') . $ErrorSeverityCode . "\n"; 
  505. $message .= __('Short Error Message: ', 'paypal-for-woocommerce') . $ErrorShortMsg . "\n"; 
  506. $message .= __('Detailed Error Message: ', 'paypal-for-woocommerce') . $ErrorLongMsg . "\n"; 
  507. $ofw_error_email_notify_mes = apply_filters('angelleye_error_email_notify_message', $message, $ErrorCode, $ErrorSeverityCode, $ErrorShortMsg, $ErrorLongMsg); 
  508. $ofw_error_email_notify_subject = apply_filters('angelleye_error_email_notify_subject', $subject); 
  509. wp_mail($admin_email, $ofw_error_email_notify_subject, $ofw_error_email_notify_mes); 
  510. if ((isset($resArray["Errors"][0]['ErrorID']) && !empty($resArray["Errors"][0]['ErrorID'])) && ( isset($resArray["Errors"][0]['Message']) && !empty($resArray["Errors"][0]['Message']))) { 
  511. $ErrorCode = $resArray["Errors"][0]['ErrorID']; 
  512. $ErrorShortMsg = $resArray["Errors"][0]['Message']; 
  513. $this->ec_add_log(__($method_name . ' API call failed. ', 'paypal-for-woocommerce')); 
  514. $this->ec_add_log(__('Short Error Message: ', 'paypal-for-woocommerce') . $ErrorShortMsg); 
  515. $this->ec_add_log(__('Error Code: ', 'paypal-for-woocommerce') . $ErrorCode); 
  516. $message = ''; 
  517. if ($this->error_email_notify) { 
  518. $admin_email = get_option("admin_email"); 
  519. $message .= __($method_name, "paypal-for-woocommerce") . "\n\n"; 
  520. $message .= __('Error Code: ', 'paypal-for-woocommerce') . $ErrorCode . "\n"; 
  521. $message .= __('Short Error Message: ', 'paypal-for-woocommerce') . $ErrorShortMsg . "\n"; 
  522. $ofw_error_email_notify_mes = apply_filters('angelleye_error_email_notify_message', $message, $ErrorCode, $ErrorShortMsg); 
  523. $ofw_error_email_notify_subject = apply_filters('angelleye_error_email_notify_subject', $subject); 
  524. wp_mail($admin_email, $ofw_error_email_notify_subject, $ofw_error_email_notify_mes); 
  525.  
  526. public function angelleye_woocommerce_payment_gateway_supports($boolean, $feature, $current) { 
  527. global $post; 
  528. if( empty($post->ID) ) { 
  529. return false; 
  530. $order_id = $post->ID; 
  531. if (!is_object($order_id)) { 
  532. $order = wc_get_order($order_id); 
  533. $payment_action = ''; 
  534. if ($current->id == 'paypal_express' || $current->id == 'paypal_pro') { 
  535. $old_wc = version_compare(WC_VERSION, '3.0', '<'); 
  536. $payment_action = $old_wc ? get_post_meta($order_id, '_payment_action', true) : get_post_meta($order->get_id(), '_payment_action', true); 
  537. if ($payment_action == 'Sale' || $payment_action == 'DoCapture' || empty($payment_action)) { 
  538. return $boolean; 
  539. } else { 
  540. return false; 
  541. } else { 
  542. return $boolean; 
  543.  
  544. public function angelleye_write_request_response_api_log($PayPalResult) { 
  545. $PayPalRequest = isset($PayPalResult['RAWREQUEST']) ? $PayPalResult['RAWREQUEST'] : ''; 
  546. $PayPalResponse = isset($PayPalResult['RAWRESPONSE']) ? $PayPalResult['RAWRESPONSE'] : ''; 
  547. $this->ec_add_log('Request: ' . print_r($this->paypal->NVPToArray($this->paypal->MaskAPIResult($PayPalRequest)), true)); 
  548. $this->ec_add_log('Response: ' . print_r($this->paypal->NVPToArray($this->paypal->MaskAPIResult($PayPalResponse)), true)); 
  549.  
  550. public static function angelleye_paypal_credit_card_rest_setting_fields() { 
  551. return array( 
  552. 'enabled' => array( 
  553. 'title' => __('Enable/Disable', 'paypal-for-woocommerce'),  
  554. 'type' => 'checkbox',  
  555. 'label' => __('Enable PayPal Credit Card (REST)', 'paypal-for-woocommerce'),  
  556. 'default' => 'no' 
  557. ),  
  558. 'title' => array( 
  559. 'title' => __('Title', 'paypal-for-woocommerce'),  
  560. 'type' => 'text',  
  561. 'description' => __('This controls the title which the user sees during checkout.', 'paypal-for-woocommerce'),  
  562. 'default' => __('PayPal Credit Card (REST)', 'paypal-for-woocommerce') 
  563. ),  
  564. 'description' => array( 
  565. 'title' => __('Description', 'paypal-for-woocommerce'),  
  566. 'type' => 'text',  
  567. 'description' => __('This controls the description which the user sees during checkout.', 'paypal-for-woocommerce'),  
  568. 'default' => __('PayPal Credit Card (REST) description', 'paypal-for-woocommerce') 
  569. ),  
  570. 'testmode' => array( 
  571. 'title' => __('Test Mode', 'paypal-for-woocommerce'),  
  572. 'type' => 'checkbox',  
  573. 'label' => __('Enable PayPal Sandbox/Test Mode', 'paypal-for-woocommerce'),  
  574. 'default' => 'yes',  
  575. 'description' => sprintf(__('Place the payment gateway in development mode. Sign up for a developer account <a href="%s" target="_blank">here</a>', 'paypal-for-woocommerce'), 'https://developer.paypal.com/'),  
  576. ),  
  577. 'rest_client_id_sandbox' => array( 
  578. 'title' => __('Sandbox Client ID', 'paypal-for-woocommerce'),  
  579. 'type' => 'password',  
  580. 'description' => 'Enter your Sandbox PayPal Rest API Client ID',  
  581. 'default' => '' 
  582. ),  
  583. 'rest_secret_id_sandbox' => array( 
  584. 'title' => __('Sandbox Secret ID', 'paypal-for-woocommerce'),  
  585. 'type' => 'password',  
  586. 'description' => __('Enter your Sandbox PayPal Rest API Secret ID.', 'paypal-for-woocommerce'),  
  587. 'default' => '' 
  588. ),  
  589. 'rest_client_id' => array( 
  590. 'title' => __('Live Client ID', 'paypal-for-woocommerce'),  
  591. 'type' => 'password',  
  592. 'description' => 'Enter your PayPal Rest API Client ID',  
  593. 'default' => '' 
  594. ),  
  595. 'rest_secret_id' => array( 
  596. 'title' => __('Live Secret ID', 'paypal-for-woocommerce'),  
  597. 'type' => 'password',  
  598. 'description' => __('Enter your PayPal Rest API Secret ID.', 'paypal-for-woocommerce'),  
  599. 'default' => '' 
  600. ),  
  601. 'enable_tokenized_payments' => array( 
  602. 'title' => __('Enable Tokenized Payments', 'paypal-for-woocommerce'),  
  603. 'label' => __('Enable Tokenized Payments', 'paypal-for-woocommerce'),  
  604. 'type' => 'checkbox',  
  605. 'description' => __('Allow buyers to securely save payment details to their account for quick checkout / auto-ship orders in the future.', 'paypal-for-woocommerce'),  
  606. 'default' => 'no',  
  607. 'class' => 'enable_tokenized_payments' 
  608. ),  
  609. 'invoice_prefix' => array( 
  610. 'title' => __('Invoice Prefix', 'paypal-for-woocommerce'),  
  611. 'type' => 'text',  
  612. 'description' => __('Please enter a prefix for your invoice numbers. If you use your PayPal account for multiple stores ensure this prefix is unique as PayPal will not allow orders with the same invoice number.', 'paypal-for-woocommerce'),  
  613. 'default' => 'WC-PCCR',  
  614. 'desc_tip' => true,  
  615. ),  
  616. 'card_icon' => array( 
  617. 'title' => __( 'Card Icon', 'paypal-for-woocommerce' ),  
  618. 'type' => 'text',  
  619. 'default' => plugins_url('/assets/images/cards.png', plugin_basename(dirname(__FILE__))),  
  620. 'class' => 'button_upload' 
  621. ),  
  622. 'softdescriptor' => array( 
  623. 'title' => __('Credit Card Statement Name', 'paypal-for-woocommerce'),  
  624. 'type' => 'text',  
  625. 'description' => __('The value entered here will be displayed on the buyer\'s credit card statement.', 'paypal-for-woocommerce'),  
  626. 'default' => '',  
  627. 'desc_tip' => true,  
  628. ),  
  629. 'debug' => array( 
  630. 'title' => __('Debug Log', 'paypal-for-woocommerce'),  
  631. 'type' => 'checkbox',  
  632. 'label' => __('Enable logging', 'paypal-for-woocommerce'),  
  633. 'default' => 'no',  
  634. 'description' => sprintf(__('Log PayPal events, such as Secured Token requests, inside <code>%s</code>', 'paypal-for-woocommerce'), wc_get_log_file_path('paypal_credit_card_rest')),  
  635. ),  
  636. 'is_encrypt' => array( 
  637. 'title' => __('', 'paypal-for-woocommerce'),  
  638. 'label' => __('', 'paypal-for-woocommerce'),  
  639. 'type' => 'hidden',  
  640. 'default' => 'yes',  
  641. 'class' => '' 
  642. ); 
  643.  
  644. public static function card_type_from_account_number($account_number) { 
  645. $types = array( 
  646. 'visa' => '/^4/',  
  647. 'mastercard' => '/^5[1-5]/',  
  648. 'amex' => '/^3[47]/',  
  649. 'discover' => '/^(6011|65|64[4-9]|622)/',  
  650. 'diners' => '/^(36|38|30[0-5])/',  
  651. 'jcb' => '/^35/',  
  652. 'maestro' => '/^(5018|5020|5038|6304|6759|676[1-3])/',  
  653. 'laser' => '/^(6706|6771|6709)/',  
  654. ); 
  655. foreach ($types as $type => $pattern) { 
  656. if (1 === preg_match($pattern, $account_number)) { 
  657. return $type; 
  658. return null; 
  659.  
  660. public static function is_express_checkout_credentials_is_set() { 
  661. $pp_settings = get_option('woocommerce_paypal_express_settings'); 
  662. $testmode = isset($pp_settings['testmode']) ? $pp_settings['testmode'] : 'yes'; 
  663. $enabled = (isset($pp_settings['enabled']) && $pp_settings['enabled'] == 'yes') ? 'yes' : 'no'; 
  664. if ($testmode == 'yes') { 
  665. $api_username = isset($pp_settings['sandbox_api_username']) ? $pp_settings['sandbox_api_username'] : ''; 
  666. $api_password = isset($pp_settings['sandbox_api_password']) ? $pp_settings['sandbox_api_password'] : ''; 
  667. $api_signature = isset($pp_settings['sandbox_api_signature']) ? $pp_settings['sandbox_api_signature'] : ''; 
  668. } else { 
  669. $api_username = isset($pp_settings['api_username']) ? $pp_settings['api_username'] : ''; 
  670. $api_password = isset($pp_settings['api_password']) ? $pp_settings['api_password'] : ''; 
  671. $api_signature = isset($pp_settings['api_signature']) ? $pp_settings['api_signature'] : ''; 
  672. if ('yes' != $enabled) { 
  673. return false; 
  674. if (!$api_username || !$api_password || !$api_signature) { 
  675. return false; 
  676. return true; 
  677.  
  678. public function paypal_for_woocommerce_paypal_transaction_history() { 
  679.  
  680. if (post_type_exists('paypal_transaction')) { 
  681. return; 
  682.  
  683. do_action('paypal_for_woocommerce_register_post_type'); 
  684.  
  685. register_post_type('paypal_transaction', apply_filters('paypal_for_woocommerce_register_post_type_paypal_transaction_history', array( 
  686. 'labels' => array( 
  687. 'name' => __('PayPal Transaction', 'paypal-for-woocommerce'),  
  688. 'singular_name' => __('PayPal Transaction', 'paypal-for-woocommerce'),  
  689. 'menu_name' => _x('PayPal Transaction', 'Admin menu name', 'paypal-for-woocommerce'),  
  690. 'add_new' => __('Add PayPal Transaction', 'paypal-for-woocommerce'),  
  691. 'add_new_item' => __('Add New PayPal Transaction', 'paypal-for-woocommerce'),  
  692. 'edit' => __('Edit', 'paypal-for-woocommerce'),  
  693. 'edit_item' => __('View PayPal Transaction', 'paypal-for-woocommerce'),  
  694. 'new_item' => __('New PayPal Transaction', 'paypal-for-woocommerce'),  
  695. 'view' => __('View PayPal Transaction', 'paypal-for-woocommerce'),  
  696. 'view_item' => __('View PayPal Transaction', 'paypal-for-woocommerce'),  
  697. 'search_items' => __('Search PayPal Transaction', 'paypal-for-woocommerce'),  
  698. 'not_found' => __('No PayPal Transaction found', 'paypal-for-woocommerce'),  
  699. 'not_found_in_trash' => __('No PayPal Transaction found in trash', 'paypal-for-woocommerce'),  
  700. 'parent' => __('Parent PayPal Transaction', 'paypal-for-woocommerce') 
  701. ),  
  702. 'description' => __('This is where you can add new PayPal Transaction to your store.', 'paypal-for-woocommerce'),  
  703. 'public' => false,  
  704. 'show_ui' => false,  
  705. 'capability_type' => 'post',  
  706. 'capabilities' => array( 
  707. 'create_posts' => false, // Removes support for the "Add New" function 
  708. ),  
  709. 'map_meta_cap' => true,  
  710. 'publicly_queryable' => true,  
  711. 'exclude_from_search' => false,  
  712. 'hierarchical' => false, // Hierarchical causes memory issues - WP loads all records! 
  713. 'rewrite' => array('slug' => 'paypal_ipn'),  
  714. 'query_var' => true,  
  715. 'supports' => array('', ''),  
  716. 'has_archive' => true,  
  717. 'show_in_nav_menus' => FALSE 
  718. ); 
  719.  
  720. public function angelleye_paypal_for_woocommerce_order_action_meta_box($post_type, $post) { 
  721. if (isset($post->ID) && !empty($post->ID) && $post_type == 'shop_order') { 
  722. if ($this->angelleye_is_display_paypal_transaction_details($post->ID)) { 
  723. add_meta_box('angelleye-pw-order-action', __('PayPal Transaction History', 'paypal-for-woocommerce'), array($this, 'angelleye_paypal_for_woocommerce_order_action_callback'), 'shop_order', 'normal', 'high', null); 
  724.  
  725. public function angelleye_paypal_for_woocommerce_order_action_callback($post) { 
  726.  
  727. $args = array( 
  728. 'post_type' => 'paypal_transaction',  
  729. 'posts_per_page' => -1,  
  730. 'meta_key' => 'order_id',  
  731. 'meta_value' => $post->ID,  
  732. 'order' => 'ASC',  
  733. 'post_status' => 'any' 
  734. ); 
  735. $posts_array = get_posts($args); 
  736. foreach ($posts_array as $post_data): 
  737. $payment_status = get_post_meta($post_data->ID, 'PAYMENTSTATUS', true); 
  738. if( isset($post->post_title) && !empty($post_data->post_title) && isset($payment_status) && $payment_status == 'Pending' ) { 
  739. $this->angelleye_get_transactionDetails($post_data->post_title); 
  740. endforeach; 
  741. $order = wc_get_order($post->ID); 
  742.  
  743. if (empty($this->angelleye_woocommerce_order_actions)) { 
  744. $this->angelleye_woocommerce_order_actions = $this->angelleye_woocommerce_order_actions(); 
  745. ?> 
  746. <div class='wrap'> 
  747. <?php 
  748. if (isset($this->angelleye_woocommerce_order_actions) && !empty($this->angelleye_woocommerce_order_actions)) { 
  749. ?> 
  750. <select name="angelleye_payment_action" id="angelleye_payment_action">  
  751. <?php 
  752. $i = 0; 
  753. foreach ($this->angelleye_woocommerce_order_actions as $k => $v) : 
  754. if ($i == 0) { 
  755. echo '<option value="" >Select Action</option>'; 
  756. ?> 
  757. <option value="<?php echo esc_attr($k); ?>" ><?php echo esc_html($v); ?></option> 
  758. <?php 
  759. $i = $i + 1; 
  760. endforeach; 
  761. ?> 
  762. </select>  
  763. <div class="angelleye_authorization_box" style="display: none;"> 
  764. <?php 
  765. if (isset($this->remain_authorize_amount)) { 
  766. $remain_authorize_amount_text = 'less than ' . $this->remain_authorize_amount; 
  767. } else { 
  768. $remain_authorize_amount_text = ''; 
  769. ?> 
  770. <input type="text" placeholder="Enter amount <?php echo $remain_authorize_amount_text; ?>" id="_regular_price" name="_regular_price" class="short wc_input_price text-box" style="width: 220px"> 
  771. </div> 
  772. <?php $this->angelleye_express_checkout_transaction_capture_dropdownbox($post->ID); ?> 
  773. <input type="submit" id="angelleye_payment_submit_button" value="Submit" name="save" class="button button-primary" style="display: none"> 
  774. <br/><br/><br/> 
  775. <script> 
  776. (function($) { 
  777. "use strict"; 
  778.  
  779. //Asking confirm for the capture 
  780. $('#angelleye_payment_submit_button').on('click', function() { 
  781. var selected = $('#angelleye_payment_action option:checked').val(); 
  782. if(selected == 'DoCapture') { 
  783. var amt = $('.angelleye_order_action_table:first tr:first td:last').text(); 
  784.  
  785. return confirm('You are capturing: ' + amt + '. Are you sure?'); 
  786. }) 
  787.  
  788. MutationObserver = window.MutationObserver || window.WebKitMutationObserver; 
  789. var observer = new MutationObserver(function(mutations, observer) { 
  790. var currency_symbol = window.woocommerce_admin_meta_boxes.currency_format_symbol; 
  791.  
  792. for(var i = 0, len = mutations.length; i < len; i++) { 
  793. //Updating the total order action table field 
  794. if(mutations[i].target.className == 'inside' && mutations[i].addedNodes.length > 0) { 
  795. var new_amt_with_curr = $('.wc-order-refund-items .wc-order-totals tr td.total .amount:last').text(); 
  796. //Adjusting price with paypal-for-woocommerce amount format 
  797. new_amt_with_curr = currency_symbol + new_amt_with_curr.replace(currency_symbol, ''); 
  798. $('.angelleye_order_action_table:first tr:first td:last').text(new_amt_with_curr); 
  799. }); 
  800.  
  801. //Setting an observer to know about total new total amount 
  802. $(document).ready(function () { 
  803. var target = document.getElementById('woocommerce-order-items').getElementsByClassName('inside')[0]; 
  804. observer.observe(target, { 
  805. childList: true,  
  806. }); 
  807. }); 
  808. })(jQuery); 
  809. </script> 
  810. <?php 
  811.  
  812. ?> 
  813. <table class="widefat angelleye_order_action_table" style="width: 190px;float: right;"> 
  814. <tbody> 
  815. <tr> 
  816. <td><?php echo __('Order Total:', 'paypal-for-woocommerce'); ?></td> 
  817. <td><?php echo $order->get_formatted_order_total(); ?></td> 
  818. </tr> 
  819. <tr> 
  820. <td><?php echo __('Total Capture:', 'paypal-for-woocommerce'); ?></td> 
  821. <td><?php echo $this->total_DoCapture .' '. get_woocommerce_currency_symbol() ?></td> 
  822. </tr> 
  823. </tbody> 
  824. </table> 
  825. <br/><br/> 
  826. <table class="widefat angelleye_order_action_table"> 
  827. <thead> 
  828. <tr> 
  829. <th><?php echo __('Transaction ID', 'paypal-for-woocommerce'); ?></th> 
  830. <th><?php echo __('Date', 'paypal-for-woocommerce'); ?></th>  
  831. <th><?php echo __('Amount', 'paypal-for-woocommerce'); ?></th> 
  832. <th><?php echo __('Payment Status', 'paypal-for-woocommerce'); ?></th> 
  833. <th><?php echo __('Payment Action', 'paypal-for-woocommerce'); ?></th> 
  834. </tr> 
  835. </thead> 
  836. <tfoot> 
  837. <tr> 
  838. <th><?php echo __('Transaction ID', 'paypal-for-woocommerce'); ?></th> 
  839. <th><?php echo __('Date', 'paypal-for-woocommerce'); ?></th>  
  840. <th><?php echo __('Amount', 'paypal-for-woocommerce'); ?></th> 
  841. <th><?php echo __('Payment Status', 'paypal-for-woocommerce'); ?></th> 
  842. <th><?php echo __('Payment Action', 'paypal-for-woocommerce'); ?></th> 
  843. </tr> 
  844. </tfoot> 
  845. <tbody> 
  846. <?php 
  847. foreach ($posts_array as $post): 
  848. ?> 
  849. <tr> 
  850. <td><?php echo $post->post_title; ?></td> 
  851. <td><?php echo esc_attr(get_post_meta($post->ID, 'TIMESTAMP', true)); ?></th>  
  852. <td><?php echo esc_attr(get_post_meta($post->ID, 'AMT', true)) .' '. get_woocommerce_currency_symbol(); ?></td> 
  853. <?php $PENDINGREASON = esc_attr(get_post_meta($post->ID, 'PENDINGREASON', true)); ?> 
  854. <td <?php echo ($PENDINGREASON) ? sprintf('title="%s"', $PENDINGREASON) : ""; ?> ><?php echo esc_attr(get_post_meta($post->ID, 'PAYMENTSTATUS', true)); ?></td> 
  855. <td><?php echo esc_attr(get_post_meta($post->ID, 'payment_action', true)); ?> </td> 
  856. </tr> 
  857. <?php 
  858. endforeach; 
  859. ?> 
  860. </tbody> 
  861. </table> 
  862. </div> 
  863. <?php 
  864.  
  865. public static function angelleye_paypal_for_woocommerce_add_paypal_transaction($response, $order, $payment_action) { 
  866. if ($payment_action == 'Authorization') { 
  867. $payment_action = 'DoAuthorization'; 
  868. $order_id = version_compare( WC_VERSION, '3.0', '<' ) ? $order->id : $order->get_id(); 
  869. $TRANSACTIONID = ''; 
  870. if (isset($response['PAYMENTINFO_0_TRANSACTIONID']) && !empty($response['PAYMENTINFO_0_TRANSACTIONID'])) { 
  871. $TRANSACTIONID = $response['PAYMENTINFO_0_TRANSACTIONID']; 
  872. } elseif (isset($response['TRANSACTIONID']) && !empty($response['TRANSACTIONID'])) { 
  873. $TRANSACTIONID = $response['TRANSACTIONID']; 
  874. } elseif (isset($response['AUTHORIZATIONID'])) { 
  875. $TRANSACTIONID = $response['AUTHORIZATIONID']; 
  876. $insert_paypal_transaction = array( 
  877. 'ID' => '',  
  878. 'post_type' => 'paypal_transaction',  
  879. 'post_status' => $payment_action,  
  880. 'post_title' => $TRANSACTIONID,  
  881. 'post_parent' => $order_id 
  882. ); 
  883. unset($response['ERRORS']); 
  884. unset($response['REQUESTDATA']); 
  885. unset($response['RAWREQUEST']); 
  886. unset($response['RAWRESPONSE']); 
  887. unset($response['PAYMENTS']); 
  888. $post_id = wp_insert_post($insert_paypal_transaction); 
  889. $response['order_id'] = $order_id; 
  890. $response['payment_action'] = $payment_action; 
  891. $response['_trans_date'] = current_time('mysql'); 
  892. update_post_meta($post_id, 'paypal_transaction', $response); 
  893. foreach ($response as $metakey => $metavalue) { 
  894. $metakey = str_replace('PAYMENTINFO_0_', '', $metakey); 
  895. update_post_meta($post_id, $metakey, $metavalue); 
  896. if ($payment_action == 'DoVoid') { 
  897. $post_id_value = self::get_post_id_by_meta_key_and_meta_value('TRANSACTIONID', $response['AUTHORIZATIONID']); 
  898. $AMT = get_post_meta($post_id_value, 'AMT', true); 
  899. update_post_meta($post_id, 'AMT', $AMT); 
  900.  
  901. public static function get_post_id_by_meta_key_and_meta_value($key, $value) { 
  902. global $wpdb; 
  903. $post_id_value = $wpdb->get_var($wpdb->prepare("SELECT post_id FROM {$wpdb->postmeta} WHERE `meta_key` LIKE '%s' AND `meta_value` LIKE '%s'", $key, $value)); 
  904. return $post_id_value; 
  905.  
  906. public function save($post_id, $post) { 
  907. $order = wc_get_order($post_id); 
  908. if (empty($this->payment_method)) { 
  909. $old_wc = version_compare(WC_VERSION, '3.0', '<'); 
  910. $order_id = version_compare( WC_VERSION, '3.0', '<' ) ? $order->id : $order->get_id(); 
  911. $this->payment_method = $old_wc ? get_post_meta($order_id, '_payment_method', true) : get_post_meta($order->get_id(), '_payment_method', true); 
  912. if (!empty($_POST['angelleye_payment_action'])) { 
  913. $action = wc_clean($_POST['angelleye_payment_action']); 
  914. $hook_name = 'wc_' . $this->payment_method . '_' . strtolower($action); 
  915. if (!did_action('woocommerce_order_action_' . sanitize_title($hook_name))) { 
  916. do_action('woocommerce_order_action_' . sanitize_title($hook_name), $order); 
  917.  
  918. public static function get_total($action, $status, $order_id) { 
  919. global $wpdb; 
  920. if ($action == 'DoVoid') { 
  921. $total = $wpdb->get_var($wpdb->prepare(" 
  922. SELECT SUM( postmeta.meta_value ) 
  923. FROM $wpdb->postmeta AS postmeta 
  924. INNER JOIN $wpdb->posts AS posts ON ( posts.post_type = 'paypal_transaction' AND posts.post_status LIKE '%s' AND post_parent = %d ) 
  925. WHERE postmeta.meta_key = 'AMT'  
  926. AND postmeta.post_id = posts.ID LIMIT 0, 99 
  927. ", $action, $order_id)); 
  928. } else { 
  929. if ($action == 'DoCapture') { 
  930. $total = $wpdb->get_var($wpdb->prepare(" 
  931. SELECT SUM( postmeta.meta_value ) 
  932. FROM $wpdb->postmeta AS postmeta 
  933. JOIN $wpdb->postmeta pm2 ON pm2.post_id = postmeta.post_id 
  934. INNER JOIN $wpdb->posts AS posts ON ( posts.post_type = 'paypal_transaction' AND posts.post_status LIKE '%s' AND post_parent = %d ) 
  935. WHERE postmeta.meta_key = 'AMT' AND pm2.meta_key = 'PAYMENTSTATUS' AND (pm2.meta_value LIKE '%s' OR pm2.meta_value LIKE 'Pending') 
  936. AND postmeta.post_id = posts.ID LIMIT 0, 99 
  937. ", $action, $order_id, $status)); 
  938. } else { 
  939. $total = $wpdb->get_var($wpdb->prepare(" 
  940. SELECT SUM( postmeta.meta_value ) 
  941. FROM $wpdb->postmeta AS postmeta 
  942. JOIN $wpdb->postmeta pm2 ON pm2.post_id = postmeta.post_id 
  943. INNER JOIN $wpdb->posts AS posts ON ( posts.post_type = 'paypal_transaction' AND posts.post_status LIKE '%s' AND post_parent = %d ) 
  944. WHERE postmeta.meta_key = 'AMT' AND pm2.meta_key = 'PAYMENTSTATUS' AND pm2.meta_value LIKE '%s' 
  945. AND postmeta.post_id = posts.ID LIMIT 0, 99 
  946. ", $action, $order_id, $status)); 
  947. if ($total == NULL) { 
  948. $total = 0; 
  949. return self::number_format($total); 
  950.  
  951. public function angelleye_paypal_for_woocommerce_order_status_handler($order) { 
  952. $this->angelleye_woocommerce_order_actions = $this->angelleye_woocommerce_order_actions(); 
  953. if (!is_object($order)) { 
  954. $order = wc_get_order($order); 
  955. $old_wc = version_compare(WC_VERSION, '3.0', '<'); 
  956. $order_id = version_compare(WC_VERSION, '3.0', '<') ? $order->id : $order->get_id(); 
  957. $_first_transaction_id = $old_wc ? get_post_meta($order_id, '_first_transaction_id', true) : get_post_meta($order->get_id(), '_first_transaction_id', true); 
  958. if( empty($_first_transaction_id) ) { 
  959. return false; 
  960. $this->angelleye_get_transactionDetails($_first_transaction_id); 
  961. $_payment_action = $old_wc ? get_post_meta($order_id, '_payment_action', true) : get_post_meta($order->get_id(), '_payment_action', true); 
  962. if (isset($_payment_action) && !empty($_payment_action) && $_payment_action == 'Order') { 
  963. if (($this->max_authorize_amount <= $this->total_DoVoid) || ($this->total_Pending_DoAuthorization == 0 && $this->total_Completed_DoAuthorization == 0 && $this->total_DoVoid == $order->get_total())) { 
  964. $order->update_status('cancelled'); 
  965. if ($order->get_total() - $order->get_total_refunded() <= $this->total_Completed_DoAuthorization && $this->total_Pending_DoAuthorization == 0) { 
  966. do_action('woocommerce_order_status_pending_to_processing', $order_id); 
  967. $order->payment_complete($_first_transaction_id); 
  968. do_action('woocommerce_checkout_order_processed', $order_id, $posted = array()); 
  969. if ($old_wc) { 
  970. $order->reduce_order_stock(); 
  971. } else { 
  972. wc_reduce_stock_levels($order->get_id()); 
  973.  
  974. if ($order->get_total() == $this->total_DoVoid) { 
  975. $order->update_status('cancelled'); 
  976.  
  977. public function angelleye_express_checkout_transaction_capture_dropdownbox($post_id) { 
  978. global $wpdb; 
  979. $order = wc_get_order($post_id); 
  980. wp_reset_postdata(); 
  981. $old_wc = version_compare(WC_VERSION, '3.0', '<'); 
  982. $order_id = version_compare( WC_VERSION, '3.0', '<' ) ? $order->id : $order->get_id(); 
  983. $payment_action = $old_wc ? get_post_meta($order_id, '_payment_action', true) : get_post_meta($order->get_id(), '_payment_action', true); 
  984. if ($this->total_DoCapture == 0 && $this->total_Pending_DoAuthorization == 0) { 
  985. if ('Order' == $payment_action) { 
  986. $post_status = 'Order'; 
  987. } else { 
  988. $post_status = 'DoAuthorization'; 
  989. } else { 
  990. $post_status = 'DoAuthorization'; 
  991. }  
  992. if ($this->total_Completed_DoAuthorization < $this->total_Order || $this->total_Pending_DoAuthorization > 0) { 
  993. $posts = $wpdb->get_results($wpdb->prepare("SELECT $wpdb->posts.ID, $wpdb->posts.post_title FROM $wpdb->posts INNER JOIN $wpdb->postmeta ON ( $wpdb->posts.ID = $wpdb->postmeta.post_id ) WHERE 1=1 AND $wpdb->posts.post_status LIKE '%s' AND $wpdb->posts.post_parent = %d AND ( ( $wpdb->postmeta.meta_key = 'PAYMENTSTATUS' AND CAST($wpdb->postmeta.meta_value AS CHAR) = 'Pending' ) ) AND $wpdb->posts.post_type = 'paypal_transaction' GROUP BY $wpdb->posts.ID ORDER BY $wpdb->posts.post_date DESC LIMIT 0, 99", $post_status, $order_id), ARRAY_A); 
  994. if (empty($posts)) { 
  995. return false; 
  996. ?> 
  997. <select name="angelleye_paypal_capture_transaction_dropdown" id="angelleye_paypal_capture_transaction_dropdown" style="display: none">  
  998. <?php 
  999. $i = 0; 
  1000. foreach ($posts as $post): 
  1001. if ($i == 0) { 
  1002. echo '<option value="" >Select Transaction ID</option>'; 
  1003. ?> 
  1004. <option value="<?php echo esc_attr($post['post_title']); ?>" ><?php echo esc_html($post['post_title']); ?></option> 
  1005. <?php 
  1006. $i = $i + 1; 
  1007. endforeach; 
  1008. ?> 
  1009. </select>  
  1010. <?php 
  1011. if (($this->total_Completed_DoAuthorization == $this->total_DoCapture && $this->total_DoCapture > 0) || $this->total_Pending_DoAuthorization >= 0) { 
  1012. ?> 
  1013. <select name="angelleye_paypal_dovoid_transaction_dropdown" id="angelleye_paypal_dovoid_transaction_dropdown" style="display: none">  
  1014. <?php 
  1015. $i = 0; 
  1016. if (empty($posts)) { 
  1017. $posts = $wpdb->get_results($wpdb->prepare("SELECT $wpdb->posts.ID, $wpdb->posts.post_title FROM $wpdb->posts INNER JOIN $wpdb->postmeta ON ( $wpdb->posts.ID = $wpdb->postmeta.post_id ) WHERE 1=1 AND $wpdb->posts.post_status LIKE '%s' AND $wpdb->posts.post_parent = %d AND ( ( $wpdb->postmeta.meta_key = 'PAYMENTSTATUS' AND CAST($wpdb->postmeta.meta_value AS CHAR) = 'Pending' ) ) AND $wpdb->posts.post_type = 'paypal_transaction' GROUP BY $wpdb->posts.ID ORDER BY $wpdb->posts.post_date DESC LIMIT 0, 99", $post_status, $order_id), ARRAY_A); 
  1018. foreach ($posts as $post): 
  1019. if ($i == 0) { 
  1020. echo '<option value="" >Select Transaction ID</option>'; 
  1021. ?> 
  1022. <option value="<?php echo esc_attr($post['post_title']); ?>" ><?php echo esc_html($post['post_title']); ?></option> 
  1023. <?php 
  1024. $i = $i + 1; 
  1025. endforeach; 
  1026. ?> 
  1027. </select>  
  1028. <?php 
  1029. if (($this->total_Completed_DoAuthorization == $this->total_DoCapture && $this->total_DoCapture > 0) || $this->total_Pending_DoAuthorization >= 0) { 
  1030. ?> 
  1031. <select name="angelleye_paypal_doreauthorization_transaction_dropdown" id="angelleye_paypal_doreauthorization_transaction_dropdown" style="display: none">  
  1032. <?php 
  1033. $i = 0; 
  1034. if (empty($posts)) { 
  1035. $posts = $wpdb->get_results($wpdb->prepare("SELECT $wpdb->posts.ID, $wpdb->posts.post_title FROM $wpdb->posts INNER JOIN $wpdb->postmeta ON ( $wpdb->posts.ID = $wpdb->postmeta.post_id ) WHERE 1=1 AND $wpdb->posts.post_status LIKE '%s' AND $wpdb->posts.post_parent = %d AND ( ( $wpdb->postmeta.meta_key = 'PAYMENTSTATUS' AND CAST($wpdb->postmeta.meta_value AS CHAR) = 'Pending' ) ) AND $wpdb->posts.post_type = 'paypal_transaction' GROUP BY $wpdb->posts.ID ORDER BY $wpdb->posts.post_date DESC LIMIT 0, 99", $post_status, $order_id), ARRAY_A); 
  1036. foreach ($posts as $post): 
  1037. if ($i == 0) { 
  1038. echo '<option value="" >Select Transaction ID</option>'; 
  1039. ?> 
  1040. <option value="<?php echo esc_attr($post['post_title']); ?>" ><?php echo esc_html($post['post_title']); ?></option> 
  1041. <?php 
  1042. $i = $i + 1; 
  1043. endforeach; 
  1044. ?> 
  1045. </select>  
  1046. <?php 
  1047.  
  1048. public function angelleye_get_transactionDetails($transaction_id) { 
  1049. if( empty($this->payment_method) && $this->payment_method == false) { 
  1050. $this->angelleye_set_payment_method_using_transaction_id($transaction_id); 
  1051. $this->add_ec_angelleye_paypal_php_library(); 
  1052. $GTDFields = array( 
  1053. 'transactionid' => $transaction_id 
  1054. ); 
  1055. $PayPalRequestData = array('GTDFields' => $GTDFields); 
  1056. $get_transactionDetails_result = $this->paypal->GetTransactionDetails($PayPalRequestData); 
  1057. $this->angelleye_write_request_response_api_log($get_transactionDetails_result); 
  1058. $ack = strtoupper($get_transactionDetails_result["ACK"]); 
  1059. if ($ack == "SUCCESS" || $ack == "SUCCESSWITHWARNING") { 
  1060. $AUTHORIZATIONID = $this->get_post_by_title($transaction_id); 
  1061. if ($AUTHORIZATIONID != null) { 
  1062. update_post_meta($AUTHORIZATIONID, 'PAYMENTSTATUS', $get_transactionDetails_result['PAYMENTSTATUS']); 
  1063.  
  1064. function get_post_by_title($page_title) { 
  1065. global $wpdb; 
  1066. $post = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_title = %s AND post_type='paypal_transaction'", $page_title)); 
  1067. if ($post) { 
  1068. return $post; 
  1069. return null; 
  1070.  
  1071. public function get_amount_by_transaction_id($transaction_id) { 
  1072. $meta_post_id = self::get_post_id_by_meta_key_and_meta_value('TRANSACTIONID', $transaction_id); 
  1073. $AMT = get_post_meta($meta_post_id, 'AMT', true); 
  1074. return self::number_format($AMT); 
  1075.  
  1076. public function angelleye_max_authorize_amount($order_id) { 
  1077. if (!is_object($order_id)) { 
  1078. $order = wc_get_order($order_id); 
  1079. $percentage = 115; 
  1080. $new_percentage_amount = self::round(($percentage / 100) * $order->get_total()); 
  1081. $diff_percentage_amount = self::round($new_percentage_amount - $order->get_total()); 
  1082. if ($diff_percentage_amount > 75) { 
  1083. $max_authorize_amount = self::round($order->get_total() + 75); 
  1084. } else { 
  1085. $max_authorize_amount = $new_percentage_amount; 
  1086. $this->max_authorize_amount = self::number_format($max_authorize_amount); 
  1087.  
  1088. public function angelleye_remain_authorize_amount() { 
  1089. $this->remain_authorize_amount = self::number_format($this->max_authorize_amount - ( self::round($this->total_Pending_DoAuthorization + $this->total_Completed_DoAuthorization))); 
  1090.  
  1091. public static function currency_has_decimals($currency) { 
  1092. if (in_array($currency, array('HUF', 'JPY', 'TWD'))) { 
  1093. return false; 
  1094. return true; 
  1095.  
  1096. public static function round($price) { 
  1097. $precision = 2; 
  1098. if (!self::currency_has_decimals(get_woocommerce_currency())) { 
  1099. $precision = 0; 
  1100. return round($price, $precision); 
  1101.  
  1102. /** 
  1103. * @since 1.1.8.1 
  1104. * Non-decimal currency bug..?? #384  
  1105. * Round prices 
  1106. * @param type $price 
  1107. * @return type 
  1108. */ 
  1109. public static function number_format($price) { 
  1110. $decimals = 2; 
  1111. if (!self::currency_has_decimals(get_woocommerce_currency())) { 
  1112. $decimals = 0; 
  1113. return number_format($price, $decimals, '.', ''); 
  1114.  
  1115. public function angelleye_is_display_paypal_transaction_details($post_id) { 
  1116. $order = wc_get_order($post_id); 
  1117. $old_wc = version_compare(WC_VERSION, '3.0', '<'); 
  1118. $order_id = version_compare( WC_VERSION, '3.0', '<' ) ? $order->id : $order->get_id(); 
  1119. $_payment_method = $old_wc ? get_post_meta($order_id, '_payment_method', true) : get_post_meta($order->get_id(), '_payment_method', true); 
  1120. $_payment_action = $old_wc ? get_post_meta($order_id, '_payment_action', true) : get_post_meta($order->get_id(), '_payment_action', true); 
  1121. if (isset($_payment_method) && !empty($_payment_method) && isset($_payment_action) && !empty($_payment_action)) { 
  1122. if (($_payment_method == 'paypal_pro' || $_payment_method == 'paypal_express') && $_payment_method != "Sale") { 
  1123. return true; 
  1124. } else { 
  1125. return false; 
  1126. } else { 
  1127. return false; 
  1128.  
  1129. public static function is_valid_for_use_paypal_express() { 
  1130. return in_array( get_woocommerce_currency(), apply_filters( 'woocommerce_paypal_express_supported_currencies', array( 'AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP' ) ) ); 
  1131.  
  1132. public function angelleye_set_payment_method() { 
  1133. if( empty($this->payment_method) || $this->payment_method == false) { 
  1134. global $post; 
  1135. $old_wc = version_compare(WC_VERSION, '3.0', '<'); 
  1136. $order = wc_get_order($post->ID); 
  1137. $order_id = version_compare( WC_VERSION, '3.0', '<' ) ? $order->id : $order->get_id(); 
  1138. $this->payment_method = $old_wc ? get_post_meta($order_id, '_payment_method', true) : get_post_meta($order->get_id(), '_payment_method', true); 
  1139.  
  1140. public function angelleye_set_payment_method_using_transaction_id($transaction) { 
  1141. if( empty($this->payment_method) || $this->payment_method == false) { 
  1142. global $wpdb; 
  1143. $results = $wpdb->get_results( $wpdb->prepare( "SELECT post_id FROM {$wpdb->prefix}postmeta WHERE meta_value = %s ORDER BY meta_id", $transaction )); 
  1144. if( !empty($results[0]->post_id) ) { 
  1145. $old_wc = version_compare(WC_VERSION, '3.0', '<'); 
  1146. $order = wc_get_order($results[0]->post_id); 
  1147. $order_id = version_compare( WC_VERSION, '3.0', '<' ) ? $order->id : $order->get_id(); 
  1148. $this->payment_method = $old_wc ? get_post_meta($order_id, '_payment_method', true) : get_post_meta($order->get_id(), '_payment_method', true); 
  1149.  
  1150. public static function crypting( $string, $action = 'e' ) { 
  1151. $secret_key = AUTH_SALT; 
  1152. $secret_iv = SECURE_AUTH_SALT; 
  1153. $output = false; 
  1154. $encrypt_method = "AES-256-CBC"; 
  1155. $key = hash( 'sha256', $secret_key ); 
  1156. $iv = substr( hash( 'sha256', $secret_iv ), 0, 16 ); 
  1157. if( $action == 'e' ) { 
  1158. $output = base64_encode( openssl_encrypt( $string, $encrypt_method, $key, 0, $iv ) ); 
  1159. } else if ($action == 'd') { 
  1160. $output = openssl_decrypt( base64_decode( $string ), $encrypt_method, $key, 0, $iv ); 
  1161. return $output; 
  1162.  
  1163.  
  1164. public function angelleye_paypal_for_woocommerce_billing_agreement_details($order) { 
  1165. if (!is_object($order)) { 
  1166. $order = wc_get_order($order); 
  1167. $old_wc = version_compare(WC_VERSION, '3.0', '<'); 
  1168. $order_id = version_compare( WC_VERSION, '3.0', '<' ) ? $order->id : $order->get_id(); 
  1169. $billing_agreement_id = $old_wc ? get_post_meta($order_id, 'BILLINGAGREEMENTID', true) : get_post_meta($order->get_id(), 'BILLINGAGREEMENTID', true); 
  1170. if( empty($billing_agreement_id) ) { 
  1171. return false; 
  1172. ?> 
  1173. <h3> 
  1174. <?php _e( 'Billing Agreement Details', 'woocommerce' ); ?> 
  1175. </h3> 
  1176. <p> <?php echo $billing_agreement_id; ?></p> <?php  
  1177.  
  1178. public static function angelleye_paypal_for_woocommerce_is_set_sandbox_product() { 
  1179. $is_sandbox_set = false; 
  1180. if (isset(WC()->cart) && sizeof(WC()->cart->get_cart()) > 0) { 
  1181. foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { 
  1182. $product_id = apply_filters( 'woocommerce_cart_item_product_id', $cart_item['product_id'], $cart_item, $cart_item_key ); 
  1183. $_enable_sandbox_mode = get_post_meta($product_id, '_enable_sandbox_mode', true); 
  1184. if ($_enable_sandbox_mode == 'yes') { 
  1185. $is_sandbox_set = true; 
  1186. return $is_sandbox_set; 
  1187. return $is_sandbox_set; 
  1188.  
  1189. public static function angelleye_set_address( $order_id, $address, $type = 'billing' ) { 
  1190. foreach ( $address as $key => $value ) { 
  1191. update_post_meta( $order_id, "_{$type}_" . $key, $value ); 
  1192.  
  1193.