0
votes

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?

1

1 Answers

1
votes

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.