使用PHP中的REST API进行Paypal付款

前端之家收集整理的这篇文章主要介绍了使用PHP中的REST API进行Paypal付款前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我不清楚如何将此代码示例放入 PHP的CURL结构中,特别是-d句柄.
  1. curl -v https://api.sandBox.paypal.com/v1/payments/payment \
  2. -H 'Content-Type:application/json' \
  3. -H 'Authorization:Bearer EOjEJigcsRhdOgD7_76lPfrr45UfuI43zzNzTktUk1MK' \
  4. -d '{
  5. "intent":"sale","redirect_urls":{
  6. "return_url":"http://<return URL here>","cancel_url":"http://<cancel URL here>"
  7. },"payer":{
  8. "payment_method":"paypal"
  9. },"transactions":[
  10. {
  11. "amount":{
  12. "total":"7.47","currency":"USD"
  13. },"description":"This is the payment transaction description."
  14. }
  15. ]
  16. }'

我已经使用了以下测试调用,但不知道如何将其扩展到上面的示例.

  1. curl_setopt($ch,CURLOPT_URL,"https://api.sandBox.paypal.com/v1/oauth2/token");
  2. curl_setopt($ch,CURLOPT_HEADER,false);
  3. curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,CURLOPT_POST,true);
  4. curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
  5. curl_setopt($ch,CURLOPT_USERPWD,$clientId.":".$secret);
  6. curl_setopt($ch,CURLOPT_POSTFIELDS,"grant_type=client_credentials");
  7.  
  8. $result = curl_exec($ch);
  9.  
  10. if(empty($result))die("Error: No response.");
  11. else
  12. {
  13. $json = json_decode($result);
  14. print_r($json->access_token);
  15. }
尝试这样的事情,-d是你要发布的数据.自定义标头使用CURLOPT_HTTPHEADER设置.
  1. $data = '{
  2. "intent":"sale","description":"This is the payment transaction description."
  3. }
  4. ]
  5. }';
  6.  
  7. curl_setopt($ch,"https://api.sandBox.paypal.com/v1/payments/payment");
  8. curl_setopt($ch,$data);
  9. curl_setopt($ch,CURLOPT_HTTPHEADER,array(
  10. "Content-Type: application/json","Authorization: Bearer EOjEJigcsRhdOgD7_76lPfrr45UfuI43zzNzTktUk1MK","Content-length: ".strlen($data))
  11. );

看看这里的选项,http://php.net/manual/en/function.curl-setopt.php设置curl_setopt($ch,false);例如,如果您不需要返回标头.

猜你在找的PHP相关文章