-
Notifications
You must be signed in to change notification settings - Fork 0
/
CustomerExample.html
115 lines (96 loc) · 4.24 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<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 = 'd2e249d455165a2e90f6131d49fe3345';
// 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);
getAccounts(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;
var id = allCustomers[i]._id;
var account =
console.log("Customer[" + i + "]: " + firstName + " " + lastName + " " + id);
// 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>");
}
function getAccounts (key, cust) {
var allAccounts = cust.getAllAccounts();
var myAccount = null;
// loop through all customers and log their info
console.log("[Accounts - Get All Accounts]");
for (var i = 0; i < allAccounts.length; i++) {
var id = allAccounts[i]._id;
var type = allAccounts[i].type;
var nickname = allAccounts[i].nickname;
var rewards = allAccounts[i].rewards;
var balance = allAccounts[i].balance;
var account_number = allAccounts[i].account_number;
var customer_id = allAccounts[i].customer_id;
console.log("Account[" + i + "]: " + id + " " + account_number);
// take note of the customer we created
// if(firstName == customerFirstName && lastName == customerLastName) {
// myAccount = 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>