Giter Site home page Giter Site logo

jessepollak / card Goto Github PK

View Code? Open in Web Editor NEW
11.6K 240.0 1.5K 2.22 MB

:credit_card: make your credit card form better in one line of code

License: MIT License

HTML 3.01% CoffeeScript 26.34% JavaScript 2.69% SCSS 67.96%
javascript jquery credit-card payments coffeescript css

card's Introduction

npm

Card - check out the demo

A better credit card form in one line of code

Card will take any credit card form and make it the best part of the checkout process (without you changing anything). Everything is created with pure CSS, HTML, and Javascript — no images required.

card

Usage (without jQuery)

To use, you'll need to include the Card JavaScript files into your HTML, no CSS link is necessary as the JavaScript file does this for you. You can find the necessary file at /dist/card.js and include it in your HTML like so.

<!-- at the end of BODY -->
<!-- CSS is included via this JavaScript file -->
<script src="/path/to/card.js"></script>

Once you've included those files, you can initialize Card.

var card = new Card({
    // a selector or DOM element for the form where users will
    // be entering their information
    form: 'form', // *required*
    // a selector or DOM element for the container
    // where you want the card to appear
    container: '.card-wrapper', // *required*

    formSelectors: {
        numberInput: 'input#number', // optional — default input[name="number"]
        expiryInput: 'input#expiry', // optional — default input[name="expiry"]
        cvcInput: 'input#cvc', // optional — default input[name="cvc"]
        nameInput: 'input#name' // optional - defaults input[name="name"]
    },

    width: 200, // optional — default 350px
    formatting: true, // optional - default true

    // Strings for translation - optional
    messages: {
        validDate: 'valid\ndate', // optional - default 'valid\nthru'
        monthYear: 'mm/yyyy', // optional - default 'month/year'
    },

    // Default placeholders for rendered fields - optional
    placeholders: {
        number: '•••• •••• •••• ••••',
        name: 'Full Name',
        expiry: '••/••',
        cvc: '•••'
    },

    masks: {
        cardNumber: '•' // optional - mask card number
    },

    // if true, will log helpful messages for setting up Card
    debug: false // optional - default false
});

Installing card from bower

If you're using bower, you can install card.js with:

bower install card --save

Installing card from npm

If you're using npm, you can install card.js with:

npm install --save card

var $ = require("jquery");
// The current card.js code does not explictly require jQuery, but instead uses the global, so this line is needed.
window.jQuery = $;
var card = require("card");

Using multiple inputs for one field

Card can be used in forms where you have multiple inputs that render to a single field (i.e. you have a first and last name input). To use Card with this functionality, just pass in a selector that selects the fields in the correct order. For example,

<html>
<body>
<div class='card-wrapper'></div>
<!-- CSS is included via this JavaScript file -->
<script src="/path/to/card.js"></script>
<form id="cc-form">
    <input type="text" name="number">
    <input type="text" name="first-name"/>
    <input type="text" name="last-name"/>
    <input type="text" name="expiry"/>
    <input type="text" name="cvc"/>
</form>
<script>
var card = new Card({
    form: 'cc-form',
    container: '.card-wrapper',

    formSelectors: {
        nameInput: 'input[name="first-name"], input[name="last-name"]'
    }
});
</script>
</body>
</html>

Rendering with different initial card placeholders

Card renders with default placeholders for card name, number, expiry, and cvc. To override these placeholders, you can pass in a placeholders object.

<html>
<body>
<div class='card-wrapper'></div>
<!-- CSS is included via this JavaScript file -->
<script src="/path/to/card.js"></script>
<form id="cc-form">
    <input type="text" name="number">
    <input type="text" name="name"/>
    <input type="text" name="expiry"/>
    <input type="text" name="cvc"/>
</form>
<script>

var card = new Card({
    form: 'cc-form',
    container: '.card-wrapper',

    placeholders: {
        number: '**** **** **** ****',
        name: 'Arya Stark',
        expiry: '**/****',
        cvc: '***'
    }
});
</script>
</body>
</html>

Translation

To render the card with the strings in a different language, you can pass in a messages object.

<html>
<body>
<div class='card-wrapper'></div>
<!-- CSS is included via this JavaScript file -->
<script src="/path/to/card.js"></script>
<form id="cc-form">
    <input type="text" name="number">
    <input type="text" name="name"/>
    <input type="text" name="expiry"/>
    <input type="text" name="cvc"/>
</form>
<script>

var card = new Card({
    form: 'cc-form',
    container: '.card-wrapper',

    messages: {
        validDate: 'expire\ndate',
        monthYear: 'mm/yy'
    }
});
</script>
</body>
</html>

Using with jQuery

To use with jQuery, you'll need to include the jquery.card.js file into your HTML. You can find the necessary file at /dist/jquery.card.js and include it in your HTML like so.

<!-- at the end of BODY -->
<!-- CSS is included via this JavaScript file -->
<script src="/path/to/jquery.card.js"></script>

Once you've included those files, you can initialize Card with jQuery.

$('form').card({
    // a selector or DOM element for the container
    // where you want the card to appear
    container: '.card-wrapper', // *required*

    // all of the other options from above
});

Using with other javascript libraries

Card has wrappers that make it easy to use with other javascript libraries:

Angular 1.x

Angular 2+

Ember

React

Vue

For use with VueJs, install card.js from npm:

npm install card --save

Add in your component an Div with class 'card-wrapper', just pass in a selector that selects the fields in the correct order. Import the component card.js and add the object in instance mounted like this example:

<div class='card-wrapper'></div>

<form>
    <input type="text" name="number">
    <input type="text" name="first-name"/>
    <input type="text" name="last-name"/>
    <input type="text" name="expiry"/>
    <input type="text" name="cvc"/>
</form>

<script>
import * as Card from "card";

export default {
    name: "Form CreditCard",
    mounted() {
    new Card({ 
      form: "form#cc-form",
      container: ".card-wrapper",
      formSelectors: { 
        numberInput: "input#cc-number",
        expiryInput: "input#cc-expiration",
        cvcInput: "input#cc-cvv",
        nameInput: "input#cc-name"
      },
      width: 270,
      formatting: true,
      placeholders: {
        number: "•••• •••• •••• ••••",
        name: "Nome Completo",
        expiry: "••/••",
        cvc: "•••"
      }
    });
  },
}
</script>

Development

To contribute, follow this steps:

$ git clone --recursive https://github.com/jessepollak/card.git
$ cd card
$ git submodule init && git submodule update
$ npm install
$ npm run development

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

Places using Card

Card is used in the wild in these places:

Are you using Card in production? If so, we'd love to link to you from this page. Open a PR or drop @jessepollak a line on Twitter and we'll add you right away!

Project scope

The project scope is to improve the capture of payment cards on websites. Issues and fixes related to the user interface and validating of payment cards are in scope.

For questions on how to use Card in your particular project, please ask on Stack Overflow or similar forum.

Donations

If you'd like to donate to help support development of Card, send Bitcoin directly to 17NUKd3v7GWben18kGhmFafa4ZpWrXpQSC or through Coinbase here.

card's People

Contributors

adamjlev avatar allenan avatar alokedesai avatar andymockli avatar annieh avatar apaleslimghost avatar appleboy avatar ballisticpain avatar baltasarparreira avatar danieljuhl avatar davidreinberger avatar dblandin avatar dependabot[bot] avatar dominotree avatar euclio avatar hernan avatar iigmir avatar iwootten avatar jacquesloubser avatar jessepollak avatar jonathongrigg avatar kambanwait avatar lovespirals avatar luanmuniz avatar manioube avatar melloware avatar mikemaccana avatar sheck avatar sith-lord-vader avatar sorgrum 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  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

card's Issues

Compiled CSS oddities

See: https://github.com/jessepollak/card/blob/master/lib/css/card.css#L407

This line has one linear-gradient with a -webkit- prefix despite the rest not having the prefix.

Also I have no idea why the background-images are repeated twice each. The single difference is in the sheen on the top left. The top one has a degree of 245 and the other has -115, functionally identical in every way.

I'm not used to scss, so I couldn't find the issue at hand.

SSL vs HTTP submission of CC Strings

Link redirects to HTTP when I click the HTTPS URL in the readme.md

Perhaps the script could detect whether it's running on a secure protocol.

So - run some sort of sniffer script which alerts the user if he/she is submitting data through plaintexted HTTP, and also NEVER allow non-secure HTTP AJAX Posts/Submissions of such data.

I am aware this script caters to the UI aspect, and doesn't concern itself with the AJAX plumbing, but I don't see how it would play nice with security professionals who design these systems defensively from the very beginning.

CVV not displayed in IE10

In Internet Explorer 10, the back of the card is transparent (meaning it shows the content on the front of the card) and also flipped, and the CVV doesn't appear at all.

Is IE10 on the list of supported browsers?

Allow card types to be excluded

Does this project allow for excluding card types? Let's say I have a company that only accepts Visa and MasterCard and NO Amex. Can I prevent Amex cards from showing the graphics?

Minimum font sizes break credit card logos

Chrome has this nifty little feature that it doesn’t allow fonts to go under a specific size (6pt is the minimum, the value is user-configurable; don’t remember the default setting though). However, Discover and AmEx logos are broken by that, and look like crap (network in Discover is off-center; AmEx is a complete mess).

image
image

npm install errors

I followed the developer instructions i.e to clone and then run an npm install however the npm install fails with an error.

The error appears to be: npm ERR! Error: No compatible version found: gulp@'^3.7.0'

I am new to node package management - is there something I am missing?

Here is the full output to the console:

G:\Users\Darrell\Source\Repos\card>npm install
npm http GET https://registry.npmjs.org/jquery
npm http GET https://registry.npmjs.org/jquery.payment
npm http GET https://registry.npmjs.org/gulp
npm http GET https://registry.npmjs.org/coffee-script
npm http GET https://registry.npmjs.org/bower
npm http GET https://registry.npmjs.org/gulp-browserify
npm http GET https://registry.npmjs.org/gulp-sass
npm http GET https://registry.npmjs.org/gulp-autoprefixer/0.0.7
npm http GET https://registry.npmjs.org/gulp-livereload
npm http GET https://registry.npmjs.org/coffeeify
npm http GET https://registry.npmjs.org/tiny-lr/0.0.7
npm http GET https://registry.npmjs.org/nodemon
npm http GET https://registry.npmjs.org/gulp-rename
npm http GET https://registry.npmjs.org/gulp-changed
npm http GET https://registry.npmjs.org/gulp-clean
npm http GET https://registry.npmjs.org/gulp-connect
npm http GET https://registry.npmjs.org/run-sequence
npm http GET https://registry.npmjs.org/gulp-open
npm http 304 https://registry.npmjs.org/coffee-script
npm http 304 https://registry.npmjs.org/jquery.payment
npm http 304 https://registry.npmjs.org/gulp-sass
npm http 304 https://registry.npmjs.org/gulp-autoprefixer/0.0.7
npm http 304 https://registry.npmjs.org/gulp-browserify
npm http 304 https://registry.npmjs.org/jquery
npm http 304 https://registry.npmjs.org/gulp
npm ERR! Error: No compatible version found: gulp@'^3.7.0'
npm ERR! Valid install targets:
npm ERR! ["0.0.1","0.0.2","0.0.3","0.0.4","0.0.5","0.0.7","0.0.8","0.0.9","0.1.0
","0.2.0","1.0.0","1.1.0","1.2.0","1.2.1","2.0.0","2.0.1","2.1.0","2.2.0","2.3.0
","2.4.0","2.4.1","2.6.0","2.6.1","2.7.0","3.0.0","3.1.1","3.1.2","3.1.3","3.1.4
","3.2.0","3.2.1","3.2.2","3.2.3","3.2.4","3.2.5","3.3.0","3.3.1","3.3.2","3.3.4
","3.4.0","3.5.0","3.5.1","3.5.2","3.5.5","3.5.6","3.6.0","3.6.1","3.6.2","3.7.0
","3.8.0","3.8.1"]
npm ERR! at installTargetsError (G:\Program Files\nodejs\node_modules\npm\li
b\cache.js:685:10)
npm ERR! at G:\Program Files\nodejs\node_modules\npm\lib\cache.js:607:10
npm ERR! at saved (G:\Program Files\nodejs\node_modules\npm\node_modules\npm
-registry-client\lib\get.js:138:7)
npm ERR! at Object.oncomplete (fs.js:107:15)
npm ERR! If you need help, you may report this log at:
npm ERR! http://github.com/isaacs/npm/issues
npm ERR! or email it to:
npm ERR! [email protected]

npm ERR! System Windows_NT 6.2.9200
npm ERR! command "G:\Program Files\nodejs\node.exe" "G:\Program Files\nod
ejs\node_modules\npm\bin\npm-cli.js" "install"
npm ERR! cwd G:\Users\Darrell\Source\Repos\card
npm ERR! node -v v0.10.4
npm ERR! npm -v 1.2.18
npm http 304 https://registry.npmjs.org/coffeeify
npm http 304 https://registry.npmjs.org/gulp-livereload
npm http 304 https://registry.npmjs.org/gulp-rename
npm http 304 https://registry.npmjs.org/nodemon
npm http 304 https://registry.npmjs.org/gulp-changed
npm http 304 https://registry.npmjs.org/gulp-clean
npm http 304 https://registry.npmjs.org/bower
npm http 304 https://registry.npmjs.org/gulp-connect
npm http 304 https://registry.npmjs.org/tiny-lr/0.0.7
npm http 304 https://registry.npmjs.org/gulp-open
npm http 304 https://registry.npmjs.org/run-sequence
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! G:\Users\Darrell\Source\Repos\card\npm-debug.log
npm ERR! not ok code 0

G:\Users\Darrell\Source\Repos\card>

Implement name length checks and year validation

image

The Name field doesn't appear to have any length checks. The MM/YY field accepts 13 to 19 as a valid month, and up to 9999 as a valid year. It also accepts years less than the current year.

Add to bower

Adding this to bower would make it a lot more easily usable.

Card not rendered when using paste

When I paste a card number into the form and use only the mouse (no keyboard events) the card is not rendered correctly. No numbers appear on the card graphic however formatting is done to the pasted value.

Support for ASP.net Web Forms

This this is awesome, great work.

I cannot get the plugin to work with ASP.net web forms. I believe it has something to do with having the form tag on every page and not just around the form itself.

Publish to NuGet?

Any chance of having this packaged and published to http://www.nuget.org/ so us Microsoft Visual Studio users can easily incoprorate this into our .NET applications as a NuGet Package?

If you can call an .exe during the build process then it should be super simple to do!

Default value set to card render

I'm having the issue that after the form is ran and there are validation errors the card render is back to it's blank state while the form still displays input in the fields.

I'd like for the card to be able to render on load with default values.

SSL

Whilst I appreciate this is a demo - the SSL/HTTP link is more preferable. Just incase. It's highly unlikely anyone would be entering sensitive data. But I've seen stranger things:

https://jessepollak.github.io/card/

Ability to replace card detection method

Many payment providers have their own card detection and they get updated pretty often, this way the developer gets too choose to use their payment providers ones or built-in one.

Add better error messages for missing inputs

Right now, if your form doesn't contain the correct inputs (or you select the wrong form), you're just going to get a JS undefined error. For less technical users, it would be helpful to explicitly warn when certain inputs are missing.

This would help with solves #30.

Missing front view

Missing some critical toggle styles:
screenshot from 2014-06-05 09 49 57

using: Google Chrome Version 34.0.1847.132
Work as expected After adding the following in chrome devtools:

div.card .front {
  display: block;
}
div.card .back {
  display: none;
}

div.card.flipped .front {
  display: none;
}
div.card.flipped .back {
  display: block;
}

Focus on text input when rendered part of card is clicked

When clicking on card-number or other parts of the image, a focus on that text field would be nice. I found my self clicking there and it felt odd not being able to edit in-place.

Also when a text field is focused a highlight could be nice to have on the card itself.

Auto fill by browsers does not trigger re-render

Using the arrow keys to select an existing entry in the form history then pressing tab to select it and continue to the next input field does not update the visual display.

Firefox 29 on OS 10.9

Font on the <body>

I think that you shouldn't set the font on the body.
It can change the look of the entire page.

body {
font-family: $card-font-family;

Handle non utf-8 browser rendering

Hi,

I tried this repository for my website. I used this:

<!DOCTYPE html>
<html lang="de"><head><style><endnote><head>
<style><endnote><head>
<style><endnote><head>
<style><endnote><head>
<style></style>
<script></script><title>Card &#8212; the better way to collect credit cards</title>

<link rel="stylesheet" href="http://suriyaakudo.bplaced.net/projects/card/lib/css/card.css">
</head>
<body>
<style>
.demo-container {
width: 350px;
margin: 50px auto;
}
form {
margin: 30px;
}
input {
width: 200px;
margin: 10px auto;
display: block;
}
</style>
<div class="demo-container">
<div class="card-wrapper"></div>
<div class="form-container active">
<form action=""><input placeholder="Card number" name="number" type="text"><input placeholder="Full name" name="name" type="text"><input placeholder="MM/YY" name="expiry" type="text"><input placeholder="CVC" name="cvc" type="text"></form>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://suriyaakudo.bplaced.net/projects/card/lib/js/card.js"></script>
<script>
$('.active form').card({ container: $('.card-wrapper')})
</script>
</body></html>

Where should I paste this:

$('form').card({
    // a selector or jQuery object for the container
    // where you want the card to appear
    container: '.card-wrapper', // *required*
    numberInput: 'input#number', // optional — default input[name="number"]
    expiryInput: 'input#expiry', // optional — default input[name="expiry"]
    cvcInput: 'input#cvc', // optional — default input[name="cvc"]
    nameInput: 'input#name', // optional - defaults input[name="name"]

    width: 200, // optional — default 350px
    formatting: true // optional - default true
});

???

Yours
Suriyaa Kudo

Improve font colour on unrecognized card type

You might want to change the colour of the font for better contrast when it can't recognize the card type.

Ie. if I type in a random number just to see how it works, I can barely see what I'm typing in on the card due to the lack of contrast.

Radial gradients are broken in Safari

Safari chokes on the radial gradients with super high transparency. For now, I've disabled them by checking user agent and disabling for Safari, but I'd like to find a way to make them work.

tab navigation not working

If you use tab to navigate through the form fields, it never gets to CVC (whereas without using the card plugin it works just fine).
Tested in firefox 30 and chrome 34.
EDIT: I realized just now that tab wasn't working because the date value wasn't valid. What are you guys doing to show validation errors? (without doing another validation on the field)

Add additional card types

I'm not sure how many cards this affects, but here's an example:

Type in 62 into the card entry. It should be UnionPay. It's nothing. Try 622. It should be Discover. Nothing.

Furthermore, 622 is not a Discover card prefix, it's a UnionPay prefix. The program is missing a few card numbers as well.

See: the Wikipedia page

Add slide-out as optional replacement for CVC card rotation

I find that the 3d rotation is too grand. I would suggest another solution.
As soon as the form is recognizing a card which has CVC at the back.
The backside of the card will slide quickly into the image and "greyed", when user selects the CVC field, the front/back changes focus according to the image.

When entering card details you really want to disturb the user as little as possible as it can affect CR.

suggestion

Allow values to be prefilled

Sometimes values may be prefilled on page load. Currently to display values like this, one must manually trigger the keyup/change event, even if all the info is there and accurate.

Demo is blocked by highlighter not loading

Saw this a few days ago and it worked great on Chrome for iOS, but honestly don't know if I looked at it with desktop Chrome or not.

Got back to the office today and it doesn't display the card at all, the form controls all work and the "demo" keystrokes play, but no visuals of the card at all at least with Chrome Version 35.0.1916.114 for OSX.

Missing semicolon in build version

I see this plugin is wrapped after its been converted from Coffeescript.

There isn't a semi colon at the end of the browserify shim, which causes this to fail in my build process -- which concat's a bunch of JS files together.

Allow for bypass of expiry format

Some credit card processors require the expiry date to be in MMYY format.
This script forces the value to be MM/YY format. I realize that I could strip the slash before sending the value to the processor, but doing this is inconvenient.
Would it make sense to utilize a bypass option for this value's format?

Inplace input/select fields

Would be awesome to also offer built-in input and select boxes.
The init method could receive as arguments the input/select field names and select boxes could optionally get the option values/titles.

I know this might not be the goal of this project, but would probably be awesome.
I was almost implementing my own version of https://dribbble.com/shots/660725-Credit-Card-Form for our checkout process, but looks like I'll be using yours now.

Card should handle `value` values correctly in initial rendering

When the form is partially pre-filled with address data, it should display this on the card.

I can't figure out how to get it take the pre-fill data and use it, tabbing around the form causes the image to update, but triggering clicks, focus, change, etc does not. Also, it only updates the image with pre-fill data from a field you tab into focus, not tabbing out (blur).

What's the easiest way to update the image with data place in the form from the DB?

Cannot turn formatting off in the options

It seems that the default formatting setting (true) overwrites whatever you add in.

I think it's because of line (547)

this.options = $.extend({}, opts, this.defaults);

I think you want to swap the user options to after your provided defaults so they override.

I'll make a quick PR with the change

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.