Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import * as Payment from "payment";
const input = document.getElementById('input') as HTMLInputElement;
Payment.restrictNumeric(input);
Payment.formatCardNumber(input);
Payment.formatCardExpiry(input);
Payment.formatCardCVC(input);
const card = "1234 5678 9012 3456";
const cardType = Payment.fns.cardType(card);
Payment.fns.validateCardNumber(card);
Payment.fns.validateCardExpiry("1 / 20");
Payment.fns.validateCardExpiry("1", "20");
Payment.fns.validateCardCVC("123", cardType);
componentDidMount() {
const { number, expiration, cvc, zip } = this.refs
Payment.formatCardNumber(ReactDOM.findDOMNode(number).querySelector('input'))
Payment.formatCardExpiry(ReactDOM.findDOMNode(expiration).querySelector('input'))
Payment.formatCardCVC(ReactDOM.findDOMNode(cvc).querySelector('input'))
if (zip) {
Payment.restrictNumeric(ReactDOM.findDOMNode(zip).querySelector('input'))
}
}
handleCVCChange(e) {
const CVC = e.target.value;
const CVCLength = CVC.length;
payment.formatCardCVC(document.getElementById('cvc'));
this.setFieldValid();
if (CVCLength >= 4) {
const cardType = payment.fns.cardType(this.state.cardNumber);
if (!payment.fns.validateCardCVC(CVC, cardType)) {
this.setFieldInvalid('CVC is invalid');
}
}
const { cardCVCInputProps } = this.props;
if (cardCVCInputProps.onChange) {
cardCVCInputProps.onChange(e);
}
}
componentDidMount: function() {
const el = this.refs.input.getDOMNode();
switch ( this.props.formatter ) {
case 'cardNumber':
Payment.formatCardNumber( el );
break;
case 'cardExpiry':
Payment.formatCardExpiry( el );
break;
case 'cardCVV':
case 'cardCVC':
Payment.formatCardCVC( el );
break;
}
},