Coder Social home page Coder Social logo

pagarme / react-payment-card-component Goto Github PK

View Code? Open in Web Editor NEW
99.0 102.0 18.0 1.56 MB

:credit_card: A modern credit card component for React

Home Page: https://pagarme.github.io/react-payment-card-component

License: MIT License

JavaScript 68.21% CSS 31.79%
credit-cards react-component

react-payment-card-component's Introduction

React Payment Card Component | GitHub license Travis CI Status

A modern credit card component for React

React Payment Card Component

This React component will help you building your checkout on your e-commerce.

The first version of a payment card modal was used in Pagar.me's checkout 1.0, but as we're now rewriting it to version 2.0 in React, why not creating a component so people also can use it the way they prefer?

By having a lot of credit cards from many different banks, brands and types, users will be able to see a digital version of their credit cards as they type the credit card number.

Check it live at https://pagarme.github.io/react-payment-card-component

Usage

To use this component in your React app, start by adding it to the project dependencies list:

npm version > 5

npm i react-payment-card-component

npm version < 5

npm i react-payment-card-component --save

yarn

yarn add react-payment-card-component

And then, import it:

import PaymentCard from 'react-payment-card-component'

render () {
  return (
    <PaymentCard
      bank="itau"
      model="personnalite"
      type="black"
      brand="mastercard"
      number="4111111111111111"
      cvv="202"
      holderName="Owen Lars"
      expiration="12/20"
      flipped={false}
    />
  );
}

Flipping the card

You can use React to manage the card state and implement your own logic, like flipping the card with a button or when user is typing the CVV (Card Verification Value).

flipCard () {
  const flipped = !this.state.flipped
  this.setState({ flipped })
}

Available Props

Name Type Required Description
bank String true The bank prop defines the major style for the card, like the elements positions, background color and logos. Examples.: default, itau, santander, nubank
model String false Model refers to the card model. Examples.: normal, prime, personnalite
type String false (although it's not required, some styles may not properly work without it) The type is used alongside with bank and model to get the final card styling. They are the types of a credit card that each bank can emit. Examples.: gold, black, platinum
brand String true This prop is used to get the correct logo and position of the brand used in the card. Examples: mastercard, visa.
number String false The card number printed in the card
cvv String false 3-digit CVV (Card Verification Value)
holderName String false The holder name as printed in the card
expiration String false The expiration month and year following the pattern: MM/YY
flipped Boolean false If true the backface of the card will be shown

Customizing

Styling

The CSS files to manage the banks styles are under ./src/components/PaymentCard/styles, where each bank needs its own file under the banks folder and have it imported in the main ./src/components/PaymentCard/styles/index.css file.

To add a new style, remember to create classes following the pattern: bankName-cardModel-cardType:

.santander-normal-black {
  background: #000000;
}

Logos

We currently have 3 types of logos:

  • bankLogo
  • brandLogo
  • modelLogo

If you need to add new assets for corresponding logos, do it under the proper component folder in the images folder.

Guidelines

  • Prefer .svg files or .png (in that order)
  • Keep them as small as possible, even if they are going to be compressed in the build process

Contributing

We're always happy with contributors helping us evolving this project, so feel free to warn us about any bugs you found, new features you think might be cool for the project and also by adding new banks so we can have a lot of different credit cards.

Start by reading our Contributing guide and checking our Issues page.

License

This project is licensed under MIT License

react-payment-card-component's People

Contributors

augusto-jm-amaral avatar marcoworms avatar thgmhz avatar vcapretz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-payment-card-component's Issues

Default classes

React props already provide us a validation for non-implemented banks and/or brands, but it would be nice to add default values so the component will at least properly render

Could not find package on the "npm" registry

Description

Yarn and npm are failing when trying to install the module:

  • Yarn

error Couldn't find package "react-payment-card-component" on the "npm" registry.
2017-11-28-142406_633x113_scrot

  • npm
    2017-11-28-142603_645x114_scrot

Did you publish the project under this name?

Refatorar arquitetura de estilos

Hoje temos 3 níveis de variação que um cartão pode ter:

  • banco
  • modelo
  • tipo

e a lógica que utilizamos foi ter uma classe banco e outra classe concatenando os 3: banco-modelo-tipo. Mas aqui estamos repetindo o banco e evitando coisas compartilhadas

Exemplo: todos os cartões bancoX podem ter um logo só;
a maioria dos cartões modeloY tem um tipo de bandeira, mas pode ser diferente para outros casos.

A solução atual permite que sigamos a regra do styleLint de que não podemos ter mais de 2 condições (não permitindo .banco .modelo .tipo.

Há duas coisas possíveis a serem feitas:

  • Remover regra do lint e refatorar para que usemos o padrão definido acima, já que o lint nesse caso não se aplica.
  • css-modules

Alterar o nome do projeto

Conforme discutimos nessa Issue: #7

Vamos alterar o nome do projeto para react-payment-card-component, basicamente precisamos alterar o package.json, o README.md e o nome do repositório aqui no Github.

Sugestão: escrever readme pra esse repo

Seria legal ter um readme pro projeto ja desde o inicio pois assim todo mundo que chegar pra contribuir consegue entender qual é a interface desejada pro projeto. Escrever readme antes do código é sempre bom pq funciona mais ou menos como um "tdd" da sua interface, vc primeiro escreve como vc quer usar isso pra depois implementar.

Título do projeto/componente

A ideia principal do componente não bate com o seu título. O termo Card(s) é referente a cartões/cartas e o mesmo pode ser referente a cartas de jogo, tarô, correio, etc.

A sugestão é alterar o termo cards para Payment Cards ou até mesmo Credit Cards (se o projeto final for referente somente a isso). Essas considerações são baseadas em questões de pesquisa, já que, por relevância, os primeiros resultados apresentados serão justamente os citados acima (cartas de jogo, tarô, correio, etc).

Proposta de mudança na API do projeto

Atualmente nossa interface está assim:

<PaymentCard
   bank="bradesco"
   type="black-prime"
   brand="mastercard"
   number="4111111111111111"
   cvv="123"
   holderName="Fulano de Tal"
   expiration="12/19"
/>

Repare que o type está recebendo dois valores, o tipo do cartão na verdade é apenas prime, o black deveria estar em outra propriedade que eu ainda não sei qual nome deveria ter.

O problema da implementação atual é que recebemos 2 dados em um: black-prime, e para tratar esse dado a gente da um split e depois capitaliza o valor pra ficar blackPrime, será que isso não é overengineering?

Dado que os cartões geralmente tem 3 atributos, exemplo: Bradesco - Prime - Gold, acredito que faz mais sentido criar uma nova propriedade, a questão é: qual o nome dessa propriedade que receberia valores como black, gold, electron, etc?

Backface visibility and safari

Description

On MacOS using safari the cvv and doesn't show up.

Checking about backface-visibility I could check that it is fact something we needed, but actually we are not flipping the back and front face, we are flipping the entire card, so browser doesn't know exactly which side is facing down or up.

A quick solution would be get rid of backface-visibility and use display: none, what do you think?

Another possible solution would be to correctly manage the transform property on each element that will be facing down or up.

My Setup

  • Operating system: MacOS High Sierra
  • Browser version: Safari 11.0
  • I have tested with the latest version
  • I can simulate the issue easily

Current Behavior

CVV is not visible

Expected Behavior

CVV should be visible when flipping the card

#ReferenceError: window is not defined

Hello, first I want to thank you for creating this amazing Card component. Second I have and issue that i can't fix with it. I'm using it on my React-NextJS project and it all went well and then suddenly it's starts poping these error messages about window not defined in node_modules\react-payment-card-component\lib\index.js:1:6721. Please can you help me out. Would be really thankful. Cheers.

Bug no verso do cartão

ao clicar no flip do cartão, durante a animação é possível ver o cvv e a tarja, mas quando a animação é concluída eles somem.

OS: MacOS High Sierra 10.13
Browser: Google Chrome 61.0.3163.100

screen shot 2017-11-06 at 18 07 25

Logo on the back of the card still showing

Description

Not sure if it's the intended effect, but some of the cards, when flipped, still display a backwards logo

My Setup

  • I have tested with the latest version
  • I can simulate the issue easily

Current Behavior

screenshot-2018-1-2 storybook

Expected Behavior

To not show the logo?

Add lint

Description

Add lint to help keep project design pattern.

Expected

Use Pagar.me lint settings, stylelint-config-pagarme-react for stylelint and pagarme-react for eslint.

SVGs de Logos

Change build settings

Description

Change configs to build a react component.

Current Behavior

Build a react application.

Expected Behavior

Build a react component.

Need to add className

Do not add the className to the root component.

It is not possible to add for example the location of the card with a class.

Should work like this:

const PaymentCard = ({
  bank,
  model,
  type,
  number,
  cvv,
  expiration,
  holderName,
  brand,
  flipped,
  className,
}) => (
  <div className={`${styles.wrapper} ${className}`}>

Remover node-sass

  • Remover node-sass
  • Adicionar postcss-cssnext, postcss-import, postcss-mixins, postcss-loader, postcss-sass-each, postcss-url como no projeto Pilot e Mercurio Checkout
  • Configurar stylelint do Pagar.me
  • Refatorar arquivos .scss para .css

Suggestion: update the card gif version

The current gif shows the first version of this card developed by Pagar.me, now that we have a new version it would be nice to have a new gif showing the new layout and/or some features (like changing the bank logo)

use devDependencies

all packages on package.json are currently placed inside "dependencies", we should use "devDependencies" as well, so for production envs or builds we could save time/storage.

I am not sure which packages can be placed in devdependencies and if it's really needed.

my first thoughts were:
babel and lint packages, webpack-dev-server, storybook

Need Help In Customising

Description

Hello, First of all, I would like to take a moment to appreciate the component made by the team. I need help in passing my own customized images through props bankLogo,brandLogo,modelLogo. i want to pass the image source which can be either static or dynamic. i don't need customization wrt to logo and brand positioning. just i need help with setting up my own logo on the card.. Can we achive that?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.