我正在尝试使用cURL在我的网站上添加PayPal付款,我发现如何获取访问令牌但我不知道如何将此请求(由PayPal Developer提供)转换为PHP cURL以继续付款
curl -v https://api.sandbox.paypal.com/v1/payments/payment \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer <Access-Token>' \
-d '{
"intent":"sale",
"redirect_urls":{
"return_url":"http://example.com/your_redirect_url.html",
"cancel_url":"http://example.com/your_cancel_url.html"
},
"payer":{
"payment_method":"paypal"
},
"transactions":[
{
"amount":{
"total":"7.47",
"currency":"USD"
}
}
]
}'
答案 0 :(得分:0)
就像那样(未经测试):
$ch = curl_init('https://api.sandbox.paypal.com/v1/payments/payment');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Authorization: Bearer <Access-Token>'
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$payloadData = '{
"intent":"sale",
"redirect_urls":{
"return_url":"http://example.com/your_redirect_url.html",
"cancel_url":"http://example.com/your_cancel_url.html"
},
"payer":{
"payment_method":"paypal"
},
"transactions":[
{
"amount":{
"total":"7.47",
"currency":"USD"
}
}
]
}';
curl_setopt($ch, CURLOPT_POSTFIELDS, $payloadData);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$result = curl_exec($ch);
$httpStatusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);