diff --git a/classes/lib/angelleye/paypal-php-library/includes/paypal.class.php b/classes/lib/angelleye/paypal-php-library/includes/paypal.class.php index 271f29a28..00fd2c900 100644 --- a/classes/lib/angelleye/paypal-php-library/includes/paypal.class.php +++ b/classes/lib/angelleye/paypal-php-library/includes/paypal.class.php @@ -611,8 +611,17 @@ function CURLRequest($Request = "", $APIName = "", $APIOperation = "") curl_setopt($curl, CURLOPT_SSLCERT, $this->PathToCertKeyPEM); } - $Response = curl_exec($curl); + $Response = curl_exec($curl); + $httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE); + + if ($Response === false || $httpCode != 200) { + $curl_error = curl_error($curl); + $httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE); + $Response = array( 'CURL_ERROR' =>curl_error($curl) ); + } + curl_close($curl); + return $Response; } diff --git a/classes/lib/angelleye/paypal-php-library/includes/paypal.payflow.class.php b/classes/lib/angelleye/paypal-php-library/includes/paypal.payflow.class.php index c63be8337..cfc459fc1 100644 --- a/classes/lib/angelleye/paypal-php-library/includes/paypal.payflow.class.php +++ b/classes/lib/angelleye/paypal-php-library/includes/paypal.payflow.class.php @@ -117,24 +117,22 @@ function CURLRequest($Request = "", $APIName = "", $APIOperation = "") // in case of network issues. The idea here is since you are posting via HTTPS there // could be general network issues, so try a few times before you tell customer there // is an issue. - $i=1; - while ($i++ <= 3) - { - $Response = curl_exec($curl); - $headers = curl_getinfo($curl); - - if ($headers['http_code'] != 200) { - sleep(5); // Let's wait 5 seconds to see if its a temporary network issue. - } - else if ($headers['http_code'] == 200) - { - // we got a good response, drop out of loop. - break; - } - } - - curl_close($curl); - + if(curl_exec($curl) === false) { + return array( 'CURL_ERROR' =>curl_error($curl) ); + } else { + $i=1; + while ($i++ <= 3) { + $Response = curl_exec($curl); + $headers = curl_getinfo($curl); + if ($headers['http_code'] != 200) { + sleep(5); // Let's wait 5 seconds to see if its a temporary network issue. + } else if ($headers['http_code'] == 200) { + // we got a good response, drop out of loop. + break; + } + } + } + curl_close($curl); return $Response; } @@ -176,6 +174,9 @@ function ProcessTransaction($DataArray) } $NVPResponse = $this->CURLRequest($NVPRequest); + if( isset( $NVPResponse ) && is_array( $NVPResponse ) && !empty( $NVPResponse['CURL_ERROR'] ) ){ + return $NVPResponse; + } $NVPResponse = strstr($NVPResponse,"RESULT"); $NVPResponseArray = $this->NVPToArray($NVPResponse); diff --git a/classes/wc-gateway-paypal-express-angelleye.php b/classes/wc-gateway-paypal-express-angelleye.php index 82f378322..262f55451 100644 --- a/classes/wc-gateway-paypal-express-angelleye.php +++ b/classes/wc-gateway-paypal-express-angelleye.php @@ -1528,6 +1528,13 @@ function CallSetExpressCheckout($paymentAmount, $returnURL, $cancelURL, $usePayP // Pass data into class for processing with PayPal and load the response array into $PayPalResult $PayPalResult = $PayPal->SetExpressCheckout($PayPalRequestData); + + /** + * cURL Error Handling #146 + * @since 1.1.8 + */ + + AngellEYE_Gateway_Paypal::angelleye_paypal_for_woocommerce_curl_error_handler($PayPalResult, $methos_name = 'SetExpressCheckout', $gateway = 'PayPal Express Checkout', $this->error_email_notify); /* * Log API result @@ -1595,6 +1602,13 @@ function CallGetShippingDetails($token) { * Call GetExpressCheckoutDetails */ $PayPalResult = $PayPal->GetExpressCheckoutDetails($token); + + /** + * cURL Error Handling #146 + * @since 1.1.8 + */ + + AngellEYE_Gateway_Paypal::angelleye_paypal_for_woocommerce_curl_error_handler($PayPalResult, $methos_name = 'GetExpressCheckoutDetails', $gateway = 'PayPal Express Checkout', $this->error_email_notify); /* * Log API result @@ -1781,6 +1795,13 @@ function ConfirmPayment($FinalPaymentAmt) { // Pass data into class for processing with PayPal and load the response array into $PayPalResult $PayPalResult = $PayPal->DoExpressCheckoutPayment($PayPalRequestData); + /** + * cURL Error Handling #146 + * @since 1.1.8 + */ + + AngellEYE_Gateway_Paypal::angelleye_paypal_for_woocommerce_curl_error_handler($PayPalResult, $methos_name = 'DoExpressCheckoutPayment', $gateway = 'PayPal Express Checkout', $this->error_email_notify); + /* * Log API result */ @@ -2077,6 +2098,14 @@ public function process_refund($order_id, $amount = null, $reason = '') { $this->add_log('Refund Request: ' . print_r($PayPalRequestData, true)); // Pass data into class for processing with PayPal and load the response array into $PayPalResult $PayPalResult = $PayPal->RefundTransaction($PayPalRequestData); + + /** + * cURL Error Handling #146 + * @since 1.1.8 + */ + + AngellEYE_Gateway_Paypal::angelleye_paypal_for_woocommerce_curl_error_handler($PayPalResult, $methos_name = 'RefundTransaction', $gateway = 'PayPal Express Checkout', $this->error_email_notify); + $this->add_log('Refund Information: ' . print_r($PayPalResult, true)); if ($PayPal->APICallSuccessful($PayPalResult['ACK'])) { diff --git a/classes/wc-gateway-paypal-pro-angelleye.php b/classes/wc-gateway-paypal-pro-angelleye.php index d4ff91f2d..ed92ae599 100644 --- a/classes/wc-gateway-paypal-pro-angelleye.php +++ b/classes/wc-gateway-paypal-pro-angelleye.php @@ -813,6 +813,13 @@ function do_payment($order, $card_number, $card_type, $card_exp_month, $card_exp // Pass data into class for processing with PayPal and load the response array into $PayPalResult $PayPalResult = $PayPal->DoDirectPayment($PayPalRequestData); + + /** + * cURL Error Handling #146 + * @since 1.1.8 + */ + + AngellEYE_Gateway_Paypal::angelleye_paypal_for_woocommerce_curl_error_handler($PayPalResult, $methos_name = 'DoDirectPayment', $gateway = 'PayPal Website Payments Pro (DoDirectPayment)', $this->error_email_notify); if($this->debug) { @@ -1020,6 +1027,14 @@ public function process_refund( $order_id, $amount = null, $reason = '' ) { $this->add_log('Refund Request: '.print_r( $PayPalRequestData, true ) ); // Pass data into class for processing with PayPal and load the response array into $PayPalResult $PayPalResult = $PayPal->RefundTransaction($PayPalRequestData); + + /** + * cURL Error Handling #146 + * @since 1.1.8 + */ + + AngellEYE_Gateway_Paypal::angelleye_paypal_for_woocommerce_curl_error_handler($PayPalResult, $methos_name = 'RefundTransaction', $gateway = 'PayPal Website Payments Pro (DoDirectPayment)', $this->error_email_notify); + $this->add_log('Refund Information: '.print_r( $PayPalResult, true ) ); if($PayPal->APICallSuccessful($PayPalResult['ACK'])) { diff --git a/classes/wc-gateway-paypal-pro-payflow-angelleye.php b/classes/wc-gateway-paypal-pro-payflow-angelleye.php index b261a3b7c..b1df99435 100644 --- a/classes/wc-gateway-paypal-pro-payflow-angelleye.php +++ b/classes/wc-gateway-paypal-pro-payflow-angelleye.php @@ -432,6 +432,13 @@ function do_payment( $order, $card_number, $card_exp, $card_csc, $centinelPAResS } $PayPalResult = $PayPal->ProcessTransaction($PayPalRequestData); + + /** + * cURL Error Handling #146 + * @since 1.1.8 + */ + + AngellEYE_Gateway_Paypal::angelleye_paypal_for_woocommerce_curl_error_handler($PayPalResult, $methos_name = 'do_payment', $gateway = 'PayPal Express Checkout', $this->error_email_notify); /** * Log results @@ -716,6 +723,14 @@ public function process_refund( $order_id, $amount = null, $reason = '' ) { ); $this->add_log('Refund Request: '.print_r( $PayPalRequestData, true ) ); $PayPalResult = $PayPal->ProcessTransaction($PayPalRequestData); + + /** + * cURL Error Handling #146 + * @since 1.1.8 + */ + + AngellEYE_Gateway_Paypal::angelleye_paypal_for_woocommerce_curl_error_handler($PayPalResult, $methos_name = 'Refund Request', $gateway = 'PayPal Express Checkout', $this->error_email_notify); + $this->add_log('Refund Information: '.print_r( $PayPalResult, true ) ); add_action( 'angelleye_after_refund', $PayPalResult, $order, $amount, $reason ); if(isset($PayPalResult['RESULT']) && ($PayPalResult['RESULT'] == 0 || $PayPalResult['RESULT'] == 126)){ diff --git a/paypal-for-woocommerce.php b/paypal-for-woocommerce.php index 27c2bc085..03dca2a91 100644 --- a/paypal-for-woocommerce.php +++ b/paypal-for-woocommerce.php @@ -1021,6 +1021,19 @@ public function update_wc_paypal_plug_not_support_currency_nag() { add_user_meta( $current_user->ID, '_wc_paypal_plus_not_support_currency_nag', '1', true ); } } + + public static function angelleye_paypal_for_woocommerce_curl_error_handler($PayPalResult, $methos_name = null, $gateway = null, $error_email_notify = true) { + if( isset( $PayPalResult['CURL_ERROR'] ) ){ + if($error_email_notify == true) { + $admin_email = get_option("admin_email"); + $message = __( $methos_name . " call failed." , "paypal-for-woocommerce" )."\n\n"; + $message .= __( 'Error Code: 0' ,'paypal-for-woocommerce' ) . "\n"; + $message .= __( 'Detailed Error Message: ' , 'paypal-for-woocommerce') . $PayPalResult['CURL_ERROR']; + wp_mail($admin_email, $gateway . " Error Notification",$message); + } + throw new Exception($PayPalResult['CURL_ERROR']); + } + } } } new AngellEYE_Gateway_Paypal(); \ No newline at end of file