diff --git a/README.md b/README.md index 8fb8056..7f0ed2c 100644 --- a/README.md +++ b/README.md @@ -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( diff --git a/src/Order.js b/src/Order.js index 4287480..bab9203 100644 --- a/src/Order.js +++ b/src/Order.js @@ -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,