Created
November 9, 2015 03:13
-
-
Save mynamebrody/7a2847888596e67fd69b to your computer and use it in GitHub Desktop.
The AWS Lambda Function to order pizza via Dominos
This file contains 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
var pizzapi = require('dominos'); | |
// Setup your Default Store | |
// 6371 = Lafayette, CO 80026 | |
// Run `node findStore.js` and enter Zip Code | |
var myStore = new pizzapi.Store( | |
{ | |
ID: '6371' | |
} | |
); | |
// Setup your Address | |
var myAddress = new pizzapi.Address( | |
{ | |
Street: '900 Clark Ave', | |
City: 'St. Louis', | |
Region: 'MO', | |
PostalCode: '63102' | |
} | |
); | |
// Setup your Customer | |
var myCustomer = new pizzapi.Customer( | |
{ | |
firstName: 'Barack', | |
lastName: 'Obama', | |
address: myAddress, | |
phone: '1238675309', | |
email: 'barack@whitehouse.gov' | |
} | |
); | |
var order = new pizzapi.Order( | |
{ | |
customer: myCustomer, | |
storeID: myStore.ID | |
} | |
); | |
// Setup your Credit Card Info | |
var cardNumber='4100123422343234';// Valid but fake credit card | |
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); | |
function orderDominos(event, context) { | |
var clickType = event.clickType; | |
switch(clickType.toLowerCase()) { | |
case "single": { | |
// Setup your Default Order | |
// 14SCREEN = Large (14") Hand Tossed Pizza Whole: Cheese | |
order.addItem( | |
new pizzapi.Item( | |
{ | |
code: '14SCREEN', | |
options: {}, | |
quantity: 1 | |
} | |
) | |
); | |
break; | |
} | |
case "double": { | |
order.addItem( | |
new pizzapi.Item( | |
{ | |
code: '14SCREEN', | |
options: {}, | |
quantity: 2 | |
} | |
) | |
); | |
break; | |
} | |
case "long": { | |
order.addItem( | |
new pizzapi.Item( | |
{ | |
code: '14SCREEN', | |
options: {}, | |
quantity: 3 | |
} | |
) | |
); | |
break; | |
} | |
} | |
//Validate, price, and place order! | |
order.validate( | |
function(result) { | |
console.log("Order is Validated"); | |
} | |
); | |
order.price( | |
function(result) { | |
console.log("Order is Priced"); | |
} | |
); | |
order.place( | |
function(result) { | |
console.log("Price is", result.result.Order.Amounts, "\nEstimated Wait Time",result.result.Order.EstimatedWaitMinutes, "minutes"); | |
console.log("Order placed!"); | |
context.succeed(event); | |
} | |
); | |
} | |
exports.handler = orderDominos; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment