WC_Gateway_PayPal_Express_Request_AngellEYE

The PayPal for WooCommerce WC Gateway PayPal Express Request AngellEYE class.

Defined (1)

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

/angelleye-includes/express-checkout/class-wc-gateway-paypal-express-request-angelleye.php  
  1. class WC_Gateway_PayPal_Express_Request_AngellEYE { 
  2.  
  3. public $gateway; 
  4. public $gateway_calculation; 
  5. public $credentials; 
  6. public $paypal; 
  7. public $cart_param; 
  8. public $paypal_request; 
  9. public $paypal_response; 
  10. public $response_helper; 
  11. public $function_helper; 
  12. public $confirm_order_id; 
  13. public $order_param; 
  14. public $user_email_address; 
  15.  
  16. public function __construct($gateway) { 
  17. try { 
  18. $this->gateway = $gateway; 
  19. $this->skip_final_review = $this->gateway->get_option('skip_final_review', 'no'); 
  20. $this->billing_address = 'yes' === $this->gateway->get_option('billing_address', 'no'); 
  21. $this->disable_term = 'yes' === $this->gateway->get_option('disable_term', 'no'); 
  22. $this->save_abandoned_checkout = 'yes' === $this->gateway->get_option('save_abandoned_checkout', 'no'); 
  23. $this->softdescriptor = $this->gateway->get_option('softdescriptor', ''); 
  24. $this->testmode = 'yes' === $this->gateway->get_option('testmode', 'yes'); 
  25. $this->fraud_management_filters = $this->gateway->get_option('fraud_management_filters', 'place_order_on_hold_for_further_review'); 
  26. $this->email_notify_order_cancellations = $this->gateway->get_option('email_notify_order_cancellations', 'no'); 
  27. if ($this->testmode == false) { 
  28. $this->testmode = AngellEYE_Utility::angelleye_paypal_for_woocommerce_is_set_sandbox_product(); 
  29. if ($this->testmode == true) { 
  30. $this->API_Endpoint = "https://api-3t.sandbox.paypal.com/nvp"; 
  31. $this->PAYPAL_URL = "https://www.sandbox.paypal.com/webscr?cmd=_express-checkout&token="; 
  32. $this->api_username = $this->gateway->get_option('sandbox_api_username'); 
  33. $this->api_password = $this->gateway->get_option('sandbox_api_password'); 
  34. $this->api_signature = $this->gateway->get_option('sandbox_api_signature'); 
  35. } else { 
  36. $this->API_Endpoint = "https://api-3t.paypal.com/nvp"; 
  37. $this->PAYPAL_URL = "https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token="; 
  38. $this->api_username = $this->gateway->get_option('api_username'); 
  39. $this->api_password = $this->gateway->get_option('api_password'); 
  40. $this->api_signature = $this->gateway->get_option('api_signature'); 
  41. $this->Force_tls_one_point_two = get_option('Force_tls_one_point_two', 'no'); 
  42. $this->credentials = array( 
  43. 'Sandbox' => $this->testmode,  
  44. 'APIUsername' => $this->api_username,  
  45. 'APIPassword' => $this->api_password,  
  46. 'APISignature' => $this->api_signature,  
  47. 'Force_tls_one_point_two' => $this->gateway->Force_tls_one_point_two 
  48. ); 
  49. $this->angelleye_load_paypal_class(); 
  50. if (!class_exists('WC_Gateway_Calculation_AngellEYE')) { 
  51. require_once( PAYPAL_FOR_WOOCOMMERCE_PLUGIN_DIR . '/classes/wc-gateway-calculations-angelleye.php' ); 
  52. $this->gateway_calculation = new WC_Gateway_Calculation_AngellEYE(); 
  53. if (!class_exists('WC_Gateway_PayPal_Express_Response_AngellEYE')) { 
  54. require_once( PAYPAL_FOR_WOOCOMMERCE_PLUGIN_DIR . '/angelleye-includes/express-checkout/class-wc-gateway-paypal-express-response-angelleye.php' ); 
  55. $this->response_helper = new WC_Gateway_PayPal_Express_Response_AngellEYE(); 
  56. if (!class_exists('WC_Gateway_PayPal_Express_Function_AngellEYE')) { 
  57. require_once( PAYPAL_FOR_WOOCOMMERCE_PLUGIN_DIR . '/angelleye-includes/express-checkout/class-wc-gateway-paypal-express-function-angelleye.php' ); 
  58. $this->function_helper = new WC_Gateway_PayPal_Express_Function_AngellEYE(); 
  59. } catch (Exception $ex) { 
  60.  
  61.  
  62. public function angelleye_redirect() { 
  63. if (!empty($this->paypal_response['L_ERRORCODE0']) && $this->paypal_response['L_ERRORCODE0'] == '10486') { 
  64. $paypal_express_checkout = WC()->session->get('paypal_express_checkout'); 
  65. if( !empty($paypal_express_checkout['token'] ) ) { 
  66. $payPalURL = $this->PAYPAL_URL . $paypal_express_checkout['token']; 
  67. wp_redirect($payPalURL, 302); 
  68. exit; 
  69. }  
  70. unset(WC()->session->paypal_express_checkout); 
  71. if (!is_ajax()) { 
  72. wp_redirect(get_permalink(wc_get_page_id('cart'))); 
  73. exit; 
  74. } else { 
  75. $args = array( 
  76. 'result' => 'failure',  
  77. 'redirect' => get_permalink(wc_get_page_id('cart')),  
  78. ); 
  79. if ($this->function_helper->ec_is_version_gte_2_4()) { 
  80. wp_send_json($args); 
  81. } else { 
  82. echo '<!--WC_START-->' . json_encode($args) . '<!--WC_END-->'; 
  83.  
  84. public function angelleye_redirect_action($url) { 
  85. if (!empty($url)) { 
  86. if (!is_ajax()) { 
  87. wp_redirect($url); 
  88. exit; 
  89. } else { 
  90. $args = array( 
  91. 'result' => 'success',  
  92. 'redirect' => $url,  
  93. ); 
  94. wp_send_json($args); 
  95.  
  96. public function angelleye_set_express_checkout() { 
  97. try { 
  98. $this->angelleye_set_express_checkout_request(); 
  99. if ($this->response_helper->ec_is_response_success_or_successwithwarning($this->paypal_response)) { 
  100. $this->angelleye_redirect_action($this->paypal_response['REDIRECTURL']); 
  101. exit; 
  102. } else { 
  103. $this->angelleye_write_error_log_and_send_email_notification($paypal_action_name = 'SetExpressCheckout'); 
  104. $this->angelleye_redirect(); 
  105. } catch (Exception $ex) { 
  106.  
  107.  
  108. public function angelleye_get_express_checkout_details() { 
  109. try { 
  110. if (!isset($_GET['token'])) { 
  111. $this->angelleye_redirect(); 
  112. $token = esc_attr($_GET['token']); 
  113. $this->paypal_response = $this->paypal->GetExpresscheckoutDetails($token); 
  114. $this->angelleye_write_paypal_request_log($paypal_action_name = 'GetExpresscheckoutDetails'); 
  115. if ($this->response_helper->ec_is_response_success($this->paypal_response)) { 
  116. $paypal_express_checkout = array( 
  117. 'token' => $token,  
  118. 'shipping_details' => $this->response_helper->ec_get_shipping_details($this->paypal_response),  
  119. 'order_note' => $this->response_helper->ec_get_note_text($this->paypal_response),  
  120. 'payer_id' => $this->response_helper->ec_get_payer_id($this->paypal_response),  
  121. 'ExpresscheckoutDetails' => $this->paypal_response 
  122. ); 
  123. WC()->session->set('paypal_express_checkout', $paypal_express_checkout); 
  124. WC()->session->set('shiptoname', $this->paypal_response['FIRSTNAME'] . ' ' . $this->paypal_response['LASTNAME']); 
  125. WC()->session->set('payeremail', $this->paypal_response['EMAIL']); 
  126. WC()->session->set('chosen_payment_method', $this->gateway->id); 
  127. if ($this->angelleye_ec_force_to_display_checkout_page()) { 
  128. wp_redirect(WC()->cart->get_checkout_url()); 
  129. exit(); 
  130. $post_data = WC()->session->get('post_data'); 
  131. if(empty($post_data)) { 
  132. $this->angelleye_ec_load_customer_data_using_ec_details(); 
  133. } else { 
  134. $this->angelleye_write_error_log_and_send_email_notification($paypal_action_name = 'GetExpresscheckoutDetails'); 
  135. $this->angelleye_redirect(); 
  136. } catch (Exception $ex) { 
  137.  
  138.  
  139. public function angelleye_do_express_checkout_payment() { 
  140. try { 
  141. if (!isset($_GET['order_id'])) { 
  142. // todo need to redirect to cart page. 
  143. $this->confirm_order_id = esc_attr($_GET['order_id']); 
  144. $order = new WC_Order($this->confirm_order_id); 
  145. $old_wc = version_compare(WC_VERSION, '3.0', '<'); 
  146. $order_id = version_compare(WC_VERSION, '3.0', '<') ? $order->id : $order->get_id(); 
  147. if ($order->get_total() > 0) { 
  148. $this->angelleye_do_express_checkout_payment_request(); 
  149. } else { 
  150. $paypal_express_checkout = WC()->session->get('paypal_express_checkout'); 
  151. if(empty($paypal_express_checkout['token'])) { 
  152. $this->angelleye_redirect(); 
  153. $this->paypal_response = $this->paypal->CreateBillingAgreement($paypal_express_checkout['token']); 
  154. $this->angelleye_add_order_note($order); 
  155. $this->angelleye_add_extra_order_meta($order); 
  156. if ($this->gateway->payment_action != 'Sale') { 
  157. AngellEYE_Utility::angelleye_paypal_for_woocommerce_add_paypal_transaction($this->paypal_response, $order, $this->gateway->payment_action); 
  158. if ($this->response_helper->ec_is_response_success($this->paypal_response)) { 
  159. $this->angelleye_ec_get_customer_email_address($this->confirm_order_id); 
  160. $this->angelleye_ec_sellerprotection_handler($this->confirm_order_id); 
  161. update_post_meta($order_id, 'is_sandbox', $this->testmode); 
  162. if (empty($this->paypal_response['PAYMENTINFO_0_PAYMENTSTATUS'])) { 
  163. $this->paypal_response['PAYMENTINFO_0_PAYMENTSTATUS'] = ''; 
  164. if ($this->paypal_response['PAYMENTINFO_0_PAYMENTSTATUS'] == 'Completed') { 
  165. $order->payment_complete($this->paypal_response['PAYMENTINFO_0_TRANSACTIONID']); 
  166. } elseif (empty($this->paypal_response['PAYMENTINFO_0_PAYMENTSTATUS']) && !empty($this->paypal_response['BILLINGAGREEMENTID'])) { 
  167. $order->payment_complete($this->paypal_response['BILLINGAGREEMENTID']); 
  168. } else { 
  169. $this->update_payment_status_by_paypal_responce($this->confirm_order_id, $this->paypal_response); 
  170. if ($old_wc) { 
  171. update_post_meta($order_id, '_transaction_id', isset($this->paypal_response['PAYMENTINFO_0_TRANSACTIONID']) ? $this->paypal_response['PAYMENTINFO_0_TRANSACTIONID'] : ''); 
  172. } else { 
  173. update_post_meta($order->get_id(), '_transaction_id', isset($this->paypal_response['PAYMENTINFO_0_TRANSACTIONID']) ? $this->paypal_response['PAYMENTINFO_0_TRANSACTIONID'] : '' ); 
  174. if ($old_wc) { 
  175. $order->reduce_order_stock(); 
  176. } else { 
  177. wc_reduce_stock_levels($order->get_id()); 
  178. WC()->cart->empty_cart(); 
  179. if ($old_wc) { 
  180. update_post_meta($order_id, '_express_chekout_transactionid', isset($this->paypal_response['PAYMENTINFO_0_TRANSACTIONID']) ? $this->paypal_response['PAYMENTINFO_0_TRANSACTIONID'] : ''); 
  181. } else { 
  182. update_post_meta($order->get_id(), '_express_chekout_transactionid', isset($this->paypal_response['PAYMENTINFO_0_TRANSACTIONID']) ? $this->paypal_response['PAYMENTINFO_0_TRANSACTIONID'] : '' ); 
  183. $order->add_order_note(sprintf(__('%s payment approved! Trnsaction ID: %s', 'paypal-for-woocommerce'), $this->gateway->title, isset($this->paypal_response['PAYMENTINFO_0_TRANSACTIONID']) ? $this->paypal_response['PAYMENTINFO_0_TRANSACTIONID'] : '')); 
  184. $this->angelleye_ec_save_billing_agreement($order_id); 
  185. WC()->cart->empty_cart(); 
  186. wc_clear_notices(); 
  187. wp_redirect($this->gateway->get_return_url($order)); 
  188. exit(); 
  189. } elseif ($this->response_helper->ec_is_response_successwithwarning($this->paypal_response)) { 
  190. $this->angelleye_ec_get_customer_email_address($this->confirm_order_id); 
  191. $this->angelleye_ec_sellerprotection_handler($this->confirm_order_id); 
  192. if ($old_wc) { 
  193. update_post_meta($order_id, 'is_sandbox', $this->testmode); 
  194. } else { 
  195. update_post_meta($order->get_id(), 'is_sandbox', $this->testmode); 
  196.  
  197. if ($this->paypal_response['PAYMENTINFO_0_PAYMENTSTATUS'] == 'Completed') { 
  198. $order->payment_complete($this->paypal_response['PAYMENTINFO_0_TRANSACTIONID']); 
  199. } else { 
  200. if ($this->fraud_management_filters == 'place_order_on_hold_for_further_review' && (!empty($this->paypal_response['L_ERRORCODE0']) && $this->paypal_response['L_ERRORCODE0'] == '11610')) { 
  201. $error = !empty($this->paypal_response['L_LONGMESSAGE0']) ? $this->paypal_response['L_LONGMESSAGE0'] : $this->paypal_response['L_SHORTMESSAGE0']; 
  202. $order->update_status('on-hold', $error); 
  203. } else { 
  204. $this->update_payment_status_by_paypal_responce($this->confirm_order_id, $this->paypal_response); 
  205. if ($old_wc) { 
  206. update_post_meta($order_id, '_transaction_id', $this->paypal_response['PAYMENTINFO_0_TRANSACTIONID']); 
  207. } else { 
  208. update_post_meta($order->get_id(), '_transaction_id', $this->paypal_response['PAYMENTINFO_0_TRANSACTIONID']); 
  209.  
  210. if ($old_wc) { 
  211. $order->reduce_order_stock(); 
  212. } else { 
  213. wc_reduce_stock_levels($order->get_id()); 
  214. WC()->cart->empty_cart(); 
  215. if ($old_wc) { 
  216. update_post_meta($order_id, '_express_chekout_transactionid', isset($this->paypal_response['PAYMENTINFO_0_TRANSACTIONID']) ? $this->paypal_response['PAYMENTINFO_0_TRANSACTIONID'] : ''); 
  217. } else { 
  218. update_post_meta($order->get_id(), '_express_chekout_transactionid', isset($this->paypal_response['PAYMENTINFO_0_TRANSACTIONID']) ? $this->paypal_response['PAYMENTINFO_0_TRANSACTIONID'] : '' ); 
  219.  
  220. $order->add_order_note(sprintf(__('%s payment approved! Trnsaction ID: %s', 'paypal-for-woocommerce'), $this->gateway->title, $this->paypal_response['PAYMENTINFO_0_TRANSACTIONID'])); 
  221. $this->angelleye_ec_save_billing_agreement($order_id); 
  222. WC()->cart->empty_cart(); 
  223. wc_clear_notices(); 
  224. wp_redirect($this->gateway->get_return_url($order)); 
  225. exit(); 
  226. } else { 
  227. $this->angelleye_add_order_note_with_error($order, $paypal_action_name = 'DoExpressCheckoutPayment'); 
  228. $this->angelleye_write_error_log_and_send_email_notification($paypal_action_name = 'DoExpressCheckoutPayment'); 
  229. $this->angelleye_redirect(); 
  230. } catch (Exception $ex) { 
  231.  
  232.  
  233. public function angelleye_do_express_checkout_payment_request() { 
  234. try { 
  235. if (!empty($this->confirm_order_id)) { 
  236. $order = new WC_Order($this->confirm_order_id); 
  237. $customer_note_value = version_compare(WC_VERSION, '3.0', '<') ? wptexturize($order->customer_note) : wptexturize($order->get_customer_note()); 
  238. $customer_note = $customer_note_value ? substr(preg_replace("/[^A-Za-z0-9 ]/", "", $customer_note_value), 0, 256) : ''; 
  239. } else { 
  240.  
  241. $this->order_param = $this->gateway_calculation->order_calculation($this->confirm_order_id); 
  242. $paypal_express_checkout = WC()->session->get('paypal_express_checkout'); 
  243. if( empty($paypal_express_checkout['token'])) { 
  244. $this->angelleye_redirect(); 
  245. $DECPFields = array( 
  246. 'token' => $paypal_express_checkout['token'],  
  247. 'payerid' => (!empty($paypal_express_checkout['payer_id']) ) ? $paypal_express_checkout['payer_id'] : null,  
  248. 'returnfmfdetails' => 1,  
  249. 'buyermarketingemail' => '',  
  250. 'allowedpaymentmethod' => '' 
  251. ); 
  252. $Payments = array(); 
  253. $Payment = array( 
  254. 'amt' => AngellEYE_Gateway_Paypal::number_format($order->get_total()),  
  255. 'currencycode' => version_compare(WC_VERSION, '3.0', '<') ? $order->get_order_currency() : $order->get_currency(),  
  256. 'shippingdiscamt' => '',  
  257. 'insuranceoptionoffered' => '',  
  258. 'handlingamt' => '',  
  259. 'desc' => '',  
  260. 'custom' => apply_filters('ae_ppec_custom_parameter', json_encode(array('order_id' => version_compare(WC_VERSION, '3.0', '<') ? $order->id : $order->get_id(), 'order_key' => version_compare(WC_VERSION, '3.0', '<') ? $order->order_key : $order->get_order_key()))),  
  261. 'invnum' => $this->gateway->invoice_id_prefix . preg_replace("/[^a-zA-Z0-9]/", "", str_replace("#", "", $order->get_order_number())),  
  262. 'notetext' => !empty($customer_notes) ? $customer_notes : '',  
  263. 'allowedpaymentmethod' => '',  
  264. 'paymentaction' => ($this->gateway->payment_action == 'Authorization' || $order->get_total() == 0 ) ? 'Authorization' : $this->gateway->payment_action,  
  265. 'paymentrequestid' => '',  
  266. 'sellerpaypalaccountid' => '',  
  267. 'sellerid' => '',  
  268. 'sellerusername' => '',  
  269. 'sellerregistrationdate' => '',  
  270. 'softdescriptor' => $this->softdescriptor 
  271. ); 
  272. if (isset($this->gateway->notifyurl) && !empty($this->gateway->notifyurl)) { 
  273. $Payment['notifyurl'] = $this->gateway->notifyurl; 
  274. if ($this->gateway->send_items) { 
  275. $Payment['order_items'] = $this->order_param['order_items']; 
  276. } else { 
  277. $Payment['order_items'] = array(); 
  278. $Payment['taxamt'] = AngellEYE_Gateway_Paypal::number_format($this->order_param['taxamt']); 
  279. $Payment['shippingamt'] = AngellEYE_Gateway_Paypal::number_format($this->order_param['shippingamt']); 
  280. $Payment['itemamt'] = AngellEYE_Gateway_Paypal::number_format($this->order_param['itemamt']); 
  281.  
  282. $REVIEW_RESULT = !empty($paypal_express_checkout['ExpresscheckoutDetails']) ? $paypal_express_checkout['ExpresscheckoutDetails'] : array(); 
  283. $PaymentRedeemedOffers = array(); 
  284. if ((isset($REVIEW_RESULT) && !empty($REVIEW_RESULT)) && isset($REVIEW_RESULT['WALLETTYPE0'])) { 
  285. $i = 0; 
  286. while (isset($REVIEW_RESULT['WALLETTYPE' . $i])) { 
  287. $RedeemedOffer = array( 
  288. 'redeemedoffername' => $REVIEW_RESULT['WALLETDESCRIPTION' . $i],  
  289. 'redeemedofferdescription' => '',  
  290. 'redeemedofferamount' => '',  
  291. 'redeemedoffertype' => $REVIEW_RESULT['WALLETTYPE' . $i],  
  292. 'redeemedofferid' => $REVIEW_RESULT['WALLETID' . $i],  
  293. 'redeemedofferpointsaccrued' => '',  
  294. 'cummulativepointsname' => '',  
  295. 'cummulativepointsdescription' => '',  
  296. 'cummulativepointstype' => '',  
  297. 'cummulativepointsid' => '',  
  298. 'cummulativepointsaccrued' => '',  
  299. ); 
  300. $i = $i + 1; 
  301. array_push($PaymentRedeemedOffers, $RedeemedOffer); 
  302. $Payment['redeemed_offers'] = $PaymentRedeemedOffers; 
  303. array_push($Payments, $Payment); 
  304. } else { 
  305. array_push($Payments, $Payment); 
  306. if (WC()->cart->needs_shipping()) { 
  307. $shipping_first_name = version_compare(WC_VERSION, '3.0', '<') ? $order->shipping_first_name : $order->get_shipping_first_name(); 
  308. $shipping_last_name = version_compare(WC_VERSION, '3.0', '<') ? $order->shipping_last_name : $order->get_shipping_last_name(); 
  309. $shipping_address_1 = version_compare(WC_VERSION, '3.0', '<') ? $order->shipping_address_1 : $order->get_shipping_address_1(); 
  310. $shipping_address_2 = version_compare(WC_VERSION, '3.0', '<') ? $order->shipping_address_2 : $order->get_shipping_address_2(); 
  311. $shipping_city = version_compare(WC_VERSION, '3.0', '<') ? $order->shipping_city : $order->get_shipping_city(); 
  312. $shipping_state = version_compare(WC_VERSION, '3.0', '<') ? $order->shipping_state : $order->get_shipping_state(); 
  313. $shipping_postcode = version_compare(WC_VERSION, '3.0', '<') ? $order->shipping_postcode : $order->get_shipping_postcode(); 
  314. $shipping_country = version_compare(WC_VERSION, '3.0', '<') ? $order->shipping_country : $order->get_shipping_country(); 
  315. $Payment = array('shiptoname' => $shipping_first_name . ' ' . $shipping_last_name,  
  316. 'shiptostreet' => $shipping_address_1,  
  317. 'shiptostreet2' => $shipping_address_2,  
  318. 'shiptocity' => wc_clean(stripslashes($shipping_city)),  
  319. 'shiptostate' => $shipping_state,  
  320. 'shiptozip' => $shipping_postcode,  
  321. 'shiptocountrycode' => $shipping_country,  
  322. 'shiptophonenum' => isset($paypal_express_checkout['billing_phone']) ? $paypal_express_checkout['billing_phone'] : '',  
  323. ); 
  324. array_push($Payments, $Payment); 
  325. $this->paypal_request = array( 
  326. 'DECPFields' => $DECPFields,  
  327. 'Payments' => $Payments 
  328. ); 
  329. $this->paypal_response = $this->paypal->DoExpressCheckoutPayment(apply_filters('angelleye_woocommerce_express_checkout_do_express_checkout_payment_request_args', $this->paypal_request)); 
  330. $this->angelleye_write_paypal_request_log($paypal_action_name = 'DoExpressCheckoutPayment'); 
  331. } catch (Exception $ex) { 
  332.  
  333.  
  334. public function angelleye_load_paypal_class() { 
  335. try { 
  336. if (!class_exists('Angelleye_PayPal')) { 
  337. require_once( PAYPAL_FOR_WOOCOMMERCE_PLUGIN_DIR . '/classes/lib/angelleye/paypal-php-library/includes/paypal.class.php' ); 
  338. $this->paypal = new Angelleye_PayPal($this->credentials); 
  339. } catch (Exception $ex) { 
  340.  
  341.  
  342. public function angelleye_set_express_checkout_request() { 
  343. try { 
  344. $Payments = array(); 
  345. $cancel_url = !empty($this->gateway->cancel_page_id) ? get_permalink($this->gateway->cancel_page_id) : WC()->cart->get_cart_url(); 
  346. $this->cart_param = $this->gateway_calculation->cart_calculation(); 
  347. $SECFields = array( 
  348. 'maxamt' => '',  
  349. 'returnurl' => urldecode(add_query_arg('pp_action', 'get_express_checkout_details', WC()->api_request_url('WC_Gateway_PayPal_Express_AngellEYE'))),  
  350. 'cancelurl' => urldecode($cancel_url),  
  351. 'callback' => '',  
  352. 'callbacktimeout' => '',  
  353. 'callbackversion' => '',  
  354. 'reqconfirmshipping' => '',  
  355. 'noshipping' => '',  
  356. 'allownote' => 1,  
  357. 'addroverride' => '',  
  358. 'localecode' => ($this->gateway->use_wp_locale_code == 'yes' && get_locale() != '') ? get_locale() : '',  
  359. 'pagestyle' => $this->gateway->page_style,  
  360. 'hdrimg' => $this->gateway->checkout_logo_hdrimg,  
  361. 'logoimg' => $this->gateway->checkout_logo,  
  362. 'hdrbordercolor' => '',  
  363. 'hdrbackcolor' => '',  
  364. 'payflowcolor' => '',  
  365. 'skipdetails' => $this->angelleye_ec_force_to_display_checkout_page() == true ? '0' : '1',  
  366. 'email' => '',  
  367. 'channeltype' => '',  
  368. 'giropaysuccessurl' => '',  
  369. 'giropaycancelurl' => '',  
  370. 'banktxnpendingurl' => '',  
  371. 'brandname' => wc_clean(stripslashes($this->gateway->brand_name)),  
  372. 'customerservicenumber' => $this->gateway->customer_service_number,  
  373. 'buyeremailoptionenable' => '',  
  374. 'surveyquestion' => '',  
  375. 'surveyenable' => '',  
  376. 'totaltype' => '',  
  377. 'notetobuyer' => '',  
  378. 'buyerid' => '',  
  379. 'buyerusername' => '',  
  380. 'buyerregistrationdate' => '',  
  381. 'allowpushfunding' => '',  
  382. 'taxidtype' => '',  
  383. 'taxid' => '' 
  384. ); 
  385. $usePayPalCredit = (!empty($_GET['use_paypal_credit']) && $_GET['use_paypal_credit'] == true) ? true : false; 
  386. if ($usePayPalCredit) { 
  387. $SECFields['solutiontype'] = 'Sole'; 
  388. $SECFields['landingpage'] = 'Billing'; 
  389. $SECFields['userselectedfundingsource'] = 'BML'; 
  390. } elseif (strtolower($this->gateway->paypal_account_optional) == 'yes' && strtolower($this->gateway->landing_page) == 'billing') { 
  391. $SECFields['solutiontype'] = 'Sole'; 
  392. $SECFields['landingpage'] = 'Billing'; 
  393. $SECFields['userselectedfundingsource'] = 'CreditCard'; 
  394. } elseif (strtolower($this->gateway->paypal_account_optional) == 'yes' && strtolower($this->gateway->landing_page) == 'login') { 
  395. $SECFields['solutiontype'] = 'Sole'; 
  396. $SECFields['landingpage'] = 'Login'; 
  397.  
  398. $SECFields = $this->function_helper->angelleye_paypal_for_woocommerce_needs_shipping($SECFields); 
  399. $Payment = array( 
  400. 'amt' => AngellEYE_Gateway_Paypal::number_format(WC()->cart->total),  
  401. 'currencycode' => get_woocommerce_currency(),  
  402. 'custom' => apply_filters('ae_ppec_custom_parameter', ''),  
  403. 'notetext' => '',  
  404. 'paymentaction' => ($this->gateway->payment_action == 'Authorization' || WC()->cart->total == 0 ) ? 'Authorization' : $this->gateway->payment_action,  
  405. ); 
  406. $post_data = WC()->session->get('post_data'); 
  407. if (!empty($post_data) && WC()->cart->needs_shipping()) { 
  408. $SECFields['addroverride'] = 1; 
  409. if ($post_data['ship_to_different_address']) { 
  410. $Payment['shiptoname'] = $post_data['shipping_first_name'] . ' ' . $post_data['shipping_last_name']; 
  411. $Payment['shiptostreet'] = $post_data['shipping_address_1']; 
  412. $Payment['shiptostreet2'] = $post_data['shipping_address_2']; 
  413. $Payment['shiptocity'] = wc_clean(stripslashes($post_data['shipping_city'])); 
  414. $Payment['shiptostate'] = $post_data['shipping_state']; 
  415. $Payment['shiptozip'] = $post_data['shipping_postcode']; 
  416. $Payment['shiptocountrycode'] = $post_data['shipping_country']; 
  417. } else { 
  418. $Payment['shiptoname'] = $post_data['billing_first_name'] . ' ' . $post_data['billing_last_name']; 
  419. $Payment['shiptostreet'] = $post_data['billing_address_1']; 
  420. $Payment['shiptostreet2'] = $post_data['billing_address_2']; 
  421. $Payment['shiptocity'] = wc_clean(stripslashes($post_data['billing_city'])); 
  422. $Payment['shiptostate'] = $post_data['billing_state']; 
  423. $Payment['shiptozip'] = $post_data['billing_postcode']; 
  424. $Payment['shiptocountrycode'] = $post_data['billing_country']; 
  425. $Payment['shiptophonenum'] = $post_data['billing_phone']; 
  426. } elseif (is_user_logged_in()) { 
  427. if (version_compare(WC_VERSION, '3.0', '<')) { 
  428. $firstname = WC()->customer->firstname; 
  429. } else { 
  430. $firstname = WC()->customer->get_shipping_first_name(); 
  431. if (version_compare(WC_VERSION, '3.0', '<')) { 
  432. $lastname = WC()->customer->lastname; 
  433. } else { 
  434. $lastname = WC()->customer->get_shipping_last_name(); 
  435. $shiptostreet = WC()->customer->get_shipping_address(); 
  436. $shiptostreet_two = WC()->customer->get_shipping_address_2(); 
  437. $shipping_city = WC()->customer->get_shipping_city(); 
  438. $shipping_country = WC()->customer->get_shipping_country(); 
  439. $shipping_state = WC()->customer->get_shipping_state(); 
  440. $shipping_postcode = WC()->customer->get_shipping_postcode(); 
  441. if (version_compare(WC_VERSION, '3.0', '<')) { 
  442. $billing_shiptostreet = WC()->customer->get_address(); 
  443. $billing_shiptostreet_two = WC()->customer->get_address_2(); 
  444. $billing_city = WC()->customer->get_city(); 
  445. $billing_country = WC()->customer->get_country(); 
  446. $billing_state = WC()->customer->get_state(); 
  447. $billing_postcode = WC()->customer->get_postcode(); 
  448. $billing_phone = ''; 
  449. } else { 
  450. $billing_shiptostreet = WC()->customer->get_billing_address_1(); 
  451. $billing_shiptostreet_two = WC()->customer->get_billing_address_2(); 
  452. $billing_city = WC()->customer->get_billing_city(); 
  453. $billing_country = WC()->customer->get_billing_country(); 
  454. $billing_state = WC()->customer->get_billing_state(); 
  455. $billing_postcode = WC()->customer->get_billing_postcode(); 
  456. $billing_phone = WC()->customer->get_billing_phone(); 
  457. $Payment['shiptoname'] = $firstname . ' ' . $lastname; 
  458. $Payment['shiptostreet'] = !empty($shiptostreet) ? wc_clean(stripslashes($shiptostreet)) : wc_clean(stripslashes($billing_shiptostreet)); 
  459. $Payment['shiptostreet2'] = !empty($shiptostreet_two) ? wc_clean(stripslashes($shiptostreet_two)) : wc_clean(stripslashes($billing_shiptostreet_two)); 
  460. $Payment['shiptocity'] = !empty($shipping_city) ? wc_clean(stripslashes($shipping_city)) : wc_clean(stripslashes($billing_city)); 
  461. $Payment['shiptostate'] = !empty($shipping_state) ? wc_clean(stripslashes($shipping_state)) : wc_clean(stripslashes($billing_state)); 
  462. $Payment['shiptozip'] = !empty($shipping_postcode) ? wc_clean(stripslashes($shipping_postcode)) : wc_clean(stripslashes($billing_postcode)); 
  463. $Payment['shiptocountrycode'] = !empty($shipping_country) ? wc_clean(stripslashes($shipping_country)) : wc_clean(stripslashes($billing_country)); 
  464. $Payment['shiptophonenum'] = !empty($billing_phone) ? wc_clean(stripslashes($billing_phone)) : ''; 
  465. if ($this->gateway->send_items) { 
  466. $Payment['order_items'] = $this->cart_param['order_items']; 
  467. } else { 
  468. $Payment['order_items'] = array(); 
  469. $Payment['taxamt'] = $this->cart_param['taxamt']; 
  470. $Payment['shippingamt'] = $this->cart_param['shippingamt']; 
  471. $Payment['itemamt'] = $this->cart_param['itemamt']; 
  472. array_push($Payments, $Payment); 
  473. $PayPalRequestData = array( 
  474. 'SECFields' => $SECFields,  
  475. 'Payments' => $Payments,  
  476. ); 
  477. $this->paypal_request = $this->angelleye_add_billing_agreement_param($PayPalRequestData, $this->gateway->supports('tokenization')); 
  478. $this->paypal_response = $this->paypal->SetExpressCheckout(apply_filters('angelleye_woocommerce_express_checkout_set_express_checkout_request_args', $this->paypal_request)); 
  479. $this->angelleye_write_paypal_request_log($paypal_action_name = 'SetExpressCheckout'); 
  480. return $this->paypal_response; 
  481. } catch (Exception $ex) { 
  482.  
  483.  
  484. public function angelleye_add_billing_agreement_param($PayPalRequestData, $tokenization) { 
  485. try { 
  486. if (sizeof(WC()->cart->get_cart()) != 0) { 
  487. foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) { 
  488. $product_id = apply_filters('woocommerce_cart_item_product_id', $cart_item['product_id'], $cart_item, $cart_item_key); 
  489. $_paypal_billing_agreement = get_post_meta($product_id, '_paypal_billing_agreement', true); 
  490. $ec_save_to_account = WC()->session->get('ec_save_to_account'); 
  491. if ($_paypal_billing_agreement == 'yes' || ( isset($ec_save_to_account) && $ec_save_to_account == 'on')) { 
  492. $BillingAgreements = array(); 
  493. $Item = array( 
  494. 'l_billingtype' => '',  
  495. 'l_billingtype' => 'MerchantInitiatedBilling',  
  496. 'l_billingagreementdescription' => '',  
  497. 'l_paymenttype' => '',  
  498. 'l_paymenttype' => 'Any',  
  499. 'l_billingagreementcustom' => '' 
  500. ); 
  501. array_push($BillingAgreements, $Item); 
  502. $PayPalRequestData['BillingAgreements'] = $BillingAgreements; 
  503. return $PayPalRequestData; 
  504. return $PayPalRequestData; 
  505. } catch (Exception $ex) { 
  506.  
  507.  
  508. public function update_payment_status_by_paypal_responce($orderid, $result) { 
  509. try { 
  510. $order = wc_get_order($orderid); 
  511. switch (strtolower($result['PAYMENTINFO_0_PAYMENTSTATUS'])) : 
  512. case 'completed' : 
  513. if ($order->status == 'completed') { 
  514. break; 
  515. if (!in_array(strtolower($result['PAYMENTINFO_0_TRANSACTIONTYPE']), array('cart', 'instant', 'express_checkout', 'web_accept', 'masspay', 'send_money'))) { 
  516. break; 
  517. $order->add_order_note(__('Payment Completed via Express Checkout', 'paypal-for-woocommerce')); 
  518. $order->payment_complete($result['PAYMENTINFO_0_TRANSACTIONID']); 
  519. break; 
  520. case 'pending' : 
  521. if (!in_array(strtolower($result['PAYMENTINFO_0_TRANSACTIONTYPE']), array('cart', 'instant', 'express_checkout', 'web_accept', 'masspay', 'send_money'))) { 
  522. break; 
  523. switch (strtolower($result['PAYMENTINFO_0_PENDINGREASON'])) { 
  524. case 'address': 
  525. $pending_reason = __('Address: The payment is pending because your customer did not include a confirmed shipping address and your Payment Receiving Preferences is set such that you want to manually accept or deny each of these payments. To change your preference, go to the Preferences section of your Profile.', 'paypal-for-woocommerce'); 
  526. break; 
  527. case 'authorization': 
  528. $pending_reason = __('Authorization: The payment is pending because it has been authorized but not settled. You must capture the funds first.', 'paypal-for-woocommerce'); 
  529. break; 
  530. case 'echeck': 
  531. $pending_reason = __('eCheck: The payment is pending because it was made by an eCheck that has not yet cleared.', 'paypal-for-woocommerce'); 
  532. break; 
  533. case 'intl': 
  534. $pending_reason = __('intl: The payment is pending because you hold a non-U.S. account and do not have a withdrawal mechanism. You must manually accept or deny this payment from your Account Overview.', 'paypal-for-woocommerce'); 
  535. break; 
  536. case 'multicurrency': 
  537. case 'multi-currency': 
  538. $pending_reason = __('Multi-currency: You do not have a balance in the currency sent, and you do not have your Payment Receiving Preferences set to automatically convert and accept this payment. You must manually accept or deny this payment.', 'paypal-for-woocommerce'); 
  539. break; 
  540. case 'order': 
  541. $pending_reason = __('Order: The payment is pending because it is part of an order that has been authorized but not settled.', 'paypal-for-woocommerce'); 
  542. break; 
  543. case 'paymentreview': 
  544. $pending_reason = __('Payment Review: The payment is pending while it is being reviewed by PayPal for risk.', 'paypal-for-woocommerce'); 
  545. break; 
  546. case 'unilateral': 
  547. $pending_reason = __('Unilateral: The payment is pending because it was made to an email address that is not yet registered or confirmed.', 'paypal-for-woocommerce'); 
  548. break; 
  549. case 'verify': 
  550. $pending_reason = __('Verify: The payment is pending because you are not yet verified. You must verify your account before you can accept this payment.', 'paypal-for-woocommerce'); 
  551. break; 
  552. case 'other': 
  553. $pending_reason = __('Other: For more information, contact PayPal customer service.', 'paypal-for-woocommerce'); 
  554. break; 
  555. case 'none': 
  556. default: 
  557. $pending_reason = __('No pending reason provided.', 'paypal-for-woocommerce'); 
  558. break; 
  559. $order->add_order_note(sprintf(__('Payment via Express Checkout Pending. PayPal reason: %s.', 'paypal-for-woocommerce'), $pending_reason)); 
  560. $order->update_status('on-hold'); 
  561. break; 
  562. case 'denied' : 
  563. case 'expired' : 
  564. case 'failed' : 
  565. case 'voided' : 
  566. $order->update_status('failed', sprintf(__('Payment %s via Express Checkout.', 'paypal-for-woocommerce'), strtolower($result['PAYMENTINFO_0_PAYMENTSTATUS']))); 
  567. break; 
  568. default: 
  569. break; 
  570. endswitch; 
  571. return; 
  572. } catch (Exception $ex) { 
  573.  
  574.  
  575. public function angelleye_add_extra_order_meta($order) { 
  576. $order_id = version_compare(WC_VERSION, '3.0', '<') ? $order->id : $order->get_id(); 
  577. if (!empty($this->gateway->payment_action) && $this->gateway->payment_action != 'Sale') { 
  578. $paypal_express_checkout = WC()->session->get('paypal_express_checkout'); 
  579. $payment_order_meta = array('_transaction_id' => $this->paypal_response['PAYMENTINFO_0_TRANSACTIONID'], '_payment_action' => $this->gateway->payment_action, '_express_checkout_token' => $paypal_express_checkout['token'], '_first_transaction_id' => $this->paypal_response['PAYMENTINFO_0_TRANSACTIONID']); 
  580. AngellEYE_Utility::angelleye_add_order_meta($order_id, $payment_order_meta); 
  581.  
  582. public function angelleye_add_order_note($order) { 
  583. $paypal_express_checkout = WC()->session->get('paypal_express_checkout'); 
  584. if (!empty($paypal_express_checkout['ExpresscheckoutDetails']['PAYERSTATUS'])) { 
  585. $order->add_order_note(sprintf(__('Payer Status: %s', 'paypal-for-woocommerce'), '<strong>' . $paypal_express_checkout['ExpresscheckoutDetails']['PAYERSTATUS'] . '</strong>')); 
  586. if (!empty($paypal_express_checkout['ExpresscheckoutDetails']['ADDRESSSTATUS'])) { 
  587. $order->add_order_note(sprintf(__('Address Status: %s', 'paypal-for-woocommerce'), '<strong>' . $paypal_express_checkout['ExpresscheckoutDetails']['ADDRESSSTATUS'] . '</strong>')); 
  588.  
  589. public function angelleye_add_order_note_with_error($order, $paypal_action_name = null) { 
  590. if (!empty($this->paypal_response['L_ERRORCODE0'])) { 
  591. $ErrorCode = urldecode($this->paypal_response['L_ERRORCODE0']); 
  592. } else { 
  593. $ErrorCode = ''; 
  594. if (!empty($this->paypal_response['L_SHORTMESSAGE0'])) { 
  595. $ErrorShortMsg = urldecode($this->paypal_response['L_SHORTMESSAGE0']); 
  596. } else { 
  597. $ErrorShortMsg = ''; 
  598. if (!empty($this->paypal_response['L_LONGMESSAGE0'])) { 
  599. $ErrorLongMsg = urldecode($this->paypal_response['L_LONGMESSAGE0']); 
  600. } else { 
  601. $ErrorLongMsg = ''; 
  602. if (!empty($this->paypal_response['L_SEVERITYCODE0'])) { 
  603. $ErrorSeverityCode = urldecode($this->paypal_response['L_SEVERITYCODE0']); 
  604. } else { 
  605. $ErrorSeverityCode = ''; 
  606. $order->add_order_note(sprintf(__('PayPal %s API call failed:', 'woocommerce') . __('Detailed Error Message:', 'woocommerce') . PHP_EOL . __('Short Error Message:', 'woocommerce') . PHP_EOL . __('Error Code:', 'woocommerce') . PHP_EOL . __('Error Severity Code:', 'woocommerce'), $paypal_action_name, $ErrorLongMsg, $ErrorShortMsg, $ErrorCode, $ErrorSeverityCode)); 
  607.  
  608. public function angelleye_write_error_log_and_send_email_notification($paypal_action_name) { 
  609. if (!empty($this->paypal_response['L_ERRORCODE0'])) { 
  610. $ErrorCode = urldecode($this->paypal_response['L_ERRORCODE0']); 
  611. } else { 
  612. $ErrorCode = ''; 
  613. if (!empty($this->paypal_response['L_SHORTMESSAGE0'])) { 
  614. $ErrorShortMsg = urldecode($this->paypal_response['L_SHORTMESSAGE0']); 
  615. } else { 
  616. $ErrorShortMsg = ''; 
  617. if (!empty($this->paypal_response['L_LONGMESSAGE0'])) { 
  618. $ErrorLongMsg = urldecode($this->paypal_response['L_LONGMESSAGE0']); 
  619. } else { 
  620. $ErrorLongMsg = ''; 
  621. if (!empty($this->paypal_response['L_SEVERITYCODE0'])) { 
  622. $ErrorSeverityCode = urldecode($this->paypal_response['L_SEVERITYCODE0']); 
  623. } else { 
  624. $ErrorSeverityCode = ''; 
  625. if ($this->gateway->error_email_notify) { 
  626. $mailer = WC()->mailer(); 
  627. $error_email_notify_subject = apply_filters('ae_ppec_error_email_subject', 'PayPal Express Checkout Error Notification'); 
  628. $message = sprintf(__('PayPal %s API call failed', 'woocommerce') . PHP_EOL . __('Detailed Error Message: %s', 'woocommerce') . PHP_EOL . __('Short Error Message: %s', 'woocommerce') . PHP_EOL . __('Error Code: %s', 'woocommerce') . PHP_EOL . __('Error Severity Code: %s', 'woocommerce'), $paypal_action_name, $ErrorLongMsg, $ErrorShortMsg, $ErrorCode, $ErrorSeverityCode); 
  629. $message = apply_filters('ae_ppec_error_email_message', $message, $ErrorCode, $ErrorSeverityCode, $ErrorShortMsg, $ErrorLongMsg); 
  630. $message = $mailer->wrap_message($error_email_notify_subject, $message); 
  631. $mailer->send(get_option('admin_email'), strip_tags($error_email_notify_subject), $message); 
  632. if ($this->gateway->error_display_type == 'detailed') { 
  633. $sec_error_notice = $ErrorCode . ' - ' . $ErrorLongMsg; 
  634. $error_display_type_message = sprintf(__($sec_error_notice, 'paypal-for-woocommerce')); 
  635. } else { 
  636. $error_display_type_message = sprintf(__('There was a problem paying with PayPal. Please try another method.', 'paypal-for-woocommerce')); 
  637. $error_display_type_message = apply_filters('ae_ppec_error_user_display_message', $error_display_type_message, $ErrorCode, $ErrorLongMsg); 
  638. wc_add_notice($error_display_type_message, 'error'); 
  639.  
  640. public function angelleye_write_paypal_request_log($paypal_action_name) { 
  641. if ($paypal_action_name == 'SetExpressCheckout') { 
  642. WC_Gateway_PayPal_Express_AngellEYE::log('Redirecting to PayPal'); 
  643. WC_Gateway_PayPal_Express_AngellEYE::log(sprintf(__('PayPal for WooCommerce Version: %s', 'paypal-for-woocommerce'), VERSION_PFW)); 
  644. WC_Gateway_PayPal_Express_AngellEYE::log(sprintf(__('WooCommerce Version: %s', 'paypal-for-woocommerce'), WC_VERSION)); 
  645. WC_Gateway_PayPal_Express_AngellEYE::log('Test Mode: ' . $this->testmode); 
  646. WC_Gateway_PayPal_Express_AngellEYE::log('Endpoint: ' . $this->gateway->API_Endpoint); 
  647. $PayPalRequest = isset($this->paypal_response['RAWREQUEST']) ? $this->paypal_response['RAWREQUEST'] : ''; 
  648. $PayPalResponse = isset($this->paypal_response['RAWRESPONSE']) ? $this->paypal_response['RAWRESPONSE'] : ''; 
  649. WC_Gateway_PayPal_Express_AngellEYE::log($paypal_action_name . ' Request: ' . print_r($this->paypal->NVPToArray($this->paypal->MaskAPIResult($PayPalRequest)), true)); 
  650. WC_Gateway_PayPal_Express_AngellEYE::log($paypal_action_name . ' Response: ' . print_r($this->paypal->NVPToArray($this->paypal->MaskAPIResult($PayPalResponse)), true)); 
  651.  
  652. public function angelleye_ec_load_customer_data_using_ec_details() { 
  653. if (!empty($this->paypal_response['SHIPTOCOUNTRYCODE'])) { 
  654. if (!array_key_exists($this->paypal_response['SHIPTOCOUNTRYCODE'], WC()->countries->get_allowed_countries())) { 
  655. wc_add_notice(sprintf(__('We do not sell in your country, please try again with another address.', 'paypal-for-woocommerce')), 'error'); 
  656. wp_redirect(get_permalink(wc_get_page_id('cart'))); 
  657. exit; 
  658. if (isset($this->paypal_response['FIRSTNAME'])) { 
  659. if (version_compare(WC_VERSION, '3.0', '<')) { 
  660. WC()->customer->firstname = $this->paypal_response['FIRSTNAME']; 
  661. } else { 
  662. WC()->customer->set_shipping_first_name($this->paypal_response['FIRSTNAME']); 
  663. if (isset($this->paypal_response['LASTNAME'])) { 
  664. if (version_compare(WC_VERSION, '3.0', '<')) { 
  665. WC()->customer->lastname = $this->paypal_response['LASTNAME']; 
  666. } else { 
  667. WC()->customer->set_shipping_last_name($this->paypal_response['LASTNAME']); 
  668. if (isset($this->paypal_response['SHIPTOSTREET'])) { 
  669. WC()->customer->set_shipping_address($this->paypal_response['SHIPTOSTREET']); 
  670. if (isset($this->paypal_response['SHIPTOSTREET2'])) { 
  671. WC()->customer->set_shipping_address_2($this->paypal_response['SHIPTOSTREET2']); 
  672. if (isset($this->paypal_response['SHIPTOCITY'])) { 
  673. WC()->customer->set_shipping_city($this->paypal_response['SHIPTOCITY']); 
  674. if (isset($this->paypal_response['SHIPTOCOUNTRYCODE'])) { 
  675. WC()->customer->set_shipping_country($this->paypal_response['SHIPTOCOUNTRYCODE']); 
  676. if (isset($this->paypal_response['SHIPTOSTATE'])) { 
  677. WC()->customer->set_shipping_state($this->get_state_code($this->paypal_response['SHIPTOCOUNTRYCODE'], $this->paypal_response['SHIPTOSTATE'])); 
  678. if (isset($this->paypal_response['SHIPTOZIP'])) { 
  679. WC()->customer->set_shipping_postcode($this->paypal_response['SHIPTOZIP']); 
  680.  
  681. if (version_compare(WC_VERSION, '3.0', '<')) { 
  682. if ($this->billing_address) { 
  683. if (isset($this->paypal_response['SHIPTOSTREET'])) { 
  684. WC()->customer->set_address($this->paypal_response['SHIPTOSTREET']); 
  685. if (isset($this->paypal_response['SHIPTOSTREET2'])) { 
  686. WC()->customer->set_address_2($this->paypal_response['SHIPTOSTREET2']); 
  687. if (isset($this->paypal_response['SHIPTOCITY'])) { 
  688. WC()->customer->set_city($this->paypal_response['SHIPTOCITY']); 
  689. if (isset($this->paypal_response['SHIPTOCOUNTRYCODE'])) { 
  690. WC()->customer->set_country($this->paypal_response['SHIPTOCOUNTRYCODE']); 
  691. if (isset($this->paypal_response['SHIPTOSTATE'])) { 
  692. WC()->customer->set_state($this->get_state_code($this->paypal_response['SHIPTOCOUNTRYCODE'], $this->paypal_response['SHIPTOSTATE'])); 
  693. if (isset($this->paypal_response['SHIPTOZIP'])) { 
  694. WC()->customer->set_postcode($this->paypal_response['SHIPTOZIP']); 
  695. WC()->customer->calculated_shipping(true); 
  696. } else { 
  697. if ($this->billing_address) { 
  698. if (isset($this->paypal_response['SHIPTOSTREET'])) { 
  699. WC()->customer->set_billing_address_1($this->paypal_response['SHIPTOSTREET']); 
  700. if (isset($this->paypal_response['SHIPTOSTREET2'])) { 
  701. WC()->customer->set_billing_address_2($this->paypal_response['SHIPTOSTREET2']); 
  702. if (isset($this->paypal_response['SHIPTOCITY'])) { 
  703. WC()->customer->set_billing_city($this->paypal_response['SHIPTOCITY']); 
  704. if (isset($this->paypal_response['SHIPTOCOUNTRYCODE'])) { 
  705. WC()->customer->set_billing_country($this->paypal_response['SHIPTOCOUNTRYCODE']); 
  706. if (isset($this->paypal_response['SHIPTOSTATE'])) { 
  707. WC()->customer->set_billing_state($this->get_state_code($this->paypal_response['SHIPTOCOUNTRYCODE'], $this->paypal_response['SHIPTOSTATE'])); 
  708. if (isset($this->paypal_response['SHIPTOZIP'])) { 
  709. WC()->customer->set_billing_postcode($this->paypal_response['SHIPTOZIP']); 
  710. WC()->customer->set_calculated_shipping(true); 
  711.  
  712. public function get_state_code($country, $state) { 
  713. // If not US address, then convert state to abbreviation 
  714. if ($country != 'US') { 
  715. if (isset(WC()->countries->states[WC()->customer->get_country()]) && !empty(WC()->countries->states[WC()->customer->get_country()])) { 
  716. $local_states = WC()->countries->states[WC()->customer->get_country()]; 
  717. if (!empty($local_states) && in_array($state, $local_states)) { 
  718. foreach ($local_states as $key => $val) { 
  719. if ($val == $state) { 
  720. $state = $key; 
  721. return $state; 
  722.  
  723. public function angelleye_ec_save_billing_agreement($order_id) { 
  724. if (empty($this->paypal_response)) { 
  725. return false; 
  726. $order = wc_get_order($order_id); 
  727. $old_wc = version_compare(WC_VERSION, '3.0', '<'); 
  728. update_post_meta($order_id, '_first_transaction_id', isset($this->paypal_response['PAYMENTINFO_0_TRANSACTIONID']) ? $this->paypal_response['PAYMENTINFO_0_TRANSACTIONID'] : '' ); 
  729. do_action('before_save_payment_token', $order_id); 
  730. if (isset($this->paypal_response['BILLINGAGREEMENTID']) && !empty($this->paypal_response['BILLINGAGREEMENTID']) && is_user_logged_in()) { 
  731. update_post_meta($order_id, 'BILLINGAGREEMENTID', isset($this->paypal_response['BILLINGAGREEMENTID']) ? $this->paypal_response['BILLINGAGREEMENTID'] : ''); 
  732. $customer_id = $order->get_user_id(); 
  733. $billing_agreement_id = $this->paypal_response['BILLINGAGREEMENTID']; 
  734. $token = new WC_Payment_Token_CC(); 
  735. $token->set_user_id($customer_id); 
  736. $token->set_token($billing_agreement_id); 
  737. $token->set_gateway_id($this->gateway->id); 
  738. $token->set_card_type('PayPal Billing Agreement'); 
  739. $token->set_last4(substr($billing_agreement_id, -4)); 
  740. $token->set_expiry_month(date('m')); 
  741. $token->set_expiry_year(date('Y', strtotime('+20 years'))); 
  742. $save_result = $token->save(); 
  743. if ($save_result) { 
  744. $order->add_payment_token($token); 
  745. if (!empty($this->paypal_response['BILLINGAGREEMENTID'])) { 
  746. update_post_meta($order_id, 'BILLINGAGREEMENTID', isset($this->paypal_response['BILLINGAGREEMENTID']) ? $this->paypal_response['BILLINGAGREEMENTID'] : ''); 
  747. update_post_meta($order_id, '_payment_tokens_id', isset($this->paypal_response['BILLINGAGREEMENTID']) ? $this->paypal_response['BILLINGAGREEMENTID'] : ''); 
  748. $this->save_payment_token($order, isset($this->paypal_response['BILLINGAGREEMENTID']) ? $this->paypal_response['BILLINGAGREEMENTID'] : ''); 
  749.  
  750. public function save_payment_token($order, $payment_tokens_id) { 
  751. $order_id = version_compare(WC_VERSION, '3.0', '<') ? $order->id : $order->get_id(); 
  752. // Also store it on the subscriptions being purchased or paid for in the order 
  753. if (function_exists('wcs_order_contains_subscription') && wcs_order_contains_subscription($order_id)) { 
  754. $subscriptions = wcs_get_subscriptions_for_order($order_id); 
  755. } elseif (function_exists('wcs_order_contains_renewal') && wcs_order_contains_renewal($order_id)) { 
  756. $subscriptions = wcs_get_subscriptions_for_renewal_order($order_id); 
  757. } else { 
  758. $subscriptions = array(); 
  759. if (!empty($subscriptions)) { 
  760. foreach ($subscriptions as $subscription) { 
  761. update_post_meta($subscription->id, '_payment_tokens_id', $payment_tokens_id); 
  762.  
  763. public function angelleye_ec_get_customer_email_address($order_id) { 
  764. $this->user_email_address = ''; 
  765. $order = wc_get_order($order_id); 
  766. $old_wc = version_compare(WC_VERSION, '3.0', '<'); 
  767. if (is_user_logged_in()) { 
  768. $userLogined = wp_get_current_user(); 
  769. $this->user_email_address = $userLogined->user_email; 
  770. if ($old_wc) { 
  771. update_post_meta($order_id, '_billing_email', $userLogined->user_email); 
  772. update_post_meta($order_id, '_customer_user', $userLogined->ID); 
  773. } else { 
  774. update_post_meta($order->get_id(), '_customer_user', $userLogined->ID); 
  775. update_post_meta($order->get_id(), '_billing_email', $userLogined->user_email); 
  776. } else { 
  777. $_billing_email = get_post_meta($order_id, '_billing_email', true); 
  778. if (!empty($_billing_email)) { 
  779. $this->user_email_address = $_billing_email; 
  780. } else { 
  781. $payeremail = WC()->session->get('payeremail'); 
  782. $this->user_email_address = $payeremail; 
  783. if ($old_wc) { 
  784. update_post_meta($order_id, '_billing_email', $payeremail); 
  785. } else { 
  786. update_post_meta($order->get_id(), '_billing_email', $payeremail); 
  787.  
  788. public function angelleye_ec_sellerprotection_handler($order_id) { 
  789. $order = wc_get_order($order_id); 
  790. $old_wc = version_compare(WC_VERSION, '3.0', '<'); 
  791. if ($this->angelleye_woocommerce_sellerprotection_should_cancel_order()) { 
  792. WC_Gateway_PayPal_Express_AngellEYE::log('Order ' . $order_id . ' (' . $this->paypal_response['PAYMENTINFO_0_TRANSACTIONID'] . ') did not meet our Seller Protection requirements. Cancelling and refunding order.'); 
  793. $order->add_order_note(__('Transaction did not meet our Seller Protection requirements. Cancelling and refunding order.', 'paypal-for-woocommerce')); 
  794. $admin_email = get_option("admin_email"); 
  795. if ($this->email_notify_order_cancellations == true) { 
  796. if (isset($this->user_email_address) && !empty($this->user_email_address)) { 
  797. $mailer = WC()->mailer(); 
  798. $subject = __('PayPal Express Checkout payment declined due to our Seller Protection Settings', 'paypal-for-woocommerce'); 
  799. $message = $mailer->wrap_message($subject, __('Order #', 'paypal-for-woocommerce') . $order_id); 
  800. $mailer->send($this->user_email_address, strip_tags($subject), $message); 
  801. $mailer->send($admin_email, strip_tags($subject), $message); 
  802. if ($old_wc) { 
  803. update_post_meta($order_id, '_transaction_id', $this->paypal_response['PAYMENTINFO_0_TRANSACTIONID']); 
  804. } else { 
  805. update_post_meta($order->get_id(), '_transaction_id', $this->paypal_response['PAYMENTINFO_0_TRANSACTIONID']); 
  806. $this->gateway->process_refund($order_id, $order->get_total(), __('There was a problem processing your order. Please contact customer support.', 'paypal-for-woocommerce')); 
  807. $order->update_status('cancelled'); 
  808. wc_add_notice(__('Thank you for your recent order. Unfortunately it has been cancelled and refunded. Please contact our customer support team.', 'paypal-for-woocommerce'), 'error'); 
  809. wp_redirect(get_permalink(wc_get_page_id('cart'))); 
  810. exit(); 
  811.  
  812. public function DoReferenceTransaction($order_id) { 
  813. $PayPalRequestData = array(); 
  814. $token_id = $_POST['wc-paypal_express-payment-token']; 
  815. $token = WC_Payment_Tokens::get($token_id); 
  816. if ($token->get_user_id() !== get_current_user_id()) { 
  817. return; 
  818. $order = wc_get_order($order_id); 
  819. if (sizeof(WC()->cart->get_cart()) == 0) { 
  820. $ms = sprintf(__('Sorry, your session has expired. <a href=%s>Return to homepage →</a>', 'paypal-for-woocommerce'), '"' . home_url() . '"'); 
  821. $ec_confirm_message = apply_filters('angelleye_ec_confirm_message', $ms); 
  822. wc_add_notice($ec_confirm_message, "error"); 
  823. wp_redirect(get_permalink(wc_get_page_id('cart'))); 
  824. $customer_note_value = version_compare(WC_VERSION, '3.0', '<') ? wptexturize($order->customer_note) : wptexturize($order->get_customer_note()); 
  825. $customer_notes = $customer_note_value ? substr(preg_replace("/[^A-Za-z0-9 ]/", "", $customer_note_value), 0, 256) : ''; 
  826. $DRTFields = array( 
  827. 'referenceid' => $token->get_token(),  
  828. 'paymentaction' => ($this->gateway->payment_action == 'Authorization' || $order->get_total() == 0 ) ? 'Authorization' : $this->gateway->payment_action,  
  829. 'returnfmfdetails' => '1',  
  830. 'softdescriptor' => $this->softdescriptor 
  831. ); 
  832. $PayPalRequestData['DRTFields'] = $DRTFields; 
  833. $PaymentDetails = array( 
  834. 'amt' => AngellEYE_Gateway_Paypal::number_format($order->get_total()), // Required. Total amount of the order, including shipping, handling, and tax. 
  835. 'currencycode' => version_compare(WC_VERSION, '3.0', '<') ? $order->get_order_currency() : $order->get_currency(), // A three-character currency code. Default is USD. 
  836. 'itemamt' => '', // Required if you specify itemized L_AMT fields. Sum of cost of all items in this order. 
  837. 'shippingamt' => '', // Total shipping costs for this order. If you specify SHIPPINGAMT you mut also specify a value for ITEMAMT. 
  838. 'insuranceamt' => '',  
  839. 'shippingdiscount' => '',  
  840. 'handlingamt' => '', // Total handling costs for this order. If you specify HANDLINGAMT you mut also specify a value for ITEMAMT. 
  841. 'taxamt' => '', // Required if you specify itemized L_TAXAMT fields. Sum of all tax items in this order. 
  842. 'insuranceoptionoffered' => '', // If true, the insurance drop-down on the PayPal review page displays Yes and shows the amount. 
  843. 'desc' => '', // Description of items on the order. 127 char max. 
  844. 'custom' => apply_filters('ae_ppec_custom_parameter', json_encode(array('order_id' => version_compare(WC_VERSION, '3.0', '<') ? $order->id : $order->get_id(), 'order_key' => version_compare(WC_VERSION, '3.0', '<') ? $order->order_key : $order->get_order_key()))), // Free-form field for your own use. 256 char max. 
  845. 'invnum' => $this->gateway->invoice_id_prefix . preg_replace("/[^a-zA-Z0-9]/", "", str_replace("#", "", $order->get_order_number())), // Your own invoice or tracking number. 127 char max. 
  846. 'buttonsource' => '' // URL for receiving Instant Payment Notifications 
  847. ); 
  848. if (isset($this->gateway->notifyurl) && !empty($this->gateway->notifyurl)) { 
  849. $PaymentDetails['notifyurl'] = $this->gateway->notifyurl; 
  850. if (WC()->cart->needs_shipping()) { 
  851. $shipping_first_name = version_compare(WC_VERSION, '3.0', '<') ? $order->shipping_first_name : $order->get_shipping_first_name(); 
  852. $shipping_last_name = version_compare(WC_VERSION, '3.0', '<') ? $order->shipping_last_name : $order->get_shipping_last_name(); 
  853. $shipping_address_1 = version_compare(WC_VERSION, '3.0', '<') ? $order->shipping_address_1 : $order->get_shipping_address_1(); 
  854. $shipping_address_2 = version_compare(WC_VERSION, '3.0', '<') ? $order->shipping_address_2 : $order->get_shipping_address_2(); 
  855. $shipping_city = version_compare(WC_VERSION, '3.0', '<') ? $order->shipping_city : $order->get_shipping_city(); 
  856. $shipping_state = version_compare(WC_VERSION, '3.0', '<') ? $order->shipping_state : $order->get_shipping_state(); 
  857. $shipping_postcode = version_compare(WC_VERSION, '3.0', '<') ? $order->shipping_postcode : $order->get_shipping_postcode(); 
  858. $shipping_country = version_compare(WC_VERSION, '3.0', '<') ? $order->shipping_country : $order->get_shipping_country(); 
  859. $ShippingAddress = array('shiptoname' => $shipping_first_name . ' ' . $shipping_last_name, // Required if shipping is included. Person's name associated with this address. 32 char max. 
  860. 'shiptostreet' => $shipping_address_1, // Required if shipping is included. First street address. 100 char max. 
  861. 'shiptostreet2' => $shipping_address_2, // Second street address. 100 char max. 
  862. 'shiptocity' => wc_clean(stripslashes($shipping_city)), // Required if shipping is included. Name of city. 40 char max. 
  863. 'shiptostate' => $shipping_state, // Required if shipping is included. Name of state or province. 40 char max. 
  864. 'shiptozip' => $shipping_postcode, // Required if shipping is included. Postal code of shipping address. 20 char max. 
  865. 'shiptocountrycode' => $shipping_country, // Required if shipping is included. Country code of shipping address. 2 char max. 
  866. 'shiptophonenum' => '', // Phone number for shipping address. 20 char max. 
  867. ); 
  868. $PayPalRequestData['ShippingAddress'] = $ShippingAddress; 
  869. $this->order_param = $this->gateway_calculation->order_calculation($order_id); 
  870. if ($this->gateway->send_items) { 
  871. $Payment['order_items'] = $this->order_param['order_items']; 
  872. } else { 
  873. $Payment['order_items'] = array(); 
  874. $PaymentDetails['taxamt'] = AngellEYE_Gateway_Paypal::number_format($this->order_param['taxamt']); 
  875. $PaymentDetails['shippingamt'] = AngellEYE_Gateway_Paypal::number_format($this->order_param['shippingamt']); 
  876. $PaymentDetails['itemamt'] = AngellEYE_Gateway_Paypal::number_format($this->order_param['itemamt']); 
  877. $PayPalRequestData['PaymentDetails'] = $PaymentDetails; 
  878. $this->paypal_response = $this->paypal->DoReferenceTransaction($PayPalRequestData); 
  879. AngellEYE_Gateway_Paypal::angelleye_paypal_for_woocommerce_curl_error_handler($this->paypal_response, $methos_name = 'DoExpressCheckoutPayment', $gateway = 'PayPal Express Checkout', $this->gateway->error_email_notify); 
  880. WC_Gateway_PayPal_Express_AngellEYE::log('Test Mode: ' . $this->testmode); 
  881. WC_Gateway_PayPal_Express_AngellEYE::log('Endpoint: ' . $this->gateway->API_Endpoint); 
  882. $PayPalRequest = isset($this->paypal_response['RAWREQUEST']) ? $this->paypal_response['RAWREQUEST'] : ''; 
  883. $PayPalResponse = isset($this->paypal_response['RAWRESPONSE']) ? $this->paypal_response['RAWRESPONSE'] : ''; 
  884. WC_Gateway_PayPal_Express_AngellEYE::log('Request: ' . print_r($this->paypal->NVPToArray($this->paypal->MaskAPIResult($PayPalRequest)), true)); 
  885. WC_Gateway_PayPal_Express_AngellEYE::log('Response: ' . print_r($this->paypal->NVPToArray($this->paypal->MaskAPIResult($PayPalResponse)), true)); 
  886. return $this->paypal_response; 
  887.  
  888. public function angelleye_ec_force_to_display_checkout_page() { 
  889. $this->enable_guest_checkout = get_option('woocommerce_enable_guest_checkout') == 'yes' ? true : false; 
  890. $this->must_create_account = $this->enable_guest_checkout || is_user_logged_in() ? false : true; 
  891. $force_to_display_checkout_page = true; 
  892. if ($this->must_create_account) { 
  893. return apply_filters('angelleye_ec_force_to_display_checkout_page', true); 
  894. $paypal_express_terms = WC()->session->get('paypal_express_terms'); 
  895. if (wc_get_page_id('terms') > 0 && apply_filters('woocommerce_checkout_show_terms', true)) { 
  896. if ($this->disable_term) { 
  897. return apply_filters('angelleye_ec_force_to_display_checkout_page', false); 
  898. } elseif (isset($_POST['terms']) && $_POST['terms'] == 'on') { 
  899. return apply_filters('angelleye_ec_force_to_display_checkout_page', false); 
  900. } elseif ( !empty($paypal_express_terms) && $paypal_express_terms == true ) { 
  901. return apply_filters('angelleye_ec_force_to_display_checkout_page', false); 
  902. if ($this->skip_final_review == 'yes') { 
  903. return apply_filters('angelleye_ec_force_to_display_checkout_page', false); 
  904. return apply_filters('angelleye_ec_force_to_display_checkout_page', $force_to_display_checkout_page); 
  905.  
  906. public function angelleye_woocommerce_sellerprotection_should_cancel_order() { 
  907. $order_cancellation_setting = $this->gateway->order_cancellations; 
  908. $txn_protection_eligibility_response = isset($this->paypal_response['PAYMENTINFO_0_PROTECTIONELIGIBILITY']) ? $this->paypal_response['PAYMENTINFO_0_PROTECTIONELIGIBILITY'] : 'ERROR!'; 
  909. $txn_id = isset($this->paypal_response['PAYMENTINFO_0_TRANSACTIONID']) ? $this->paypal_response['PAYMENTINFO_0_TRANSACTIONID'] : 'ERROR!'; 
  910. switch ($order_cancellation_setting) { 
  911. case 'no_seller_protection': 
  912. if ($txn_protection_eligibility_response != 'Eligible' && $txn_protection_eligibility_response != 'PartiallyEligible') { 
  913. WC_Gateway_PayPal_Express_AngellEYE::log('Transaction ' . $txn_id . ' is BAD. Setting: no_seller_protection, Response: ' . $txn_protection_eligibility_response); 
  914. return true; 
  915. WC_Gateway_PayPal_Express_AngellEYE::log('Transaction ' . $txn_id . ' is OK. Setting: no_seller_protection, Response: ' . $txn_protection_eligibility_response); 
  916. return false; 
  917. case 'no_unauthorized_payment_protection': 
  918. if ($txn_protection_eligibility_response != 'Eligible') { 
  919. WC_Gateway_PayPal_Express_AngellEYE::log('Transaction ' . $txn_id . ' is BAD. Setting: no_unauthorized_payment_protection, Response: ' . $txn_protection_eligibility_response); 
  920. return true; 
  921. WC_Gateway_PayPal_Express_AngellEYE::log('Transaction ' . $txn_id . ' is OK. Setting: no_unauthorized_payment_protection, Response: ' . $txn_protection_eligibility_response); 
  922. return false; 
  923. case 'disabled': 
  924. WC_Gateway_PayPal_Express_AngellEYE::log('Transaction ' . $txn_id . ' is OK. Setting: disabled, Response: ' . $txn_protection_eligibility_response); 
  925. return false; 
  926. default: 
  927. WC_Gateway_PayPal_Express_AngellEYE::log('ERROR! order_cancellations setting for ' . $this->gateway->method_title . ' is not valid!'); 
  928. return true; 
  929.  
  930. public function angelleye_process_refund($order_id, $amount = null, $reason = '') { 
  931. $order = wc_get_order($order_id); 
  932. WC_Gateway_PayPal_Express_AngellEYE::log('Begin Refund'); 
  933. WC_Gateway_PayPal_Express_AngellEYE::log('Transaction ID: ' . print_r($order->get_transaction_id(), true)); 
  934. if (!$order || !$order->get_transaction_id()) { 
  935. return false; 
  936. if ($reason) { 
  937. if (255 < strlen($reason)) { 
  938. $reason = substr($reason, 0, 252) . '...'; 
  939. $reason = html_entity_decode($reason, ENT_NOQUOTES, 'UTF-8'); 
  940. $RTFields = array( 
  941. 'transactionid' => $order->get_transaction_id(),  
  942. 'refundtype' => $order->get_total() == $amount ? 'Full' : 'Partial',  
  943. 'amt' => AngellEYE_Gateway_Paypal::number_format($amount),  
  944. 'currencycode' => version_compare(WC_VERSION, '3.0', '<') ? $order->get_order_currency() : $order->get_currency(),  
  945. 'note' => $reason,  
  946. ); 
  947. $PayPalRequestData = array('RTFields' => $RTFields); 
  948. WC_Gateway_PayPal_Express_AngellEYE::log('Refund Request: ' . print_r($PayPalRequestData, true)); 
  949. $this->paypal_response = $this->paypal->RefundTransaction($PayPalRequestData); 
  950.  
  951.  
  952. AngellEYE_Gateway_Paypal::angelleye_paypal_for_woocommerce_curl_error_handler($this->paypal_response, $methos_name = 'RefundTransaction', $gateway = 'PayPal Express Checkout', $this->gateway->error_email_notify); 
  953. WC_Gateway_PayPal_Express_AngellEYE::log('Test Mode: ' . $this->testmode); 
  954. WC_Gateway_PayPal_Express_AngellEYE::log('Endpoint: ' . $this->gateway->API_Endpoint); 
  955. $PayPalRequest = isset($this->paypal_response['RAWREQUEST']) ? $this->paypal_response['RAWREQUEST'] : ''; 
  956. $PayPalResponse = isset($this->paypal_response['RAWRESPONSE']) ? $this->paypal_response['RAWRESPONSE'] : ''; 
  957. WC_Gateway_PayPal_Express_AngellEYE::log('Request: ' . print_r($this->paypal->NVPToArray($this->paypal->MaskAPIResult($PayPalRequest)), true)); 
  958. WC_Gateway_PayPal_Express_AngellEYE::log('Response: ' . print_r($this->paypal->NVPToArray($this->paypal->MaskAPIResult($PayPalResponse)), true)); 
  959. if ($this->paypal->APICallSuccessful($this->paypal_response['ACK'])) { 
  960. $order->add_order_note('Refund Transaction ID:' . $this->paypal_response['REFUNDTRANSACTIONID']); 
  961. $max_remaining_refund = wc_format_decimal($order->get_total() - $order->get_total_refunded()); 
  962. if (!$max_remaining_refund > 0) { 
  963. $order->update_status('refunded'); 
  964. if (ob_get_length()) 
  965. ob_end_clean(); 
  966. return true; 
  967. } else { 
  968. $ec_message = apply_filters('ae_ppec_refund_error_message', $this->paypal_response['L_LONGMESSAGE0'], $this->paypal_response['L_ERRORCODE0'], $this->paypal_response); 
  969. return new WP_Error('ec_refund-error', $ec_message); 
  970.