Skip to content

Commit

Permalink
added CC validation and payment documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
RIAEvangelist committed Sep 23, 2015
1 parent d88077c commit 6a47a2e
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -444,8 +444,16 @@ You don't have to do anything for the payment, Domino's Pizza will handle all tr

var pizzapi=require('dominos');

var cardNumber='4100123422343234';

var cardInfo = new order.PaymentObject();
cardInfo.Amount = order.Amounts.Customer;
cardInfo.Number = cardNumber;
cardInfo.CardType = order.validateCC(cardNumber);
cardInfo.Expiration = '0115';// 01/15 just the numbers "01/15".replace(/\D/g,'');
cardInfo.SecurityCode = '777';
cardInfo.PostalCode = '90210'; // Billing Zipcode

order.Payments.push(cardInfo);

order.place(
Expand Down
36 changes: 36 additions & 0 deletions src/Order.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,42 @@ Order.prototype.mergeResponse = function(callback,response){
}
}

Order.prototype.validateCC=function(number){
var re = {
visa : /^4[0-9]{12}(?:[0-9]{3})?$/,
mastercard : /^5[1-5][0-9]{14}$/,
amex : /^3[47][0-9]{13}$/,
diners : /^3(?:0[0-5]|[68][0-9])[0-9]{11}$/,
discover : /^6(?:011|5[0-9]{2})[0-9]{12}$/,
jcb : /^(?:2131|1800|35\d{3})\d{11}$/,
enroute : /^(?:2014|2149)\d{11}$/
};

if (re.visa.test(number))
return 'VISA';

if (re.mastercard.test(number))
return 'MASTERCARD';

if (re.amex.test(number))
return 'AMEX';

if (re.diners.test(number))
return 'DINERS';

if (re.discover.test(number))
return 'DISCOVER';

if (re.jcb.test(number))
return 'JCB';

if (re.enroute.test(number))
return 'JCB';

return "";
}
}

Order.prototype.PaymentObject=function(){
Object.defineProperties(
this,
Expand Down

0 comments on commit 6a47a2e

Please sign in to comment.