Paypal pro 使用存储的信用卡详细信息付款

Posted

技术标签:

【中文标题】Paypal pro 使用存储的信用卡详细信息付款【英文标题】:Paypal pro Payment using Stored Credt Card Details 【发布时间】:2014-12-08 00:00:22 【问题描述】:

我们将信用卡详细信息存储在贝宝服务器上。

而且反应是这样的

stdClass Object ( [id] => CARD-14C32505AV6044027KQ537UQ [state] => ok [payer_id] => GI6WdoVY6zOq1413201872 [type] => visa [number] => xxxxxxxxxxxx1111 [expire_month] => 11 [expire_year] => 2018 [first_name] => Anu [last_name] => Jose [valid_until] => 2017-10-12T00:00:00Z [create_time] => 2014-10-13T12:04:34Z [update_time] => 2014-10-13T12 :04:34Z [links] => Array ([0] => stdClass Object ( [href] => https://api.sandbox.paypal.com/v1/vault/credit-card/CARD-14C32505AV6044027KQ537UQ [rel] => self [method] => GET ) [1] => stdClass Object ( [href ] => https://api.sandbox.paypal.com/v1/vault/credit-card/CARD-14C32505AV6044027KQ537UQ [rel] => delete [method] => DELETE) [2] => stdClass Object ([href] => https://api.sandbox.paypal.com/v1/vault/credit-card/CARD-14C32505AV6044027KQ537UQ [rel] => patch [method] => PATCH) )

是否可以使用此信用卡 ID 进行交易? 有什么帮助吗?

【问题讨论】:

【参考方案1】:

是的,您绝对可以使用上面收到的信用卡 ID 使用这些存储的卡进行付款。

我已经包含了你可以使用的 curl 请求:

请求

curl -v POST  "https://api.sandbox.paypal.com/v1/payments/payment" -H "Content-Type:application/json" -H "Authorization: Bearer A0430YIJHh.TrJ7DuXoVVSzzRD9BiNhc7.JUdtWFV9bm6PM" -d "\"intent\":\"sale\",\"payer\":\"payment_method\":\"credit_card\",\"funding_instruments\":[\"credit_card_token\":\"credit_card_id\":\"CARD-7F19874*H7676925VKQ55ALQ\"],\"transactions\":[\"amount\":\"total\":\"7.47\",\"currency\":\"USD\",\"description\":\"This is the payment transaction description.\"]"

回应

"id":"PAY-17C52753U3213490GKQ56FJQ","create_time":"2014-10-13T14:33:10Z","updat
e_time":"2014-10-13T14:33:28Z","state":"approved","intent":"sale","payer":"paym
ent_method":"credit_card","funding_instruments":["credit_card_token":"credit_c
ard_id":"CARD-7F116246H7676925VKQ55ALQ","last4":"0331","type":"visa","expire_mon
th":"11","expire_year":"2018"],"transactions":["amount":"total":"7.47","cur
rency":"USD","details":"subtotal":"7.47","description":"This is the payment t
ransaction description.","related_resources":["sale":"id":"0TD97130MF446714A",
"create_time":"2014-10-13T14:33:10Z","update_time":"2014-10-13T14:33:28Z","amoun
t":"total":"7.47","currency":"USD","state":"completed","parent_payment":"PAY-1
7C52753U3213490GKQ56FJQ","links":["href":"https://api.sandbox.paypal.com/v1/pay
ments/sale/0TD97130MF446714A","rel":"self","method":"GET","href":"https://api.
sandbox.paypal.com/v1/payments/sale/0TD97130MF446714A/refund","rel":"refund","me
thod":"POST","href":"https://api.sandbox.paypal.com/v1/payments/payment/PAY-17
C52753U3213490GKQ56FJQ","rel":"parent_payment","method":"GET"]]],"links":["
href":"https://api.sandbox.paypal.com/v1/payments/payment/PAY-17C52753U3213490GK
Q56FJQ","rel":"self","method":"GET"]

JSON 格式的请求:


  "intent": "sale",
  "payer": 
    "payment_method": "credit_card",
    "funding_instruments": [
      
        "credit_card_token": 
          "credit_card_id": "CARD-7F19874*H7676925VKQ55ALQ"
        
      
    ]
  ,
  "transactions": [
    
      "amount": 
        "total": "7.47",
        "currency": "USD"
      ,
      "description": "This is the payment transaction description."
    
  ]

回应:


  "id": "PAY-8U155502YW812893MKQ55D7Q",
  "create_time": "2014-10-13T13:22:06Z",
  "update_time": "2014-10-13T13:22:27Z",
  "state": "approved",
  "intent": "sale",
  "payer": 
    "payment_method": "credit_card",
    "funding_instruments": [
      
        "credit_card_token": 
          "credit_card_id": "CARD-7F19874*H7676925VKQ55ALQ",
          "last4": "0331",
          "type": "visa",
          "expire_month": "11",
          "expire_year": "2018"
        
      
    ]
  ,
  "transactions": [
    
      "amount": 
        "total": "7.47",
        "currency": "USD",
        "details": 
          "subtotal": "7.47"
        
      ,
      "description": "This is the payment transaction description.",
      "related_resources": [
        
          "sale": 
            "id": "5U920323FW4849716",
            "create_time": "2014-10-13T13:22:06Z",
            "update_time": "2014-10-13T13:22:27Z",
            "amount": 
              "total": "7.47",
              "currency": "USD"
            ,
            "state": "completed",
            "parent_payment": "PAY-8U155502YW812893MKQ55D7Q",
            "links": [
              
                "href": "https://api.sandbox.paypal.com/v1/payments/sale/5U920323FW4849716",
                "rel": "self",
                "method": "GET"
              ,
              
                "href": "https://api.sandbox.paypal.com/v1/payments/sale/5U920323FW4849716/refund",
                "rel": "refund",
                "method": "POST"
              ,
              
                "href": "https://api.sandbox.paypal.com/v1/payments/payment/PAY-8U155502YW812893MKQ55D7Q",
                "rel": "parent_payment",
                "method": "GET"
              
            ]
          
        
      ]
    
  ],
  "links": [
    
      "href": "https://api.sandbox.paypal.com/v1/payments/payment/PAY-8U155502YW812893MKQ55D7Q",
      "rel": "self",
      "method": "GET"
    
  ]

您可以使用以下 php 代码:

<?php

//open connection
$ch = curl_init();

$client="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
$secret="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";

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",
  "payer": 
    "payment_method": "credit_card",
    "funding_instruments": [
      
        "credit_card_token": 
          "credit_card_id": "CARD-76K83451273207050KQ6MXDQ"
        
      
    ]
  ,
  "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);


?>

【讨论】:

您好,请您提供有关第二种请求方法的更多详细信息 当我尝试 "name":"INTERNAL_SERVICE_ERROR","message":"An internal service error has occurred","information_link":"developer.paypal.com/webapps/developer/docs/api/…" 同样的代码对我有用。您是否在代码中输入了您的凭据和信用卡 ID? 你可以试试这些凭据 $client="AXclRxADU6bhIhd2jF13L56hf3i23Csauat6fvBdAgntuefbNWQU1p5jbiiL"; $secret="EKOarRDlB7hJBXUXUXlz4r-zFnIJT6G-EOMM2jz24qWr81OJbfZ-iKjXVHuI"; 您似乎存储了测试信用卡号 "4111111111111111" 。您可以尝试先存储此信用卡号“4860444400352960”,其中包含任何到期日期和 cvv2=012,然后使用新卡 ID 进行付款吗?

以上是关于Paypal pro 使用存储的信用卡详细信息付款的主要内容,如果未能解决你的问题,请参考以下文章

我可以在没有购物车的情况下使用 PayPal Pro 在我的网站上处理信用卡吗?

关于 PayPal Pro 付款

在 PayPal 网站(而不是我自己的托管网站)上输入信用卡详细信息

使用 PayPal 的“Website Payments Pro”存储信用卡信息?

PayPal Payments Pro 中的采集卡功能

Paypal Vault - 合规性