dongxieli3839
2014-10-10 14:04
浏览 230
已采纳

从信用卡php接受PayPal付款

I wanted to accept the payments from my store staying on my stor and don't wanted to go to the paypal I got the access token using curl but how could I use below code. I think this is the code that I should use for the payment.

curl -v https://api.sandbox.paypal.com/v1/payments/payment \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer {accessToken}' \
-d '{
  "intent":"sale",
  "redirect_urls":{
    "return_url":"http://<return URL here>",
    "cancel_url":"http://<cancel URL here>"
  },
  "payer":{
    "payment_method":"creditcard"
  },
  "transactions":[
    {
      "amount":{
        "total":"7.47",
        "currency":"USD"
      },
      "description":"This is the payment transaction description."
    }
  ]
}'

I just need a trick to use this in curl and make payment by sending data to paypal and receive in json

图片转代码服务由CSDN问答提供 功能建议

我想接受我商店的付款,并且不想去PayPal 使用curl获取访问令牌,但我如何使用下面的代码。 我认为这是我应该用于付款的代码。

  curl -v https://api.sandbox.paypal.com/v1/payments/payment \
H'Content-Type:application / json' \
H' 授权:持票人{accessToken}'\
d'{
“意图”:“销售”,
“redirect_urls”:{
“return_url”:“http://&lt;此处返回网址&gt;”,
  “cancel_url”:“http://&lt;取消此处的网址&gt;”
},
“付款人”:{
“payment_method”:“creditcard”
},
“”交易“:[
 {  
“金额”:{
“总数”:“7.47”,
“货币”:“美元”
},
“说明”:“这是付款交易说明。”
} 
  ] 
}'
   
 
 

我只需要一个技巧就可以在curl中使用它并通过向paypal发送数据并在json中接收付款

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • doulan4939 2014-10-10 14:39
    已采纳

    You can use the below php code for the credit card payment :

    <?php
    
    //open connection
    $ch = curl_init();
    
    $client="XXXXXXXXXXXXXXXXXXXXX";
    $secret="XXXXXXXXXXXXXXXXXXXXX";
    
    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, $client.":".$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);
    }
    
    // Now doing txn after getting the token 
    
    $ch = curl_init();
    
    $data = '{
      "intent":"sale",
      "redirect_urls":{
        "return_url":"http://<return URL here>",
        "cancel_url":"http://<cancel URL here>"
      },
      "payer": {
        "payment_method": "credit_card",
        "funding_instruments": [
          {
            "credit_card": {
              "number": "5500005555555559",
              "type": "mastercard",
              "expire_month": 12,
              "expire_year": 2018,
              "cvv2": 111,
              "first_name": "Joe",
              "last_name": "Shopper"
            }
          }
        ]
      },
      "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_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data); 
    curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json","Authorization: Bearer ".$json->access_token));
    
    $result = curl_exec($ch);
    
    
    if(empty($result))die("Error: No response.");
    else
    {
        $json = json_decode($result);
        print_r($json);
    }
    
    
    ?>
    

    Response :

    A015dVGr.q9WhQyXl-JnJnkJ.xcFkxJmHmUgCXwYqansoL0{"id":"PAY-58R21143N1956774RKQ365CQ","create_time":"2014-10-10T14:34:50Z","update_time":"2014-10-10T14:34:57Z","state":"approved","intent":"sale","payer":{"payment_method":"credit_card","funding_instruments":[{"credit_card":{"type":"mastercard","number":"xxxxxxxxxxxx5559","expire_month":"12","expire_year":"2018","first_name":"Joe","last_name":"Shopper"}}]},"transactions":[{"amount":{"total":"7.47","currency":"USD","details":{"subtotal":"7.47"}},"description":"This is the payment transaction description.","related_resources":[{"sale":{"id":"3J048328N18783546","create_time":"2014-10-10T14:34:50Z","update_time":"2014-10-10T14:34:57Z","amount":{"total":"7.47","currency":"USD"},"state":"completed","parent_payment":"PAY-58R21143N1956774RKQ365CQ","links":[{"href":"https://api.sandbox.paypal.com/v1/payments/sale/3J048328N18783546","rel":"self","method":"GET"},{"href":"https://api.sandbox.paypal.com/v1/payments/sale/3J048328N18783546/refund","rel":"refund","method":"POST"},{"href":"https://api.sandbox.paypal.com/v1/payments/payment/PAY-58R21143N1956774RKQ365CQ","rel":"parent_payment","method":"GET"}]}}]}],"links":[{"href":"https://api.sandbox.paypal.com/v1/payments/payment/PAY-58R21143N1956774RKQ365CQ","rel":"self","method":"GET"}]}1
    
    打赏 评论

相关推荐 更多相似问题