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

时间:2019-05-15 14:53:20

标签: javascript stripe-payments

我一直在使用Stripe Checkout(https://stripe.com/docs/payments/checkout),现在终于切换到Stripe Elements(https://stripe.com/payments/elements)。

我将这样发送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);
  }
});

它可以正常工作,并且可以通过沙箱上的付款,但是当我检查网络呼叫条带创建令牌时,看起来它并不在乎输入什么名称或地址,只要创建令牌即可卡有效:

{
  "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
}

对于Stripe Checkout,我相信(但不能确定)它是自动处理此问题的?

1 个答案:

答案 0 :(得分:1)

条带将验证Elements中的卡号,有效期和CVC(如果需要),但是在传递给createToken时将不验证地址。

大多数银行在尝试收费时都不需要地址,因此地址的验证取决于您的实现。

Legacy Checkout确实对地址进行了一些验证,但仅进行了基本验证,并且仅因为UI元素由Stripe控制。