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 598a9381f..25cc89923 100644 --- a/classes/lib/angelleye/paypal-php-library/includes/paypal.class.php +++ b/classes/lib/angelleye/paypal-php-library/includes/paypal.class.php @@ -608,8 +608,15 @@ function CURLRequest($Request = "", $APIName = "", $APIOperation = "") { curl_setopt($curl, CURLOPT_SSLCERT, $this->PathToCertKeyPEM); } - - $Response = curl_exec($curl); + if(curl_exec($curl) === false) + { + $httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE); + $string_return = 'L_ERRORCODE0='.$httpCode.'&L_SHORTMESSAGE0='.curl_error($curl).'&L_LONGMESSAGE0='.curl_error($curl).'&L_SEVERITYCODE0='.$httpCode; + return $string_return; + } + else { + $Response = curl_exec($curl); + } curl_close($curl); return $Response; } @@ -1335,6 +1342,12 @@ function DoDirectPayment($DataArray) // Now that we have each chunk we need to go ahead and append them all together for our entire NVP string $NVPRequest = $this->NVPCredentials . $DPFieldsNVP . $CCDetailsNVP . $PayerInfoNVP . $PayerNameNVP . $BillingAddressNVP . $PaymentDetailsNVP . $OrderItemsNVP . $ShippingAddressNVP . $Secure3DNVP; $NVPResponse = $this->CURLRequest($NVPRequest); + /** + * Check Curl Error + */ + if( isset( $PayPalResult['CURL_ERROR'] ) ){ + return $PayPalResult; + } $NVPRequestArray = $this->NVPToArray($NVPRequest); $NVPResponseArray = $this->NVPToArray($NVPResponse); @@ -1538,6 +1551,9 @@ function GetExpressCheckoutDetails($Token) $NVPRequest = $this->NVPCredentials . $GECDFieldsNVP; $NVPResponse = $this->CURLRequest($NVPRequest); + if( isset( $NVPResponse ) && is_array( $NVPResponse ) && !empty( $NVPResponse['CURL_ERROR'] ) ){ + return $NVPResponse; + } $NVPRequestArray = $this->NVPToArray($NVPRequest); $NVPResponseArray = $this->NVPToArray($NVPResponse); @@ -1616,6 +1632,9 @@ function DoExpressCheckoutPayment($DataArray) $NVPRequest = $this->NVPCredentials . $DECPFieldsNVP . $PaymentsNVP . $UserSelectedOptionsNVP; $NVPResponse = $this->CURLRequest($NVPRequest); + if( isset( $NVPResponse ) && is_array( $NVPResponse ) && !empty( $NVPResponse['CURL_ERROR'] ) ){ + return $NVPResponse; + } $NVPRequestArray = $this->NVPToArray($NVPRequest); $NVPResponseArray = $this->NVPToArray($NVPResponse); 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 f3024cdbd..7587ede70 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 @@ -114,21 +114,29 @@ 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; - } - } + 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); @@ -170,6 +178,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-pro-payflow-angelleye.php b/classes/wc-gateway-paypal-pro-payflow-angelleye.php index 9318ab76c..e0e9fd1cf 100644 --- a/classes/wc-gateway-paypal-pro-payflow-angelleye.php +++ b/classes/wc-gateway-paypal-pro-payflow-angelleye.php @@ -520,6 +520,19 @@ function do_payment( $order, $card_number, $card_exp, $card_csc, $centinelPAResS $this->add_log('PayFlow Endpoint: '.$PayPal->APIEndPoint); $this->add_log(print_r($PayPalResult,true)); } + + /** + * Check Curl Error + */ + if( isset( $PayPalResult['CURL_ERROR'] ) ){ + $admin_email = get_option("admin_email"); + $message = __( "PayFlow API 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, "PayPal Pro Error Notification",$message); + throw new Exception($PayPalResult['CURL_ERROR']); + } /** * Error check