JS: Switching from Stripe Checkout to Stripe Elements

herkypam

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?

Paul Asjes

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.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Redirect from successful stripe checkout

Using Stripe Checkout in React and Express js

How to intergrate with Stripe Checkout JS/HTML

Stripe with node.js + express checkout issue

Stripe Custom Checkout - Passing JS variable into amount

Uncaught (in promise) Error: Invalid prop `stripe` supplied to `Elements`. We recommend using the `loadStripe` utility from `@stripe/stripe-js`

Pre populate email in Stripe Checkout from form

Calling a Stripe checkout form from a custom button

is there a specific way to implement card elements from stripe in vue js?

react-stripe-elements not detecting Stripe.js

redirect to stripe checkout

Stripe Checkout Integration

Hide email in Stripe Checkout

Adding Parameters with Stripe Checkout

Stripe Checkout and Customer Creation

Using Stripe Checkout in Cordova

Stripe checkout is not working

Stripe Custom Checkout With Options

Stripe - Create Checkout Session with Stripe Connect

Edit a credit card using Stripe checkout.js

Stripe checkout.js - passing custom params to token callback

What is the difference between react-stripe-checkout and react-stripe-js?

Update user in database on success from Stripe prebuilt checkout

how to pass email address from checkout form to charge page with Stripe

Stripe payments, cannot get payment amount from checkout

Stripe Checkout example running into CORS error from localhost

Set Stripe checkout custom amount from GET parameter

Stripe - Get risk score from checkout.session.completed event

Add metadata to Stripe checkout button