我希望在我的网站上实施自适应贝宝付款方式。是否可以使用curl实现?任何人都可以为自适应支付提供php代码
最佳答案
这是卷曲调用贝宝的代码
对于自适应支付,首先需要使用“ clientId”和“ secret key”生成访问令牌。然后,使用该访问令牌,您可以调用Paypal自适应支付API。
我已经给出了生成访问令牌的示例。然后从Paykey获取交易详细信息(您可以根据需要更改通话)。
//Get access token from client Id
$ch = curl_init();
$clientId = PAYPAL_CLIENT_ID;
$secret = PAYPAL_CLIENT_SECRET;
curl_setopt($ch, CURLOPT_URL, 'https://api.sandbox.paypal.com/v1/oauth2/token');// Change it to "https://api.paypal.com/v1/oauth2/token" for live
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, $clientId . ":" . $secret);
curl_setopt($ch, CURLOPT_POSTFIELDS, "grant_type=client_credentials");
$result = curl_exec($ch);
$accessToken = null;
if (empty($result))
return 'Access Token could not generated';
else {
$json = json_decode($result);
$accessToken = $json->access_token;
}
curl_close($ch);
/**
* Get payment transaction details from
* - AccessToken
* - PayKey
*/
$curl = curl_init('https://api.sandbox.paypal.com/v1/payments/payment/' . $input['payKey']);
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);
$result = json_decode($response);
您可以拥有贝宝curl呼叫的参考示例
https://github.com/paypal/rest-api-curlsamples/blob/master/execute_all_calls.php
关于php - 使用curl进行Paypal自适应支付,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26380575/