How to use the payment.getCardArray function in payment

To help you get started, we’ve selected a few payment examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github neinteractiveliterature / intercode / app / javascript / BuiltInFormControls / CreditCardNumberInput.jsx View on Github external
getIconClass = () => {
    let iconClass;
    let colorClass;
    const cardNumber = this.props.value;

    if (cardNumber && cardNumber.length > 0) {
      const cardType = Payment.fns.cardType(cardNumber);

      if (cardType) {
        iconClass = CARD_TYPE_ICONS[cardType] || CARD_TYPE_ICONS.unknown;

        const cardTypeObject = Payment.getCardArray().find(card => card.type === cardType);
        if (cardTypeObject.length.includes(cardNumber.replace(/\s/g, '').length)) {
          if (Payment.fns.validateCardNumber(cardNumber)) {
            colorClass = 'text-success';
          } else {
            iconClass = 'fa-exclamation-triangle';
            colorClass = 'text-danger';
          }
        }
      } else {
        iconClass = CARD_TYPE_ICONS.unknown;
      }
    } else {
      iconClass = CARD_TYPE_ICONS.unknown;
    }

    return classNames('fa', iconClass, colorClass);

payment

A general purpose library for building credit card forms, validating inputs and formatting numbers. Base on jquery.payment by @stripe, but without the jQuery.

MIT
Latest version published 5 months ago

Package Health Score

71 / 100
Full package analysis