We are using PayPal's refund API. In Sandbox, the return of the curl request is JSON such as: {"id":"2MF64726R55120122","create_time":"2018-08-02T16:21:02Z","update_time":"2018-08-02T16:21:02Z","state":"completed","amount":{"total":"223.64","currency":"USD"},"refund_from_transaction_fee":{"currency":"USD","value":"6.49"},"total_refunded_amount":{"currency":"USD","value":"223.64"},"refund_from_received_amount":{"currency":"USD","value":"217.15"},"sale_id":"72D344128A363704P","parent_payment":"PAY-1N951805D8633101ELNRS6FI","links":[{"href":"https://www.sandbox.paypal.com/v1/payments/refund/2MF64726R55120122","rel":"self","method":"GET"},{"href":"https://www.sandbox.paypal.com/v1/payments/payment/PAY-1N951805D8633101ELNRS6FI","rel":"parent_payment","method":"GET"},{"href":"https://www.sandbox.paypal.com/v1/payments/sale/72D344128A363704P","rel":"sale","method":"GET"}]} In production, the same code is returning: Any idea what's going on? Note that the refund transaction is posted successfully in PayPal. Only the response is gibberish. Here's the code: // Determine the proper PayPal server to POST to. if (!empty($rules_config['server']) && $rules_config['server'] == 'sandbox') { $host = 'https://www.sandbox.paypal.com'; $token_host = "https://api.sandbox.paypal.com/v1/oauth2/token"; } else { $host = 'https://www.paypal.com'; $token_host = "https://api.paypal.com/v1/oauth2/token"; } $body = [ 'amount' => [ 'total' => $amount, 'currency' => $total[0]['currency_code'] ] ]; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $token_host); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Accept: application/json', 'Accept-Language: en_US' )); curl_setopt($ch, CURLOPT_USERPWD, $client . ':' . $secret); curl_setopt($ch, CURLOPT_POSTFIELDS, 'grant_type=client_credentials'); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $output = curl_exec($ch); $json = json_decode($output); if(isset($json->access_token)) { $token = $json->access_token; // this is our PayPal access token } else { drupal_set_message("Generating token failed. Please check log for details."); } // Setup the cURL request. $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $host.'/v1/payments/sale/'.$transaction_id.'/refund'); curl_setopt($ch, CURLOPT_VERBOSE, 0); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json', 'Authorization: Bearer ' . $token )); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_NOPROGRESS, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1); // Commerce PayPal requires SSL peer verification, which may prevent out of // date servers from successfully processing API requests. If you get an error // related to peer verification, you may need to download the CA certificate // bundle file from http://curl.haxx.se/docs/caextract.html, place it in a // safe location on your web server, and update your settings.php to set the // commerce_paypal_cacert variable to contain the absolute path of the file. // Alternately, you may be able to update your php.ini to point to the file // with the curl.cainfo setting. if (variable_get('commerce_paypal_cacert', FALSE)) { curl_setopt($ch, CURLOPT_CAINFO, variable_get('commerce_paypal_cacert', '')); } $response = curl_exec($ch); print_r($response);
... View more