256 Kilobytes

Answers in Server-Side | By August R. Garcia

Published

279 views, 0 RAMs, and 0 comments

Tags: PHP, REST, PayPal API

Profile Photo - August R. GarciaAugust R. GarciaLARPing as a Sysadmi...Portland, ORSite Owner

The PHP Function
<?php
// 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;
        }

        curl_close($ch);

        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. 🐏 ⨉ 0Posted by August R. Garcia 1 year ago 🕓 Posted at 12 April, 2019 21:24 PM PDT

Sir, I can do you a nice SEO.

Post a New Comment

Do you like having a good time?

Register an Account

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

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

Answers— Read More

Find more related content below!