Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
CreditCardForm.prototype._validateNumber = function (value) {
var validationResult = validator.number(value, {
luhnValidateUnionPay: true,
maxLength: this.configuration.fields.number.maxCardLength
});
var card = validationResult.card;
var possibleCardTypes, possibleCardType;
// NEXT_MAJOR_VERSION credit-card-type fixed the mastercard enum
// but we still pass master-card in the braintree API
// in a major version bump, we can remove this and
// this will be mastercard instead of master-card
if (card && card.type === 'mastercard') {
card.type = 'master-card';
}
possibleCardTypes = this.getCardTypes(value).filter(function (cardType) {
return card && cardType.type === card.type;
CreditCardForm.prototype._validateCvv = function (value, options) {
var cvvSize, minLength;
options = options || {};
minLength = options.minLength;
if (this._fieldKeys.indexOf('number') === -1) { // CVV only
return validator.cvv(value, minLength || [3, 4]);
}
cvvSize = this.get('possibleCardTypes').map(function (item) {
return item.code.size;
});
cvvSize = uniq(cvvSize);
return validator.cvv(value, cvvSize);
};
CreditCardForm.prototype._validateCvv = function (value, options) {
var cvvSize, minLength;
options = options || {};
minLength = options.minLength;
if (this._fieldKeys.indexOf('number') === -1) { // CVV only
return validator.cvv(value, minLength || [3, 4]);
}
cvvSize = this.get('possibleCardTypes').map(function (item) {
return item.code.size;
});
cvvSize = uniq(cvvSize);
return validator.cvv(value, cvvSize);
};
test(value) {
const { card } = number((this.parent as HostedInputValues).cardNumber);
return cvv(value, card && card.code ? card.code.size : undefined).isValid;
},
});
test(value) {
const { card } = number((this.parent as HostedInputValues).cardNumber);
return cvv(value, card && card.code ? card.code.size : undefined).isValid;
},
});
test: value => number(value).isValid,
});
onCardNumberChange(event, value) {
const numberValidation = valid.number(_.camelCase(value));
const niceType = numberValidation.card ? numberValidation.card.niceType : null;
this.setState({
number: value,
cardNiceType: niceType
});
},
protected _notifyChange(value: string): void {
const cardInfo = number(value).card;
const prevCardInfo = this._previousValue && number(this._previousValue).card;
if (get(prevCardInfo, 'type') === get(cardInfo, 'type')) {
return;
}
this._eventPoster.post({
type: HostedInputEventType.CardTypeChanged,
payload: {
cardType: cardInfo ? cardInfo.type : undefined,
},
});
}
protected _notifyChange(value: string): void {
const cardInfo = number(value).card;
const prevCardInfo = this._previousValue && number(this._previousValue).card;
if (get(prevCardInfo, 'type') === get(cardInfo, 'type')) {
return;
}
this._eventPoster.post({
type: HostedInputEventType.CardTypeChanged,
payload: {
cardType: cardInfo ? cardInfo.type : undefined,
},
});
}
function cardInfoUpdated(event) {
var name = document.getElementById("full-name").value;
var expDate = document.getElementById("exp-date").value;
var number = document.getElementById("cc-number").value;
var validationResult = cardValidator.number(number);
var expDateValidation = cardValidator.expirationDate({ month: expDate.substring(5) , year: expDate.substring(0, 4) });
var readyToSave = validationResult.isValid && expDateValidation.isValid && name.length > 0;
document.getElementById("add-card-confirm-button").disabled = !readyToSave;
var formattedNumber = formatCardNumber(number);
if (number !== formattedNumber) {
document.getElementById("cc-number").value = formattedNumber;
}
}