如何显示贝宝存储信用卡的详细信息为现有或重复客户在我的网站


how to display paypal stored credit card details for existing or repeat customer in my website?

我在paypal服务器上存储信用卡详细信息并返回下面的代码。

stdClass Object
(
    [id] => CARD-817429813C079815KKXSTCWI
    [state] => ok
    [payer_id] => user12345
    [type] => visa
    [number] => xxxxxxxxxxxx0331
    [expire_month] => 11
    [expire_year] => 2018
    [first_name] => Joe1
    [last_name] => Shopper1
    [valid_until] => 2018-08-31T00:00:00Z
    [create_time] => 2015-09-01T05:02:17Z
    [update_time] => 2015-09-01T05:02:17Z
    [links] => Array
        (
            [0] => stdClass Object
                (
                    [href] => https://api.sandbox.paypal.com/v1/vault/credit-card/CARD-817429813C079815KKXSTCWI
                    [rel] => self
                    [method] => GET
                )
            [1] => stdClass Object
                (
                    [href] => https://api.sandbox.paypal.com/v1/vault/credit-card/CARD-817429813C079815KKXSTCWI
                    [rel] => delete
                    [method] => DELETE
                )
            [2] => stdClass Object
                (
                    [href] => https://api.sandbox.paypal.com/v1/vault/credit-card/CARD-817429813C079815KKXSTCWI
                    [rel] => patch
                    [method] => PATCH
                )
        )
)

i have id as credit_card_id and payer_id如何实现以下功能?

如果存在或重复客户下次购买产品,只需自动填写paypal的信用卡详细信息,从而节省客户的时间

如何显示客户信用卡的详细信息在我的网站已经存储在paypal服务器

请引导我

下面的PHP和HTML数据
<style>
.creditcard .float1 { float:left; }
</style>
<?php 
$clientId="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$secret="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
        $ipnexec = curl_init();
        curl_setopt($ipnexec, CURLOPT_URL, "https://api.sandbox.paypal.com/v1/oauth2/token"); // test url
        curl_setopt($ipnexec, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ipnexec, CURLOPT_POST, true);
        curl_setopt($ipnexec, CURLOPT_USERPWD, $clientId.":".$secret);
        curl_setopt($ipnexec, CURLOPT_POSTFIELDS, "grant_type=client_credentials");
        //curl_setopt($ipnexec, CURLOPT_POSTFIELDS, $req);
        //curl_setopt($ipnexec, CURLOPT_FOLLOWLOCATION, 0);
        curl_setopt($ipnexec, CURLOPT_RETURNTRANSFER, true);
        //curl_setopt($ipnexec, CURLOPT_TIMEOUT, 30);
        $ipnresult = curl_exec($ipnexec);
            $result = json_decode($ipnresult);
        echo "<pre>";
        $access_token = $result->access_token;
        //print_r($result->access_token);
        $token_type = $result->token_type;  
        curl_close($ipnexec);

// phase 2 for credit card payment
$scope = "https://api.sandbox.paypal.com/v1/vault/credit-card";
$expire_month = 11;
$expire_year = 2018;
$first_name = "joe1";
$last_name = "shopper1";
$method = "storecreditcard";
$number = 4446283280247004;
$type = "visa";
$payer_id="manthan228@gmail.com";
$ch = curl_init();
//curl_setopt($ch, CURLOPT_HTTPHEADER, 1);
$data = '
 {
 "payer_id":"user12345",
 "type":"visa",
 "number":"4417119669820331",
 "expire_month":"11",
 "expire_year":"2018",
 "first_name":"Joe1",
 "last_name":"Shopper1"
}
';
curl_setopt($ch, CURLOPT_URL,$scope);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json","Authorization: Bearer ".$access_token));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$result = curl_exec($ch);
if(empty($result))die("Error: No response.");
else
{
    $json = json_decode($result);
    print_r($json);
}
curl_close($ch);
/**************************** phase 3 ***********************************/
$ch = curl_init();
$data = '{
  "intent":"sale",
  "payer": {
    "payment_method": "credit_card",
    "funding_instruments": [
      {
        "credit_card_token":{
          "credit_card_id":"'.$json->id.'",
          "payer_id":"user12345"
        }
      }
    ]
  },
  "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 ".$access_token));
$result = curl_exec($ch);

if(empty($result))die("Error: No response.");
else
{
    $json = json_decode($result);
    echo "<pre>";
    print_r($json);
}

?>

<div class="creditcard" style="height:400px;width:400px; padding:2px;border:3px solid blue">
<p>card number</p>
<div style="border:1px solid grey;padding:2px 5px">
<?php echo $json->id ?>
</div>
<div>
<p>Name on card</p>
<div style="border:1px solid grey;padding:5px 5px">
<?php echo $json->first_name." ".$json->first_name ?>
</div>
<div class="float1">
<span>Expiry Month</span>
<span style="border:1px solid grey; padding:2px 5px;width:100px;padding:4px;"><?php echo $json->expire_month ?> </span>
</div>
<div class="float1">
<span>Expiry Year</span>
<span  style="border:1px solid grey;width:100px; padding:4px;"><?php echo $json->expire_year ?></span>
</div>
</div>
</div>

编辑:根据评论,因为你想要实现的是使用保存的CC,你可以在vault/credit-card调用中使用Paypal提供的id作为payment调用的credit_card_id。这里是Paypal支付概览Vault: https://developer.paypal.com/docs/integration/direct/rest-vault-overview/#use-a-stored-credit-card


原始答案

你不应该把信用卡数据保存在你的服务器上,有太多的安全和隐私问题。

您可能需要创建一个BillingAgreement。基本上,paypal将为用户存储CC数据,并请求他允许在不插入所有数据的情况下在您的网站上捕获未来的付款。然后,您将拥有一个账单协议ID,您可以在以后的付款中使用它。在这里看到的:https://developer.paypal.com/docs/classic/express-checkout/ht_ec-refTrans-SetEC-DoRefTrans-curl-etc/