-
Notifications
You must be signed in to change notification settings - Fork 319
Replace the payment dependency with credit-card-type and luhn #77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
cassiocardoso
wants to merge
14
commits into
master
Choose a base branch
from
feature/remove-payment
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
8233308
add credit-card-type and luhn libs
cassiocardoso 6d35369
deprecate payment
cassiocardoso b9b091f
add support for dankort, laser, and visa electron
cassiocardoso bd94b0b
remove unnecessary variables in the constructor
cassiocardoso 2106599
update readme
cassiocardoso dc34c1b
update my email
cassiocardoso 141c614
move configuration to its own file
cassiocardoso 9f50659
abstract card helpers logic
cassiocardoso 26f9770
move setCards call back to the constructor
cassiocardoso 8d436b7
use cardTypesMap to check for amex and diners
cassiocardoso 0bdc95c
remove preview check on the options getter
cassiocardoso 697141c
update local development instructions
cassiocardoso c739651
refactor validCardTypes
cassiocardoso 2e18b7f
fix setter function returning value
cassiocardoso File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| import creditCardType, { types as cardTypes } from 'credit-card-type'; | ||
| import luhn from 'luhn'; | ||
|
|
||
| import { dankort, laser, visaElectron } from './cardTypes'; | ||
|
|
||
| /** | ||
| * Check if a credit card number is valid using the Luhn algorithm | ||
| * @returns {boolean} | ||
| */ | ||
| export const validateLuhn = luhn.validate; | ||
|
|
||
| /** | ||
| * Given a credit card number in the format (XXXX XXXX XXXX...) return it as a string without any spaces | ||
| * @param {*} number | ||
| * @returns {string} number | ||
| */ | ||
| export const sanitizeNumber = (number) => number.toString().trim().replace(' ', ''); | ||
|
|
||
| /** | ||
| * Return the issuer of a given credit card number or `unknown` if the issuer can't be identified | ||
| * @param {string|number} cardNumber | ||
| * @returns {string} cardType | ||
| */ | ||
| export const getCardType = (cardNumber) => { | ||
| const potentialCardTypes = creditCardType(sanitizeNumber(cardNumber)); | ||
|
|
||
| if (potentialCardTypes.length === 1) { | ||
| const firstResult = potentialCardTypes.shift(); | ||
|
|
||
| return firstResult.type; | ||
| } | ||
|
|
||
| return 'unknown'; | ||
| }; | ||
|
|
||
| /** | ||
| * Configure the credit card types supported and return an array of valid types | ||
| * @returns {string[]} validCardTypes | ||
| */ | ||
| export const setInitialValidCardTypes = () => { | ||
| creditCardType.updateCard(cardTypes.MAESTRO, { | ||
| patterns: [ | ||
| 493698, | ||
| [5000, 5018], | ||
| [502000, 506698], | ||
| [506779, 508999], | ||
| [56, 59], | ||
| 63, | ||
| 67, | ||
| 6, | ||
| ], | ||
| }); | ||
|
|
||
| creditCardType.updateCard(cardTypes.HIPERCARD, { | ||
| patterns: [ | ||
| 384100, | ||
| 384140, | ||
| 384160, | ||
| 606282, | ||
| 637095, | ||
| 637568, | ||
| ], | ||
| }); | ||
|
|
||
| creditCardType.addCard(dankort); | ||
| creditCardType.addCard(laser); | ||
| creditCardType.addCard(visaElectron); | ||
|
|
||
| return Object.values(cardTypes).concat(['dankort', 'laser', 'visa-electron']); | ||
| }; | ||
|
|
||
| /** | ||
| * Provides a map of patterns to match for some card types | ||
| */ | ||
| export const cardTypesMap = { | ||
| amex: ['amex', 'americanexpress', 'american-express'], | ||
| dinersclub: ['diners', 'dinersclub', 'diners-club'], | ||
| visaelectron: ['visaelectron', 'visa-electron'], | ||
| }; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.