How to check CVC and Address with stripe.js

Someone recently asked on the Stripe API discussion mailing list:

"Does the Stripe.card.createToken call return back values for address_line1_check, address_zip_check, or cvc_check?"

Stripe Checkout has built-in behavior that runs these checks if you've provided that information and if you provide an amount. These checks work by asking the card network to authorize an amount on a particular card, but that amount doesn't get charged until you actually create a Stripe::Charge (see The Life of a Stripe Charge for full details on how this works).

It turns out, plain vanilla stripe.js that you use to construct custom forms also has this ability, but it's completely undocumented. All you have to do is pass an amount as the second parameter to the createToken call, like this:

Stripe.card.createToken({
  number: '4242424242424242',
  exp_month: '12',
  exp_year: '2022',
  cvc: '987'
}, 100, stripeResponseHandler);

There's two important caveats here:

  • This doesn't protect you against the card getting declined when you go to charge the card later. All it says is that this card can be charged right now.
  • This is completely undocumented, which means it could potentially break on you at any time.

That said, it's very useful to be able to run these checks ahead of time in a custom form.

Thanks to Matt Arkin for the original answer on the mailing list and for being a tremendous help in the Stripe community.

Mastering Modern Payments

Build a Better Payment System

Get a free five part email course all about Stripe and Rails, including the first three chapters of Mastering Modern Payments.


No spam. Unsubscribe at any time.
Pete Keen Portrait Pete Keen has been professional software developer for a decade, building payment systems and other software for companies large and small. He blogs here and at petekeen.net.