PolymerElements / gold-cc-input

An input element that only allows credit card numbers
https://webcomponents.org/element/PolymerElements/gold-cc-input
13 stars 23 forks source link

Discussion: Allowable card-types #37

Closed robrez closed 8 years ago

robrez commented 8 years ago

I would like to be able to incorporate 'allowable cardType(s)' into the validation routine.

My first instinct was to set card-type to a specific value. (I think card-type should be flagged as readOnly: true).

I was considering something like this...

var opts = { amex: true, visa: true };
or
var opts = [ 'amex', 'visa' ];
...
<gold-cc-input card-types="[[opts]]">

And then patching the validate function..

        var valid = result.valid && result.length_valid;
        this.cardType = valid ? result.card_type.name : '';
+       if (valid && this.cardTypes !== null && this.cardTypes.length > 0) {
+         valid = this.cardTypes.indexOf(this.cardType) !== -1;  //or .includes()?
+       }

Any thoughts? Edit: I'm thinking cardType should be empty if invalid.

notwaldorf commented 8 years ago

I think this is a great idea! (I left a comment on your PR, but it's almost ready to merge)

samuelli commented 8 years ago

This can be closed :)

robrez commented 8 years ago

Enhancement added via https://github.com/PolymerElements/gold-cc-input/pull/39