【问题标题】:accept payment in paypal from credit card php从信用卡php接受paypal付款
【发布时间】:2014-10-10 14:04:33
【问题描述】:

我想接受来自我的商店的付款留在我的存储中并且不想去贝宝我使用 curl 获得了访问令牌但是我如何使用下面的代码。我认为这是我应该用于付款的代码。

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."
    }
  ]
}'

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

【问题讨论】:

    标签: php curl paypal


    【解决方案1】:

    您可以使用以下 php 代码进行信用卡支付:

    <?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);
    }
    
    
    ?>
    

    回应:

    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
    

    【讨论】:

    • 你能告诉我签证的CC类型吗?这些被贝宝接受
    猜你喜欢
    • 2019-09-10
    • 1970-01-01
    • 2012-07-11
    • 2012-11-27
    • 2019-02-13
    • 2013-06-23
    • 1970-01-01
    • 1970-01-01
    • 2010-12-15
    相关资源
    最近更新 更多