-
Notifications
You must be signed in to change notification settings - Fork 16
/
CustomerExample.html
83 lines (68 loc) · 2.86 KB
/
CustomerExample.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<html>
<head>
<title>Nessie | Simple Example</title>
<!-- Nessie Required Files -->
<script data-main="lib/capital_one" src="lib/require-jquery.js"></script>
<!-- Some Basic Stylin' -->
<style>
body { font-family: 'Helvetica', 'Arial' }
div { font-family: 'Menlo', 'Courier New' }
</style>
</head>
<body>
<h1>Nessie is Real!</h1>
<!-- HTML Layout -->
<!-- see the JavaScript code below for logic & details -->
<h3>Creating a Customer</h3>
<div id="postCustomer">Uncomment postCustomer() in the source code!</div>
<h3>Retrieving a Customer</h3>
<div id="getCustomer"></div>
<!-- API Call Examples -->
<script type="text/javascript">
// Set API key here!
var apiKey = 'MY API KEY';
// sample names for customer and account nickname
var customerFirstName = "Missy";
var customerLastName = "Elliot";
$(function() {
// set the modules being used
require(['customer'], function (customer) {
// initialize customer and account
var cust = customer.initWithKey(apiKey);
// make the API Calls
//postCustomer(apiKey, cust);
getCustomer(apiKey, cust);
});
});
function postCustomer (key, cust) {
// build customer data
var newCustDetails ="{ \"first_name\": \"" + customerFirstName + "\", \"last_name\": \"" + customerLastName + "\", \"address\": { \"street_number\": \"1\", \"street_name\": \"Capital One Dr.\", \"city\": \"McLean\", \"state\": \"VA\", \"zip\": \"22102\" } }";
// make the API call, returns response code
var responseCode = cust.createCustomer(newCustDetails);
// console logging and update web page
console.log("[Customer - Create Customer] Response Code: " + responseCode);
$('#postCustomer').html("Create Customer: Response Code <b>" + responseCode + "</b>")
}
function getCustomer (key, cust) {
var allCustomers = cust.getCustomers();
var myCustomer = null;
// loop through all customers and log their info
console.log("[Customer - Get All Customers]");
for (var i = 0; i < allCustomers.length; i++) {
var firstName = allCustomers[i].first_name;
var lastName = allCustomers[i].last_name;
console.log("Customer[" + i + "]: " + firstName + " " + lastName);
// take note of the customer we created
if(firstName == customerFirstName && lastName == customerLastName) {
myCustomer = allCustomers[i];
}
}
// display the customer we created
var fullName = myCustomer.first_name + " " + myCustomer.last_name
console.log("[Customer - My Customer] " + fullName);
$('#getCustomer').html("Results: <b>" + allCustomers.length + "</b>" + " customers retrieved, please see developer console for full list.<br/>");
$('#getCustomer').append("My Customer: <b>" + fullName + "</b>");
}
</script>
</body>
</html>