Home

Awesome

React Credit Cards

NPM Travis Maintainability Test Coverage

A slick credit card component for React.

demo

Demo

Install

npm install --save react-credit-cards

Usage

import React from 'react';
import Cards from 'react-credit-cards';

export default class PaymentForm extends React.Component {
  state = {
    cvc: '',
    expiry: '',
    focus: '',
    name: '',
    number: '',
  };

  handleInputFocus = (e) => {
    this.setState({ focus: e.target.name });
  }
  
  handleInputChange = (e) => {
    const { name, value } = e.target;
    
    this.setState({ [name]: value });
  }
  
  render() {
    return (
      <div id="PaymentForm">
        <Cards
          cvc={this.state.cvc}
          expiry={this.state.expiry}
          focused={this.state.focus}
          name={this.state.name}
          number={this.state.number}
        />
        <form>
        	<input
            type="tel"
            name="number"
            placeholder="Card Number"
            onChange={this.handleInputChange}
            onFocus={this.handleInputFocus}
          />
          ...
        </form>
      </div>
    );
  }
}

Don't forget to import the react-credit-cards/lib/styles.scss if you are using SASS in your project.
Or you can import the CSS:
import 'react-credit-cards/es/styles-compiled.css';

Features

Props

* Required fields

SCSS options

Credit Card sizing

Credit Card fonts

Credit Card styling

Credit Card brands

Development

Here's how you can get started developing locally:

$ git clone https://github.com/amarofashion/react-credit-cards.git
$ cd react-credit-cards
$ npm install
$ npm start

Now, if you go to http://localhost:3000 in your browser, you should see the demo page.

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process of contributing to the project.

Useful links

EBANK's test numbers
Adyen's test numbers
Worldpay's test card numbers
Brazilian cards patterns

LICENSE

This project is licensed under the MIT License.

Made with ❤️ at AMARO.