简体   繁体   English

JS:从条纹签出切换到条纹元素

[英]JS: Switching from Stripe Checkout to Stripe Elements

I have been using Stripe Checkout ( https://stripe.com/docs/payments/checkout ) and I am now finally switching to Stripe Elements ( https://stripe.com/payments/elements ). 我一直在使用Stripe Checkout( https://stripe.com/docs/payments/checkout ),现在终于切换到Stripe Elements( https://stripe.com/payments/elements )。

I am sending the name and address fields as tokenData like this: 我将名称和地址字段作为tokenData发送,如下所示:

let tokenData = {
    name,address_line1, address_line2, address_city, address_state,address_zip, address_country
};


stripe.createToken(card, tokenData).then(function(result) {
  if (result.error) {
    // Inform the customer that there was an error.
   var errorElement = document.getElementById('card-errors');
    errorElement.textContent = result.error.message;
  } else {
    // Send the token to your server.
    stripeTokenHandler(result.token);
  }
});

It works and the payments on the sandbox go through but when I check the network call stripe makes to create the token, it looks like it doesn't care what name or address is entered and still creates the token as long as the card is valid: 它可以正常工作,并且可以通过沙箱进行付款,但是当我检查网络呼叫条带创建令牌时,看起来并不在乎输入的名称或地址,只要卡有效,它仍会创建令牌:

{
  "id": "tok_1EaOS2FLdOnSFAAaFkMjkKmu",
  "object": "token",
  "card": {
    "id": "card_1EaOS2FLdOnSFAAaHXi9klGu",
    "object": "card",
    "address_city": "asd",
    "address_country": "ads",
    "address_line1": "ads",
    "address_line1_check": "unchecked",
    "address_line2": "",
    "address_state": "sad",
    "address_zip": "11212",
    "address_zip_check": "unchecked",
    "brand": "Visa",
    "country": "US",
    "cvc_check": "unchecked",
    "dynamic_last4": null,
    "exp_month": 12,
    "exp_year": 2022,
    "funding": "credit",
    "last4": "4242",
    "metadata": {
    },
    "name": "asdd",
    "tokenization_method": null
  },
  "client_ip": "122.122.122",
  "created": 1557931886,
  "livemode": false,
  "type": "card",
  "used": false
}

For Stripe Checkouts, I believe (but can't be certain) that it handled this automatically? 对于Stripe Checkout,我相信(但不能确定)它是自动处理此问题的?

Stripe will validate the card number, expiry date and CVC (if required) in Elements, but won't validate the address when passed to createToken . Stripe将在Elements中验证卡号,有效期和CVC(如果需要),但是在传递给createToken时将不验证地址。

Most banks don't require an address when attempting a charge, so the validation of an address is left up to your implementation. 大多数银行在尝试收费时都不需要地址,因此地址的验证取决于您的实现。

Legacy Checkout did do some validation with addresses, but only basic validation and only because the UI elements were controlled by Stripe. 旧版Checkout确实对地址进行了一些验证,但是仅进行了基本验证,并且仅因为UI元素由Stripe控制。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM