Making Paypal payment using REST API in PHP(在 PHP 中使用 REST API 进行 Paypal 付款)
问题描述
我不清楚如何将此代码示例放入 PHP 的 CURL 结构中,特别是 -d 句柄.
I'm not clear how to put this code example into PHP's CURL structure, specifically, the -d handle.
curl -v https://api.sandbox.paypal.com/v1/payments/payment
-H 'Content-Type:application/json'
-H 'Authorization:Bearer EOjEJigcsRhdOgD7_76lPfrr45UfuI43zzNzTktUk1MK'
-d '{
"intent":"sale",
"redirect_urls":{
"return_url":"http://<return URL here>",
"cancel_url":"http://<cancel URL here>"
},
"payer":{
"payment_method":"paypal"
},
"transactions":[
{
"amount":{
"total":"7.47",
"currency":"USD"
},
"description":"This is the payment transaction description."
}
]
}'
我已经使用了以下测试调用,但不知道如何将其扩展到上面的示例.
I've used the following test call ok, but don't know how to extend that to the example above.
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, $clientId.":".$secret);
curl_setopt($ch, CURLOPT_POSTFIELDS, "grant_type=client_credentials");
$result = curl_exec($ch);
if(empty($result))die("Error: No response.");
else
{
$json = json_decode($result);
print_r($json->access_token);
}
推荐答案
试试这个, -d 就是你要发布的数据.自定义标头使用 CURLOPT_HTTPHEADER 设置.
Try something like this, -d is the data you want to post. custom headers are set with CURLOPT_HTTPHEADER.
$data = '{
"intent":"sale",
"redirect_urls":{
"return_url":"http://<return URL here>",
"cancel_url":"http://<cancel URL here>"
},
"payer":{
"payment_method":"paypal"
},
"transactions":[
{
"amount":{
"total":"7.47",
"currency":"USD"
},
"description":"This is the payment transaction description."
}
]
}';
curl_setopt($ch, CURLOPT_URL, "https://api.sandbox.paypal.com/v1/payments/payment");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Content-Type: application/json",
"Authorization: Bearer EOjEJigcsRhdOgD7_76lPfrr45UfuI43zzNzTktUk1MK",
"Content-length: ".strlen($data))
);
看看这里的选项,http://php.net/手册/en/function.curl-setopt.php设置 curl_setopt($ch, CURLOPT_HEADER, false);例如,如果您不需要返回标头.
Have a look at the options here, http://php.net/manual/en/function.curl-setopt.php Set curl_setopt($ch, CURLOPT_HEADER, false); for example if you dont need the headers returned.
这篇关于在 PHP 中使用 REST API 进行 Paypal 付款的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 PHP 中使用 REST API 进行 Paypal 付款


- 如何在 Symfony2 中正确使用 webSockets 2021-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- Laravel 5:Model.php 中的 MassAssignmentException 2021-01-01
- openssl_digest vs hash vs hash_hmac?盐与盐的区别HMAC? 2022-01-01
- PHP foreach() 与数组中的数组? 2022-01-01
- 使用 GD 和 libjpeg 支持编译 PHP 2022-01-01
- PHP - if 语句中的倒序 2021-01-01
- 覆盖 Magento 社区模块控制器的问题 2022-01-01
- 如何使用 Google API 在团队云端硬盘中创建文件夹? 2022-01-01
- 如何从数据库中获取数据以在 laravel 中查看页面? 2022-01-01