Adventures Inward Paypal: Starting Fourth Dimension Steps To Gaining An Access Token Using The Remainder Api


Spoiler alert: if you've come upwards hither to honor a solution on how to exercise the PayPal API amongst MAMP, hence I apologise inwards advance that I can't endure of help. I tin exclusively study the issues that I encountered when testing its compatibility.

To begin

So I've been dabbling inwards PayPal's REST APIs together with accept flora that spell using cURL from the OS X/macOS terminal is straightforward getting this materials working on my hosted website wasn't every bit straightforward without piecing together some code from but about the web. I'm non going to instruct through the steps of setting upwards a sandbox customer id together with hush-hush here, for that you lot require to instruct over to http://developer.paypal.com. I am also non going to tackle the plain of study of setting upwards the necessary PayPal describe of piece of job concern human relationship for utilising the API. Neither am I going to move into into how you lot obtain SSL certificates. Here I'll endure dealing amongst the existent footing hurdles of code existence placed on your website that is going to work. And this is going to endure reported every bit I instruct along, hence at that topographic point may good endure difficulties ahead that I can't at acquaint predict.

Code: 1

The offset useful slice of code is this:
<?php  if (!curl_version()['features'] & CURL_VERSION_SSL) {     echo "SSL is non supported amongst this cURL installation."; } else {     echo "You accept cURL version: ".curl_version()['version'].". ";    echo "You accept SSL/NSS version: ".curl_version()['ssl_version']; }  ?> 
It is rejigged from a user comment on the official PHP site. The code volition enjoin you lot whether SSL is supported together with hence SSL/NSS information.

With MAMP 3.2.1 I encountered the error: "error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alarm handshake failure". There are a number of suggested solutions to this but I haven't silent had fourth dimension to seek whatsoever of them. One of the problems is I believe that an one-time version of OpenSSL (OpenSSL/0.9.8) runs on MAMP that doesn't back upwards TLS but installing the newer version is inwards itself supposedly a challenge.

Once you've passed this offset hurdle together with flora out that you lot are likely going to endure OK, hence nosotros tin start testing for sure that nosotros tin recollect an access token.

Code: 2

<?php  // http://stackoverflow.com/questions/15729167/paypal-api-with-php-and-curl // https://github.com/paypal/adaptivepayments-sdk-php/issues/24 // https://github.com/paypal/rest-api-curlsamples/blob/master/execute_all_calls.php  $clientId = "Replace this string amongst your ID"; $secret = "Replace this string amongst your Secrect";  component subdivision get_access_token($url, $postdata) {  global $clientId, $clientSecret;  $curl = curl_init($url);   curl_setopt($curl, CURLOPT_POST, true);   curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);  curl_setopt($curl, CURLOPT_USERPWD, $clientId . ":" . $clientSecret); // curl_setopt($ch, CURLOPT_SSLVERSION, 1); // curl_setopt($ch, CURLOPT_SSL_CIPHER_LIST, 'TLSv1');  curl_setopt($curl, CURLOPT_HEADER, false);   curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);   curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);   // curl_setopt($curl, CURLOPT_VERBOSE, TRUE);  $response = curl_exec( $curl );  if (empty($response)) {      // some form of an mistake happened      die(curl_error($curl));      curl_close($curl); // closed cURL handler  } else {      $info = curl_getinfo($curl);   echo "Time took: " . $info['total_time']*1000 . "ms\n";      curl_close($curl); // closed cURL handler   if($info['http_code'] != 200 && $info['http_code'] != 201 ) {    echo "Received error: " . $info['http_code']. "\n";    echo "Raw response:".$response."\n";    die();      }  }  // Convert the effect from JSON format to a PHP array   $jsonResponse = json_decode( $response );  provide $jsonResponse->access_token; } echo get_access_token('https://api.sandbox.paypal.com/v1/oauth2/token','grant_type=client_credentials');  ?>  
You'll notice some URLs at the caput of the code. These are stopping points along the means but this code is from the PayPal Github resources together with was final updated a few years ago. You'll also reckon some commented out code, the offset 2 lines (after the URLs) that accept been commented out were suggestions of how to instruct things working but I flora were unneeded inwards the terminate for my ain setup but mightiness endure useful to others.

The to a greater extent than recent resources are harder to unpick together with carve upwards out, hence I've started hither together with volition hence endeavor to exercise this code every bit a starting indicate from which to interpret other API calls into PHP. The argue for starting amongst PHP is because it is widely understood together with a well-supported linguistic communication together with is to a greater extent than probable to accept the required libraries pre-installed than possibly others. And this post service is to a greater extent than well-nigh getting things running amongst what you lot accept than needing to install novel materials onto servers.


Comments

Popular posts from this blog

Removing The Index.Php File From Url Inward Codeigniter

What Are The Main Components of a Computer System

Delete Daily Doppler E-Mail Spam From An Iphone [Fix]