256 Kilobytes

Answers in Server-Side | By August R. Garcia

Published 7 months agoFri, 12 Apr 2019 21:24:46 -0700

187 views, 0 RAMs, and 0 comments

Tags: PHP, REST, PayPal API

Profile Photo - August R. Garcia August R. Garcia LARPing as a Sysadmi... Portland, OR
🗎 198 🗨 989 🐏 299
Site Owner

The PHP Function

// This function makes the equivalent of the cURL call below:
// curl -v<200b> https://api.sandbox.paypal.com/v1/oauth2/token \
//   -H "Accept: application/json" \
//   -H "Accept-Language: en_US" \
//   -u "Aa-VzaSh4zdUsmWcsOcVQjzOwwU_Scner8VflNO37xKF2PgCWc0JSbB-mxOdCbMHEAeS0irwWv4xmYxE" \
//   -d "grant_type=client_credentials"
function get_access_token() {

        $ch       = curl_init();

        curl_setopt($ch, CURLOPT_URL,            "https://api.sandbox.paypal.com/v1/oauth2/token");
        curl_setopt($ch, CURLOPT_HEADER,         false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_POST,           true);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_USERPWD,        env('PAYPAL_CLIENT_ID') . ":" . env('PAYPAL_SECRET')   );
        curl_setopt($ch, CURLOPT_POSTFIELDS,     "grant_type=client_credentials");

        $result = curl_exec($ch);
        $err    = curl_error($ch);

        if ($err) {  echo "cURL Error #:" . $err; }
        else      {
                $json         = json_decode($result);
                $access_token = $json->access_token;


        return json_decode( $result )->access_token;

Edit this line:

  • curl_setopt($ch, CURLOPT_USERPWD,        env('PAYPAL_CLIENT_ID') . ":" . env('PAYPAL_SECRET')   );

To include your application's client ID and secret key.

Download more RAM. 🐏 ⨉ 0 Posted by August R. Garcia 7 months ago 🕓 Posted at 12 April, 2019 21:24 PM PDT

Sir, I can do you a nice SEO.

Post a New Comment

To leave a comment, login to your account or create an account.

Do you like having a good time?

Read Quality Articles

Read some quality articles. If you can manage to not get banned for like five minutes, you can even post your own articles.

View Articles →

Argue with People on the Internet

Use your account to explain why people are wrong on the Internet forum.

View Forum →

Vandalize the Wiki

Or don't. I'm not your dad.

View Wiki →

Ask and/or Answer Questions

If someone asks a terrible question, post a LMGTFY link.

View Answers →

Make Some Money

Hire freelancers and/or advertise your goods and/or services. Hire people directly. We're not a middleman or your dad. Manage your own business transactions.

Register an Account
You can also login to an existing account or recover your password. All use of this site is subject to terms outlined in the terms of service and privacy policy.