Skip to content

Commit

Permalink
cURL Error Handling, ref #146
Browse files Browse the repository at this point in the history
  • Loading branch information
kcppdevelopers committed Dec 28, 2015
1 parent 5ff8486 commit 6863c0d
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

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

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

Expand Down
29 changes: 29 additions & 0 deletions classes/wc-gateway-paypal-express-angelleye.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -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'])) {

Expand Down
15 changes: 15 additions & 0 deletions classes/wc-gateway-paypal-pro-angelleye.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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']))
{
Expand Down
15 changes: 15 additions & 0 deletions classes/wc-gateway-paypal-pro-payflow-angelleye.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)){
Expand Down
13 changes: 13 additions & 0 deletions paypal-for-woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

0 comments on commit 6863c0d

Please sign in to comment.