如何在我的网站上为现有或回头客显示贝宝存储的信用卡详细信息?

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

我将信用卡详细信息存储在 paypal 服务器上,return 下面的代码。

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
                )

        )

)

我的 ID 为 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 作为 credit_card_idpayment 次调用。以下是 Vault 的 Paypal 付款概述: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/