Generate Access token of Paypal Gateway in PHP

0
57
Paypal Integration

This tutorial explains how to generate access token of Paypal Payment gateway in PHP

<?php
$auth64code="paypal authcode";  // auth code

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://api.paypal.com/v1/oauth2/token",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
   CURLOPT_POSTFIELDS => "grant_type=client_credentials",
  CURLOPT_HTTPHEADER => array(
    "authorization: Basic $auth64code",
    "cache-control: no-cache",
    "content-type: application/x-www-form-urlencoded"
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

 $obj_res=json_decode($response);
 print_r($obj_res);
 echo $obj_res->access_token;
?>

LEAVE A REPLY

Please enter your comment!
Please enter your name here