paypal支付接口开发--token获取,订单详情获取,交易信息获取

admin3年前PayPal1008

代码下载

完整代码下载

<?php 
//获取token
function get_token($clientId,$secret)
{
    

$uri = 'https://api.sandbox.paypal.com/v1/oauth2/token';
//for live production use $uri = 'https://api.paypal.com/v1/oauth2/token';
 

 
$ch = curl_init();
 
curl_setopt($ch, CURLOPT_URL, $uri);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSLVERSION , 6); //NEW ADDITION
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_USERPWD, $clientId.":".$secret);
curl_setopt($ch, CURLOPT_POSTFIELDS, "grant_type=client_credentials");
 
$result = curl_exec($ch);
$access_token = '';
if(empty($result))die("Error: No response.");
else
{
    $json = json_decode($result);
    $access_token = $json->access_token;
}
return $access_token;
curl_close($ch);

}
$clientId = '*********************';
$secret = '*********************';

//输出token
echo  get_token($clientId,$secret);
$access_token =get_token($clientId,$secret);

//获取交易流程

$url = "https://api.sandbox.paypal.com/v2/payments/captures/订单号";
$accessToken=$access_token;
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_POST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
    'Authorization: Bearer ' . $accessToken,
    'Accept: application/json',
    'Content-Type: application/json'
));
$response = curl_exec($curl);




//获取订单详情

$url = "https://api.sandbox.paypal.com/v2/checkout/orders/订单号";
$accessToken=$access_token;
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_POST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
    'Authorization: Bearer ' . $accessToken,
    'Accept: application/json',
    'Content-Type: application/json'
));
$response = curl_exec($curl);
 
print_r($response);








 ?>


相关文章

paypal的接口文档

 paypal的接口文档 amount_breakdown  breakdown属于amount在amount的大括号下面...

paypal开发

快捷生成js收款按钮采用SDK录入数据库关键:要把沙盒地址修改成正式地址...

paypal获取token

 <?php $ch = curl_init(); $clientId = "******"; $secret&n...

发表评论    

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。