如何获取,而无需使用条纹的UI层客户端的令牌?

问题描述 投票:0回答:2

我有以下的PHP页面,正常工作:

<html>
<head>
    <script src="https://checkout.stripe.com/checkout.js"></script>
    <script>
        var handler = StripeCheckout.configure({
          key: '<?=$stripePublicKey?>',
          image: 'https://stripe.com/img/documentation/checkout/marketplace.png',
          locale: 'auto',
          token: function(token) {
            // You can access the token ID with `token.id`.
            // Get the token ID to your server-side code for use.
            console.log("token.id: " + token.id);
            console.log("token: " + token);
          }
        });

        function init(){
            document.getElementById('customButton').addEventListener('click', function(e) {
                // Open Checkout with further options:
                handler.open({
                    name: 'TruckerCert',
                    description: 'Buy Certs',
                    amount: 2000
                });
                e.preventDefault();
            });

            // Close Checkout on page navigation:
            window.addEventListener('popstate', function() {
              handler.close();
            });
        }
    </script>
</head>
<body onload="init()">
<h1>Stripe Token Test</h1>
<button id="customButton">Purchase</button>
</body>
</html>

它的工作原理,并产生下列JSON:

{
  "id": "tok_1E255j2*****wC135im",
  "object": "token",
  "card": {
    "id": "card_1E255j2H1*****RGS4Kqc",
    "object": "card",
    "address_city": null,
    "address_country": null,
    "address_line1": null,
    "address_line1_check": null,
    "address_line2": null,
    "address_state": null,
    "address_zip": null,
    "address_zip_check": null,
    "brand": "Visa",
    "country": "US",
    "customer": null,
    "cvc_check": "pass",
    "dynamic_last4": null,
    "exp_month": 12,
    "exp_year": 2021,
    "fingerprint": "3nk5B*****29xV",
    "funding": "unknown",
    "last4": "1111",
    "metadata": {
    },
    "name": "her*******@gmail.com",
    "tokenization_method": null,
    "type": "Visa"
  },
  "client_ip": "67.***.***.17",
  "created": 1549754315,
  "email": "her********@gmail.com",
  "livemode": false,
  "type": "card",
  "used": false
}

所以这是所有预期。问题是,我能找到提交我的信用卡号码和EXP日期和接收回来的JSON的唯一途径是通过自己的UI打算。例如,当我点击我的customButton,显示此对话框:

enter image description here

我不想用自己的CC形式。我有我自己的CC形式。我想用我自己的形式,发送一个Ajax请求条纹的API端点,并接收返回的JSON如上而已。我已经通过条纹的在线文档梳理了一个小时,找不到任何方式做到这一点。

它是如何做?

javascript stripe-payments
2个回答
2
投票

你提到的产品被称为Stripe Checkout并让您采集卡安全细节,而无需建立自己的支付形式。

既然你提到将您的付款形式已经尽管你应该改为考虑Stripe Elements。这可让您的设计和风格你自己的支付形式,同时仍然满足PCI合规性,SAQ A的最低水平,为documented here

你可以根据付款形式还是多个例子和相应的代码在这里:https://stripe.github.io/elements-examples/


1
投票

Stripe.js版本2支持这一点。由于写这个的时候,你可以看到老文档here。如果我猜Stripe.js V2将全面贬值,从在某一时刻使用时被移除。因此,尽管你可以用一些麻烦使用它,它是贬值了,你要问自己是否值得那些具有在未来改写的风险。由于您目前正在建设中,但我只想用最先进的技术。

另外,根据Stripe's page on PCI compliance

如果继续使用Stripe.js V2,你会被要求每年上传您的SAQ A-EP来证明你的企业是PCI兼容。


总体使用条纹的元素系统是要走的路。有没有办法,你可以接触到用户的支付信息,这使得它尽可能的安全。更何况你在你的代码VS AJAX调用搞乱的可能性。如果你不小心送AJAX调用自己的服务器?你违反PCI合规的呢。

条纹元素还提供定制的车型方面很多。你应该能够在与现有的形式很容易地集成的方式来设计它。

© www.soinside.com 2019 - 2024. All rights reserved.