简体   繁体   中英

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 ).

I am sending the name and address fields as tokenData like this:

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 will validate the card number, expiry date and CVC (if required) in Elements, but won't validate the address when passed to 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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