Skip to content

Commit

Permalink
- fixes #146
Browse files Browse the repository at this point in the history
  • Loading branch information
levansy2020 committed Mar 10, 2015
1 parent 9b8d49f commit fc32048
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 17 deletions.
23 changes: 21 additions & 2 deletions classes/lib/angelleye/paypal-php-library/includes/paypal.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down
13 changes: 13 additions & 0 deletions classes/wc-gateway-paypal-pro-payflow-angelleye.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit fc32048

Please sign in to comment.