├── CustomerExample.html
├── README.md
└── lib
├── account.js
├── atm.js
├── bills.js
├── branch.js
├── capital_one.js
├── customer.js
├── deposit.js
├── example.html
├── merchant.js
├── purchase.js
├── require-jquery.js
├── tests
├── accountTests.js
├── atmTests.js
├── billTests.js
├── branchTests.js
├── customerTests.js
├── depositTests.js
├── merchantTests.js
├── purchaseTests.js
├── transferTests.js
└── withdrawalTests.js
├── transfer.js
├── unit_tests.html
└── withdrawal.js
/CustomerExample.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Nessie | Simple Example
5 |
6 |
7 |
8 |
12 |
13 |
14 | Nessie is Real!
15 |
16 |
17 |
18 | Creating a Customer
19 | Uncomment postCustomer() in the source code!
20 |
21 | Retrieving a Customer
22 |
23 |
24 |
25 |
82 |
83 |
84 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Nessie-JavaScript-SDK
2 | ## Synopsis
3 | Capital One Nessie API SDK written in JavaScript and wrapped in require-jquery. This SDK can be easily embedded in web apps.
4 | ## Installation for Web App
5 | 1. Download the lib directory.
6 | 2. Save the library in the web project directory.
7 | 3. Include the library in the header of the project (double check your directory path!) as shown below:
8 | ```javascript
9 |
10 | ```
11 | ## Usage
12 | 1. Require the Nessie library you intend to use, within the function to execute after the DOM is ready.
13 | 2. Set the api key. With the api key set, you're ready to use to client to get any data that you need.
14 | ```javascript
15 | $(function(){
16 | require(['account'], function (account) {
17 | var apikey = 'YOUR-API-KEY';
18 | accountDemo(apikey, account);
19 | });
20 | });
21 | ```
22 | Each Nessie client method returns an object which provides access to data for your desired use.
23 | ```javascript
24 | function accountDemo (apikey, account) {
25 | console.log('Account Demo');
26 | var custAccount = account.initWithKey(apikey);
27 | console.log("[Account - Get All] : Sample Account Nickname: (" + custAccount.getAllAccounts()[0].nickname + ")");
28 | }
29 | ```
30 | You can find examples [here](https://github.com/nessieisreal/nessie-javascript-sdk/blob/master/lib/example.html).
31 |
--------------------------------------------------------------------------------
/lib/account.js:
--------------------------------------------------------------------------------
1 | define('account', function (require) {
2 | "use strict";
3 | var Config = require('capital_one');
4 |
5 | var Account = {
6 | initWithKey: function(apiKey) {
7 | Config.setApiKey(apiKey);
8 | return this;
9 | },
10 | urlWithEntity: function() {
11 | return Config.baseUrl+'/accounts/';
12 | },
13 | urlWithCustomerEntity: function() {
14 | return Config.baseUrl+'/customers/';
15 | },
16 | apiKey: function() {
17 | return Config.apiKey;
18 | },
19 | /**
20 | # @Method: getAllAccounts
21 | # @Brief: Each index in the array is the JSON object of an individual customer.
22 | # @Returns an array of JSON objects getting all the customers.
23 | **/
24 | getAllAccounts: function() {
25 | var accounts;
26 | var request = $.ajax({
27 | url: this.urlWithEntity(),
28 | data: 'key='+this.apiKey(),
29 | async: false,
30 | dataType: 'json'});
31 |
32 | request.complete(function(results) {
33 | accounts = results.responseJSON;
34 | });
35 | return accounts;
36 | },
37 | /**
38 | # @Method: getAllByType
39 | # @Brief: Gets all accounts of a given type.
40 | # @Parameters: type
41 | # @Note: Accepts a string of the account type. 3 possbilities: Credit Card, Savings, Checking.
42 | # @Returns an array of JSON objects with the accounts.
43 | **/
44 | getAllByType: function(type) {
45 | var accounts;
46 | var request = $.ajax({
47 | url: this.urlWithEntity(),
48 | data: {'type': type, 'key': this.apiKey()},
49 | async: false,
50 | dataType: 'json'});
51 |
52 | request.complete(function(results) {
53 | accounts = results.responseJSON;
54 | });
55 | return accounts;
56 | },
57 | /**
58 | # @Method: getAccountById
59 | # @Brief: Returns the account specified by its account ID.
60 | # @Parameters: AccountId
61 | # @Note: Accepts a string of the account ID.
62 | # @Returns a JSON object with the account info.
63 | **/
64 | getAccountById: function(id) {
65 | var account;
66 | var request = $.ajax({
67 | url: this.urlWithEntity()+id,
68 | data: 'key='+this.apiKey(),
69 | async: false,
70 | dataType: 'json'});
71 |
72 | request.complete(function(results) {
73 | account = results.responseJSON;
74 | });
75 | return account;
76 | },
77 | /**
78 | # @Method: getAllByCustomerId
79 | # @Parameters: CustomerId
80 | # @Note: Accepts a string of the customer ID
81 | # @Returns all accounts associated with a given customer ID as an array of JSON objects.
82 | **/
83 | getAllByCustomerId: function(customerId) {
84 | var accounts;
85 | var request = $.ajax({
86 | url: this.urlWithCustomerEntity()+customerId+'/accounts',
87 | data: 'key='+this.apiKey(),
88 | async: false,
89 | dataType: 'json'
90 | });
91 |
92 | request.complete(function(results) {
93 | accounts = results.responseJSON;
94 | });
95 | return accounts;
96 | },
97 | /**
98 | # @Method: updateAccount
99 | # @Brief: Updates an account's nickname.
100 | # @Parameters: AccountID, Accountobject
101 | # @Returns the http response code.
102 | **/
103 | updateAccount: function(accountId, account) {
104 | var respCode;
105 | var request = $.ajax({
106 | url: this.urlWithEntity()+accountId+'?key='+this.apiKey(),
107 | data: JSON.parse(account),
108 | async: false,
109 | type: 'PUT'
110 | });
111 | request.complete(function(jqXHR, textStatus) {
112 | respCode = jqXHR.status;
113 | });
114 | return respCode;
115 | },
116 | /**
117 | # @Method: createAccount
118 | # @Brief: Creates a new account
119 | # @Parameters: CustomerID, accountobject
120 | # @Returns the http response code.
121 | **/
122 | createAccount: function(custID, account) {
123 | var respCode;
124 | var request = $.ajax({
125 | url: this.urlWithCustomerEntity()+custID+'/accounts?key='+this.apiKey(),
126 | data: account,
127 | contentType: 'application/json',
128 | async: false,
129 | type: 'POST'
130 | });
131 | request.complete(function(jqXHR, textStatus) {
132 | respCode = jqXHR.status;
133 | });
134 | return respCode;
135 | },
136 | /**
137 | # @Method: deleteAccount
138 | # @Brief: delete a given account by accountId.
139 | # @Parameters: AccountId.
140 | # @Returns the http response code.
141 | **/
142 | deleteAccount: function(accountId) {
143 | var respCode;
144 | var request = $.ajax({
145 | url: this.urlWithEntity()+accountId+'?key='+this.apiKey(),
146 | async: false,
147 | type: 'DELETE'
148 | });
149 | request.complete(function(jqXHR, textStatus) {
150 | respCode = jqXHR.status;
151 | });
152 | return respCode;
153 | }
154 | };
155 | return Account;
156 | });
157 |
--------------------------------------------------------------------------------
/lib/atm.js:
--------------------------------------------------------------------------------
1 | define('atm', function (require) {
2 | "use strict";
3 | var Config = require('capital_one');
4 |
5 | var Atm = {
6 | initWithKey: function(apiKey) {
7 | Config.setApiKey(apiKey);
8 | return this;
9 | },
10 | UrlWithEntity: function() {
11 | return Config.baseUrl+"/atms/";
12 | },
13 | apiKey: function() {
14 | return Config.apiKey;
15 | },
16 | /**
17 | # @Method: getAll
18 | # @Returns all ATMs as an array of JSON Objects.
19 | **/
20 | getAll: function() {
21 | var atms;
22 | var request = $.ajax({ url: this.UrlWithEntity(),
23 | data: 'key='+this.apiKey(),
24 | async: false,
25 | dataType: 'json'});
26 |
27 | request.complete(function(results) {
28 | atms = results.responseJSON;
29 | });
30 | return atms;
31 | },
32 | /**
33 | # @Method: getOne
34 | # @Brief: Gets one ATM for a given ID
35 | # @Parameters: AtmId
36 | # @Returns the ATM that has the given ID.
37 | **/
38 | getATM: function(id) {
39 | var atm;
40 | var request = $.ajax({ url: this.UrlWithEntity()+id,
41 | data: 'key='+this.apiKey(),
42 | async: false,
43 | dataType: 'json'});
44 |
45 | request.complete(function(results) {
46 | atm = results.responseJSON;
47 | });
48 | return atm;
49 | },
50 | /**
51 | # @Method: getAllByLocation
52 | # @Brief: Get all ATMs withing a certain radius of a geocoordinate
53 | # @Paremeters: latitude, longitude, radius
54 | # @Note: Accepts lat, lng, and rad as floats
55 | # @Returns an array of JSON Objects within the radius of the geocoordinate. Each hash has an ATM.
56 | **/
57 | getAtmByLocation: function(lat, lng, rad) {
58 | var atm;
59 | var request = $.ajax({ url: this.UrlWithEntity(),
60 | data: {'key': this.apiKey(), 'lat': lat, 'lng': lng, 'rad': rad},
61 | async: false,
62 | dataType: 'json'});
63 |
64 | request.complete(function(results) {
65 | atm = results.responseJSON;
66 | });
67 | return atm;
68 | }
69 | };
70 | return Atm;
71 | });
--------------------------------------------------------------------------------
/lib/bills.js:
--------------------------------------------------------------------------------
1 | define('bills', function (require) {
2 | "use strict";
3 | var Config = require('capital_one');
4 |
5 | var Bills = {
6 | initWithKey: function(apiKey) {
7 | console.log(apiKey);
8 | Config.setApiKey(apiKey);
9 | return this;
10 | },
11 | urlWithEntity: function() {
12 | return Config.baseUrl+'/bills/';
13 | },
14 | urlWithAccountEntity: function() {
15 | return Config.baseUrl+'/accounts/';
16 | },
17 | urlWithCustomerEntity: function() {
18 | return Config.baseUrl+'/customers/';
19 | },
20 | apiKey: function() {
21 | return Config.apiKey;
22 | },
23 | /**
24 | # @Method: getAllByAccountId
25 | # @Brief: Get all bills for a specific account
26 | # @Parameters: accountId
27 | # @Returns an array of objects containing the bills.
28 | **/
29 | getAllByAccountId: function(accID) {
30 | var bills;
31 | var request = $.ajax({
32 | url: this.urlWithAccountEntity()+accID+'/bills',
33 | data: 'key='+this.apiKey(),
34 | async: false,
35 | dataType: 'json'
36 | });
37 |
38 | request.complete(function(results) {
39 | bills = results.responseJSON;
40 | });
41 | return bills;
42 | },
43 | /**
44 | # @Method: getAllByCustomerId
45 | # @Brief: Get all bills for a specific customer
46 | # @Parameters: customerId
47 | # @Returns the customer as a object array.
48 | **/
49 | getAllByCustomerId: function(custID) {
50 | var bills;
51 | var request = $.ajax({
52 | url: this.urlWithCustomerEntity()+custID+'/bills',
53 | data: 'key='+this.apiKey(),
54 | async: false,
55 | dataType: 'json'
56 | });
57 |
58 | request.done(function(results) {
59 | bills = results;
60 | });
61 | return bills;
62 | },
63 | /**
64 | # @Method: getBill
65 | # @Brief: Gets a bill for a specific bill ID
66 | # @Parameters: bill ID
67 | # @Returns a object with the bill data
68 | **/
69 | getBill: function(id) {
70 | var bill;
71 | var request = $.ajax({
72 | url: this.urlWithEntity()+id,
73 | data: 'key='+this.apiKey(),
74 | async: false,
75 | dataType: 'json'
76 | });
77 |
78 | request.complete(function(results) {
79 | bill = results.responseJSON;
80 | });
81 | return bill;
82 | },
83 | /**
84 | # @Method: updateBill
85 | # @Brief: Updates an account's information by id with given json data.
86 | # @Parameters: BillId, BillJson
87 | # Json format is as follows:
88 | # {
89 | # "status": "",
90 | # "payee": "",
91 | # "nickname": "",
92 | # "payment_date": "",
93 | # "recurring_date": 0,
94 | # "payment_amount": 0
95 | # }
96 | # @Returns http response code.
97 | **/
98 | updateBill: function(id, json) {
99 | var respCode;
100 | var request = $.ajax({
101 | url: this.urlWithEntity()+id+'?key='+this.apiKey(),
102 | data: json,
103 | contentType: 'application/json',
104 | async: false,
105 | type: 'PUT'
106 | });
107 |
108 | request.complete(function(jqXHR, textStatus) {
109 | respCode = jqXHR.status;
110 | });
111 | return respCode;
112 | },
113 | /**
114 | # @Method: createBill
115 | # @Brief: create a new bill on an associated account ID
116 | # @Parameters: AccountId, Bill JSON
117 | # Json is as follows:
118 | # {
119 | # "status": "",
120 | # "payee": "",
121 | # "nickname": "",
122 | # "payment_date": "",
123 | # "recurring_date": 0,
124 | # "payment_amount": 0
125 | # }
126 | # @Returns http response code.
127 | **/
128 | createBill: function(accID, json) {
129 | var respCode;
130 | var request = $.ajax({
131 | url: this.urlWithAccountEntity()+accID+'/bills?key='+this.apiKey(),
132 | data: json,
133 | contentType: 'application/json',
134 | async: false,
135 | type: 'POST'
136 | });
137 | request.complete(function(jqXHR, textStatus) {
138 | respCode = jqXHR.status;
139 | });
140 | return respCode;
141 | },
142 | /**
143 | # @Method: deleteBill
144 | # @Brief: delete a bill by its id
145 | # @Parameters: Bill ID
146 | # @Returns http response code
147 | **/
148 | deleteBill: function(id) {
149 | var respCode;
150 | var request = $.ajax({
151 | url: this.urlWithEntity()+id+'?key='+this.apiKey(),
152 | async: false,
153 | type: 'DELETE'
154 | });
155 | request.complete(function(jqXHR, textStatus) {
156 | respCode = jqXHR.status;
157 | });
158 | return respCode;
159 | }
160 |
161 | };
162 | return Bills;
163 | });
--------------------------------------------------------------------------------
/lib/branch.js:
--------------------------------------------------------------------------------
1 | define('branch', function (require) {
2 | "use strict";
3 | var Config = require('capital_one');
4 |
5 | var Branch = {
6 | initWithKey: function(apiKey) {
7 | Config.setApiKey(apiKey);
8 | return this;
9 | },
10 | urlWithEntity: function() {
11 | return Config.baseUrl+"/branches";
12 | },
13 | apiKey: function() {
14 | return Config.apiKey;
15 | },
16 | /**
17 | # @Method: getAll
18 | # @Returns all Branches as an array of JSON Objects
19 | **/
20 | getAll: function() {
21 | var branches;
22 | var request = $.ajax({
23 | url: this.urlWithEntity(),
24 | data: 'key='+this.apiKey(),
25 | async: false,
26 | dataType: 'json'
27 | });
28 |
29 | request.complete(function(results) {
30 | branches = results.responseJSON;
31 | });
32 | return branches;
33 | },
34 | /**
35 | # @Method: getBranch
36 | # @Brief: Gets a branch for a specific branch ID
37 | # @Parameters: branch ID
38 | # @Returns a object with the branch data
39 | **/
40 | getBranch: function(id) {
41 | var branch;
42 | var request = $.ajax({
43 | url: this.urlWithEntity()+'/'+id,
44 | data: 'key='+this.apiKey(),
45 | async: false,
46 | dataType: 'json'
47 | });
48 |
49 | request.complete(function(results) {
50 | branch = results.responseJSON;
51 | });
52 | return branch;
53 | }
54 | };
55 | return Branch;
56 | });
--------------------------------------------------------------------------------
/lib/capital_one.js:
--------------------------------------------------------------------------------
1 | var VERSION = "0.1.0";
2 |
3 | require.config({
4 | baseUrl: 'lib/',
5 | context: VERSION,
6 | bundles: {
7 | 'main': ['capital_one', 'account', 'bills', 'atm', 'branch', 'customer', 'deposit', 'withdrawal','merchant', 'purchase', 'transfer']
8 | }
9 | });
10 |
11 | require(['account', 'atm', 'bills', 'branch', 'customer', 'deposit', 'withdrawal', 'merchant', 'purchase', 'transfer']);
12 |
13 | define('capital_one', function() {
14 | "use strict";
15 | var Config = {
16 | baseUrl: 'http://api.reimaginebanking.com:80',
17 | apiKey: function() {
18 | return this.apiKey;
19 | },
20 | setApiKey: function(apiKey) {
21 | this.apiKey = apiKey;
22 | }
23 | };
24 | return Config;
25 | });
26 |
--------------------------------------------------------------------------------
/lib/customer.js:
--------------------------------------------------------------------------------
1 | define('customer', function (require) {
2 | "use strict";
3 | var Config = require('capital_one');
4 |
5 | var Customer = {
6 | initWithKey: function(apiKey) {
7 | Config.setApiKey(apiKey);
8 | return this;
9 | },
10 | urlWithEntity: function() {
11 | return Config.baseUrl+"/customers/";
12 | },
13 | urlWithAcctEntity: function() {
14 | return Config.baseUrl+"/accounts/";
15 | },
16 | apiKey: function() {
17 | return Config.apiKey;
18 | },
19 | /**
20 | # @Method: getCustomers
21 | # @Brief: Gets all customers the API key has acccess to.
22 | # @Returns an array of JSON Objects.
23 | **/
24 | getCustomers: function() {
25 | var customers;
26 | var request = $.ajax({
27 | url: this.urlWithEntity(),
28 | data: 'key='+this.apiKey(),
29 | async: false,
30 | dataType: 'json'
31 | });
32 |
33 | request.done(function(results) {
34 | customers = results;
35 | });
36 | return customers;
37 | },
38 | /**
39 | # @Method: getCustomerById
40 | # @Brief: Gets the specified customer's information.
41 | # @Parameters: CustomerId
42 | # @Returns a object with the customer data
43 | **/
44 | getCustomerById: function(custId) {
45 | var customer;
46 | var request = $.ajax({
47 | url: this.urlWithEntity()+custId,
48 | data: 'key='+this.apiKey(),
49 | async: false,
50 | dataType: 'json'
51 | });
52 |
53 | request.done(function(results) {
54 | customer = results;
55 | });
56 | return customer;
57 | },
58 | /**
59 | # @Method: Get the customer for the given account.
60 | # @Parameters: AccountId
61 | # @Returns a object with the specified customer data.
62 | **/
63 | getCustomerByAcountId: function(accId) {
64 | var customer;
65 | var request = $.ajax({
66 | url: this.urlWithAcctEntity()+accId+'/customer',
67 | data: 'key='+this.apiKey(),
68 | async: false,
69 | dataType: 'json'
70 | });
71 |
72 | request.done(function(results) {
73 | customer = results;
74 | });
75 | return customer;
76 | },
77 | /**
78 | # @Method: updateCustomer
79 | # @Brief: Updates a customer by id with given JSON data.
80 | # @Parameters: CustomerId, Customerobject.
81 | # @Note: Json is as follows:
82 | # {
83 | # "address": {
84 | # "street_number": "",
85 | # "street_name": "",
86 | # "city": "",
87 | # "state": "",
88 | # "zip": ""
89 | # }
90 | # }
91 | # @Returns http response code.
92 | **/
93 | updateCustomer: function(custId, json) {
94 | var respCode;
95 | var request = $.ajax({
96 | url: this.urlWithEntity()+custId+'?key='+this.apiKey(),
97 | data: json,
98 | contentType: 'application/json',
99 | async: false,
100 | type: 'PUT'
101 | });
102 |
103 | request.complete(function(jqXHR, textStatus) {
104 | respCode = jqXHR.status;
105 | });
106 | return respCode;
107 | },
108 | /**
109 | # @Method: createCustomer
110 | # @Brief: Creates a customer with given JSON data.
111 | # @Parameters: Customerobject.
112 | # @Note: Json is as follows:
113 | #
114 | # {
115 | # "first_name": "",
116 | # "last_name": "",
117 | # {
118 | # "address": {
119 | # "street_number": "",
120 | # "street_name": "",
121 | # "city": "",
122 | # "state": "",
123 | # "zip": ""
124 | # }
125 | # }
126 | # }
127 | #
128 | # @Returns http response code.
129 | **/
130 | createCustomer: function(json) {
131 | var respCode;
132 | var request = $.ajax({
133 | url: this.urlWithEntity()+'?key='+this.apiKey(),
134 | data: json,
135 | contentType: 'application/json',
136 | async: false,
137 | type: 'POST'
138 | });
139 |
140 | request.complete(function(jqXHR, textStatus) {
141 | respCode = jqXHR.status;
142 | });
143 | return respCode;
144 | }
145 | };
146 | return Customer;
147 | });
--------------------------------------------------------------------------------
/lib/deposit.js:
--------------------------------------------------------------------------------
1 | define('deposit', function (require) {
2 | "use strict";
3 | var Config = require('capital_one');
4 |
5 | var Deposit = {
6 | initWithKey: function(apiKey) {
7 | Config.setApiKey(apiKey);
8 | return this;
9 | },
10 | urlWithEntity: function() {
11 | return Config.baseUrl+'/deposits/';
12 | },
13 | urlWithAccountEntity: function () {
14 | return Config.baseUrl+'/accounts/'
15 | },
16 | url: function() {
17 | return Config.baseUrl;
18 | },
19 | apiKey: function() {
20 | return Config.apiKey;
21 | },
22 | /**
23 | # @Method: getAllByAccountId
24 | # @Brief: Get all deposits for a specific account
25 | # @Parameters: AccountID
26 | # @Returns an array of JSON Objects containing the deposits for that account.
27 | **/
28 | getAllByAccountId: function(accID) {
29 | var account;
30 | var request = $.ajax({
31 | url: this.urlWithAccountEntity()+accID+'/deposits',
32 | data: 'key='+this.apiKey(),
33 | async: false,
34 | dataType: 'json'
35 | });
36 |
37 | request.complete(function(results) {
38 | account = results.responseJSON;
39 | });
40 | return account;
41 | },
42 | /**
43 | # @Method: getDepositById
44 | # @Brief: Returns a deposit for a given Deposit ID
45 | # @Parameters: DepositId
46 | # @Returns a JSON Object with the deposit data
47 | **/
48 | getDepositById: function(id) {
49 | var deposit;
50 | var request = $.ajax({
51 | url: this.urlWithEntity()+id,
52 | data: 'key='+this.apiKey(),
53 | async: false,
54 | dataType: 'json'});
55 |
56 | request.complete(function(results) {
57 | deposit = results.responseJSON;
58 | });
59 | return deposit;
60 | },
61 | /**
62 | # @Method: createDeposit
63 | # @Brief: Creates a new deposit.
64 | # @Parameters: toAccountId, Depositobject
65 | # @Note: Depositobject is formatted as follows:
66 | # {
67 | # "medium": "balance",
68 | # "transaction_date": "string",
69 | # "status": "pending",
70 | # "amount": 0,
71 | # "description": "string"
72 | # }
73 | # @Returns http response code.
74 | **/
75 | createDeposit: function(toAcc, json) {
76 | var respCode;
77 | var request = $.ajax({
78 | url: this.urlWithAccountEntity()+toAcc+'/deposits?key='+this.apiKey(),
79 | data: json,
80 | contentType: 'application/json',
81 | async: false,
82 | type: 'POST'
83 | });
84 | request.complete(function(jqXHR, textStatus) {
85 | respCode = jqXHR.status;
86 | });
87 | return respCode;
88 | },
89 | /**
90 | # @Method: updateDeposit
91 | # @Brief: Updates an existing deposit
92 | # @Parameters: DepositId, Depositobject
93 | # @Object: Depositobject is formatted as follows:
94 | # {
95 | # "medium": "balance",
96 | # "transaction_date": "string",
97 | # "status": "pending",
98 | # "amount": 0,
99 | # "description": "string"
100 | # }
101 | # @Returns http response code
102 | **/
103 | updateDeposit: function(id, json) {
104 | var respCode;
105 | var request = $.ajax({
106 | url: this.urlWithEntity()+id+'/?key='+this.apiKey(),
107 | data: json,
108 | contentType: 'application/json',
109 | async: false,
110 | type: 'PUT'
111 | });
112 | request.complete(function(jqXHR, textStatus) {
113 | respCode = jqXHR.status;
114 | });
115 | return respCode;
116 | },
117 | /**
118 | # @Method: deleteDeposit
119 | # @Brief: Deletes an existing deposit
120 | # @Parameters: DepositId
121 | # @Returns http response code
122 | **/
123 | deleteDeposit: function(id) {
124 | var respCode;
125 | var request = $.ajax({
126 | url: this.urlWithEntity()+id,
127 | data: 'key='+this.apiKey(),
128 | async: false,
129 | dataType: 'json'
130 | });
131 | request.complete(function(jqXHR, textStatus) {
132 | respCode = jqXHR.status;
133 | });
134 | return respCode;
135 | }
136 | };
137 | return Deposit;
138 | });
139 |
--------------------------------------------------------------------------------
/lib/example.html:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
30 |
31 |
32 | Nessie is Real!
33 | Consume the API to learn more about...
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/lib/merchant.js:
--------------------------------------------------------------------------------
1 | define('merchant', function (require) {
2 | "use strict";
3 | var Config = require('capital_one');
4 |
5 | var Merchant = {
6 | initWithKey: function(apiKey) {
7 | Config.setApiKey(apiKey);
8 | return this;
9 | },
10 | urlWithEntity: function() {
11 | return Config.baseUrl+'/merchants/';
12 | },
13 | apiKey: function() {
14 | return Config.apiKey;
15 | },
16 | /**
17 | # @Method: getAll
18 | # @Returns all Merchants as an array of JSON Objects
19 | **/
20 | getAll: function() {
21 | var merchants;
22 | var request = $.ajax({
23 | url: this.urlWithEntity(),
24 | data: 'key='+this.apiKey(),
25 | async: false,
26 | dataType: 'json'
27 | });
28 |
29 | request.complete(function(results) {
30 | merchants = results.responseJSON;
31 | });
32 | return merchants;
33 | },
34 | /**
35 | # @Method: getMerchant
36 | # @Returns a single merchant for a given ID
37 | # @Parameters: MerchantId
38 | # @Returns a JSON Object
39 | **/
40 | getMerchant: function(id) {
41 | var merchant;
42 | var request = $.ajax({
43 | url: this.urlWithEntity()+id,
44 | data: 'key='+this.apiKey(),
45 | async: false,
46 | dataType: 'json'
47 | });
48 |
49 | request.complete(function(results) {
50 | merchant = results.responseJSON;
51 | });
52 | return merchant;
53 | },
54 | /**
55 | # @Method: createMerchant
56 | # @Brief: Creates a new Merchant
57 | # @Parameters: Merchantobject
58 | # @Note: Merchantobject format is as follows:
59 | # {
60 | # "name": "string",
61 | # "address": {
62 | # "street_number": "string",
63 | # "street_name": "string",
64 | # "city": "string",
65 | # "state": "string",
66 | # "zip": "string",
67 | # },
68 | # "geocode": {
69 | # "lat": 0,
70 | # "lng": 0,
71 | # }
72 | # }
73 | # @Returns http response code
74 | **/
75 | createMerchant: function(merchant) {
76 | var respCode;
77 | var request = $.ajax({
78 | url: this.urlWithEntity()+'?key='+this.apiKey(),
79 | data: merchant,
80 | contentType: 'application/json',
81 | async: false,
82 | type: 'POST'
83 | });
84 | request.complete(function(jqXHR, textStatus) {
85 | respCode = jqXHR.status;
86 | });
87 | return respCode;
88 | },
89 | /**
90 | # @Method: updateMerchant
91 | # @Brief: Updates an existing Merchant
92 | # @Parameters: MerchantId, Merchantobject
93 | # @Note: Merchantobject format is as follows:
94 | # {
95 | # "name": "string",
96 | # "address": {
97 | # "street_number": "string",
98 | # "street_name": "string",
99 | # "city": "string",
100 | # "state": "string",
101 | # "zip": "string",
102 | # },
103 | # "geocode": {
104 | # "lat": 0,
105 | # "lng": 0,
106 | # }
107 | # }
108 | # @Returns http response code
109 | **/
110 | updateMerchant: function(id, json) {
111 | var respCode;
112 | var request = $.ajax({
113 | url: this.urlWithEntity()+id+'?key='+this.apiKey(),
114 | data: json,
115 | contentType: 'application/json',
116 | async: false,
117 | type: 'PUT'
118 | });
119 | request.complete(function(jqXHR, textStatus) {
120 | respCode = jqXHR.status;
121 | });
122 | return respCode;
123 | }
124 | };
125 | return Merchant;
126 | });
127 |
--------------------------------------------------------------------------------
/lib/purchase.js:
--------------------------------------------------------------------------------
1 | define('purchase', function (require) {
2 | "use strict";
3 | var Config = require('capital_one');
4 |
5 | var Purchase = {
6 | initWithKey: function(apiKey) {
7 | Config.setApiKey(apiKey);
8 | return this;
9 | },
10 | urlWithEntity: function() {
11 | return Config.baseUrl+'/purchases/';
12 | },
13 | urlWithAccountEntity: function() {
14 | return Config.baseUrl+'/accounts/';
15 | },
16 | urlWithMerchantEntity: function() {
17 | return Config.baseUrl+'/merchants/';
18 | },
19 | apiKey: function() {
20 | return Config.apiKey;
21 | },
22 | /**
23 | # @Method: getAll
24 | # @Parameters: Account Id
25 | # @Returns all Purchases as an array of JSON Objects
26 | **/
27 | getAll: function(id) {
28 | var purchases;
29 | var request = $.ajax({
30 | url: this.urlWithAccountEntity()+id+'/purchases',
31 | data: 'key='+this.apiKey(),
32 | async: false,
33 | dataType: 'json'
34 | });
35 | request.complete(function(results) {
36 | purchases = results.responseJSON;
37 | });
38 | return purchases;
39 | },
40 | /**
41 | # @Method: getAllByAcctAndMerchant
42 | # @Parameters: Account Id, Merchant Id
43 | # @Returns all Purchases as an array of JSON Objects
44 | **/
45 | getAllByAcctAndMerchant: function(accID, merchantID) {
46 | var purchases;
47 | var request = $.ajax({
48 | url: this.urlWithMerchantEntity()+merchantID+'/accounts/'+accID+'/purchases',
49 | data: 'key='+this.apiKey(),
50 | async: false,
51 | dataType: 'json'
52 | });
53 | request.complete(function(results) {
54 | purchases = results.responseJSON;
55 | });
56 | return purchases;
57 | },
58 | /**
59 | # @Method: getAllByMerchant
60 | # @Parameters: Merchant Id
61 | # @Returns all Purchases as an array of JSON Objects
62 | **/
63 | getAllByMerchant: function(merchantID) {
64 | var purchases;
65 | var request = $.ajax({
66 | url: this.urlWithMerchantEntity()+merchantID+'/purchases',
67 | data: 'key='+this.apiKey(),
68 | async: false,
69 | dataType: 'json'
70 | });
71 | request.complete(function(results) {
72 | purchases = results.responseJSON;
73 | });
74 | return purchases;
75 | },
76 | /**
77 | # @Method: getPurchase
78 | # @Brief: Returns a purchase for a given ID
79 | # @Parameters: PurchaseId
80 | # @Returns a JSON Object
81 | **/
82 | getPurchase: function(id) {
83 | var purchase;
84 | var request = $.ajax({
85 | url: this.urlWithEntity()+id,
86 | data: 'key='+this.apiKey(),
87 | async: false,
88 | dataType: 'json'
89 | });
90 | request.complete(function(results) {
91 | purchase = results.responseJSON;
92 | });
93 | return purchase;
94 | },
95 | /**
96 | # @Method: createPurchase
97 | # @Brief: Creates a new purchase for a given account
98 | # @Parameters: AccountId, Purchaseobject
99 | # @Note: Purchaseobject is formatted as follows:
100 | # {
101 | # "merchant_id": "string",
102 | # "medium": "balance",
103 | # "purchase_date": "string",
104 | # "amount": 0,
105 | # "status": "pending",
106 | # "description": "string"
107 | # }
108 | # @Returns http response code
109 | **/
110 | createPurchase: function(accID, json) {
111 | var respCode;
112 | var request = $.ajax({
113 | url: this.urlWithAccountEntity()+accID+'/purchases?key='+this.apiKey(),
114 | data: json,
115 | contentType: 'application/json',
116 | async: false,
117 | type: 'POST'
118 | });
119 | request.complete(function(jqXHR, textStatus) {
120 | respCode = jqXHR.status;
121 | });
122 | return respCode;
123 | },
124 | /**
125 | # @Method: updatePurchase
126 | # @Brief: Updates an existing purchase
127 | # @Parameters: PurchaseId, Purchaseobject
128 | # @Note: Purchaseobject is formatted as follows:
129 | # {
130 | # "merchant_id": "string",
131 | # "medium": "balance",
132 | # "purchase_date": "string",
133 | # "amount": 0,
134 | # "status": "pending",
135 | # "description": "string"
136 | # }
137 | # @Returns http response code
138 | **/
139 | updatePurchase: function(id, json) {
140 | var respCode;
141 | var request = $.ajax({
142 | url: this.urlWithEntity()+id+'?key='+this.apiKey(),
143 | data: json,
144 | contentType: 'application/json',
145 | async: false,
146 | type: 'PUT'
147 | });
148 | request.complete(function(jqXHR, textStatus) {
149 | respCode = jqXHR.status;
150 | });
151 | return respCode;
152 | },
153 | /**
154 | # @Method: deletePurchase
155 | # @Brief: Deletes a purchase for a given ID
156 | # @Parameters: PurchaseId
157 | # @Returns http response code
158 | **/
159 | deletePurchase: function(id) {
160 | var respCode;
161 | var request = $.ajax({
162 | url: this.urlWithEntity()+id,
163 | data: 'key='+this.apiKey(),
164 | async: false,
165 | dataType: 'json'
166 | });
167 | request.complete(function(jqXHR, textStatus) {
168 | respCode = jqXHR.status;
169 | });
170 | return respCode;
171 | }
172 | };
173 | return Purchase;
174 | });
--------------------------------------------------------------------------------
/lib/tests/accountTests.js:
--------------------------------------------------------------------------------
1 |
7 |
8 | require(['account'], function (account) {
9 |
10 | module('Account API - Module');
11 | test('tests', function() {
12 | var accounts = account.initWithKey(apikey);
13 | var customerId = getFirstCustomerId(accounts);
14 | var accountId = getFirstAccountId(accounts);
15 | var deleteAccountId = getLastAccountId(accounts);
16 | var newAcctDetails = "{ \"type\": \"Checking\", \"nickname\": \"Retail Checking Account\", \"rewards\": 0, \"balance\": 2500 }";
17 | var accountInfo = "{\"nickname\":\"Mr. Stanislaus's Account\"}";
18 |
19 | ok(testGetAccounts(accounts, customerId), 'Test Get all accounts');
20 | ok(testGetAccountById(accounts, accountId, customerId), 'Test Get account by id');
21 | ok(testGetAccountsByCustomerId(accounts, customerId, accountId), 'Test Get accounts by customer id');
22 | ok(testCreateAccount(accounts, customerId, newAcctDetails), 'Test Create an account');
23 | ok(testUpdateAccount(accounts, accountId, accountInfo), 'Test Update a specific existing account');
24 | ok(testDeleteAccount(accounts, deleteAccountId), 'Delete a specific existing account');
25 | });
26 | });
27 |
28 | function testGetAccounts(accounts, customerId) {
29 | var res = accounts.getAllAccounts();
30 | return equals(res[0].customer_id, customerId);
31 | }
32 |
33 | function testGetAccountById(accounts, accountId, customerId) {
34 | var res = accounts.getAccountById(accountId);
35 | return equals(res.customer_id, customerId);
36 | }
37 |
38 | function testGetAccountsByCustomerId(accounts, customerId, accountId) {
39 | var res = accounts.getAllByCustomerId(customerId)[0];
40 | return equals(res._id, accountId);
41 | }
42 |
43 | function testCreateAccount(accounts, customerId, newAcctDetails) {
44 | var respCode = accounts.createAccount(customerId, newAcctDetails);
45 | return respCode == 201;
46 | }
47 |
48 | function testUpdateAccount(accounts, accountId, accountInfo) {
49 | var respCode = accounts.updateAccount(accountId, accountInfo);
50 | return respCode == 202;
51 | }
52 |
53 | function testDeleteAccount(accounts, deleteAccountId) {
54 | var respCode = accounts.deleteAccount(deleteAccountId);
55 | return respCode == 204;
56 | }
57 |
58 | function getFirstAccountId(accounts) {
59 | return accounts.getAllAccounts()[0]._id;
60 | }
61 |
62 | function getFirstCustomerId(accounts) {
63 | return accounts.getAllAccounts()[0].customer_id;
64 | }
65 |
66 | function getLastAccountId(accounts) {
67 | return accounts.getAllAccounts().pop()._id;
68 | }
69 |
70 | function equals(val1, val2) {
71 | return val1 === val2;
72 | }
--------------------------------------------------------------------------------
/lib/tests/atmTests.js:
--------------------------------------------------------------------------------
1 |
7 |
8 | require(['atm'], function (atm) {
9 |
10 | module('ATM API - Module');
11 | test('tests', function() {
12 | var atms = atm.initWithKey(apikey);
13 | var atmID = getFirstATMId(atms);
14 |
15 | ok(testGetAllATM(atm), 'Test Get all accounts');
16 | ok(testGetATMById(atm, atmID), 'Test Get ATM by id');
17 | });
18 | });
19 |
20 | function testGetAllATM(atms) {
21 | var res = atms.getAll().data;
22 | return res.length > 0;
23 | }
24 |
25 | function testGetATMById(atms, atmID) {
26 | var res = atms.getATM(atmID)._id;
27 | return equals(res, atmID);
28 | }
29 |
30 | function getFirstATMId(atms) {
31 | return atms.getAll().data[0]._id;
32 | }
33 |
34 | function equals(val1, val2) {
35 | return val1 === val2;
36 | }
--------------------------------------------------------------------------------
/lib/tests/billTests.js:
--------------------------------------------------------------------------------
1 |
7 |
8 | require(['bills', 'account', 'customer'], function (bills, account, customer) {
9 |
10 | module('Bill API - Module');
11 | test('tests', function() {
12 | var bill = bills.initWithKey(apikey);
13 | var accounts = account.initWithKey(apikey);
14 | var customers = customer.initWithKey(apikey);
15 | var accountID = getFirstAccountId(accounts);
16 |
17 | var customerId = getFirstCustomerId(customers);
18 |
19 | var sampleBill = "{\"status\": \"pending\",\"payee\": \"Verizon\",\"nickname\": \"Cable/Internet\",\"payment_date\": \"2015-09-18\", \"recurring_date\": 15, \"payment_amount\": 50 }";
20 | var sampleBillUpdate = "{\"status\": \"cancelled\",\"payee\": \"Verizon\",\"nickname\": \"Cable/Internet\",\"payment_date\": \"2015-09-18\", \"recurring_date\": 1, \"payment_amount\": 30 }";
21 |
22 |
23 | ok(testCreateBill(bill, accountID, sampleBill), 'Test Create a bill');
24 |
25 | var billId = getFirstBillId(bill, accountID);
26 | ok(testGetAllBillsByAcctId(bill, accountID), 'Test Get all bills for a specific account');
27 | ok(testGetBillById(bill, billId), 'Test Get bill by id');
28 | ok(testGetBillsByCustId(bill, customerId), 'Test Get bills by customer id');
29 |
30 | ok(testUpdateBill(bill, billId, sampleBillUpdate), 'Test Update a specific existing bill');
31 |
32 | var lastBillId = getLastBillId(bill, accountID);
33 | ok(testDeleteBill(bill, lastBillId), 'Test Delete a specific existing bill');
34 | });
35 | });
36 |
37 |
38 | function testGetAllBillsByAcctId(bill, accountID) {
39 | var res = bill.getAllByAccountId(accountID);
40 | if (res.length > 0) {
41 | return equals(res[0].account_id, accountID);
42 | } else {
43 | return false;
44 | }
45 | }
46 |
47 | function testGetBillById(bill, billId) {
48 | var res = bill.getBill(billId)._id;
49 | return equals(res, billId);
50 | }
51 |
52 | function testGetBillsByCustId(bill, customerId) {
53 | var res = bill.getAllByCustomerId(customerId)[0].nickname;
54 | return !equals(res, "");
55 | }
56 |
57 | function testCreateBill(bill, accountID, sampleBill) {
58 | var respCode = bill.createBill(accountID, sampleBill);
59 | return equals(respCode, 201);
60 | }
61 |
62 | function testUpdateBill(bill, billId, sampleBillUpdate) {
63 | var respCode = bill.updateBill(billId, sampleBillUpdate);
64 | return equals(respCode, 202);
65 | }
66 |
67 | function testDeleteBill(bill, billId) {
68 | var respCode = bill.deleteBill(billId);
69 | return equals(respCode, 204);
70 | }
71 |
72 | function getFirstBillId(bill, accountID) {
73 | return bill.getAllByAccountId(accountID)[0]._id;
74 | }
75 |
76 | function getFirstAccountId(accounts) {
77 | return accounts.getAllAccounts()[0]._id;
78 | }
79 |
80 | function getFirstCustomerId(customers) {
81 | return customers.getCustomers()[0]._id;
82 | }
83 |
84 | function getLastBillId(bill, accountID) {
85 | return bill.getAllByAccountId(accountID).pop()._id;
86 | }
87 |
88 | function equals(val1, val2) {
89 | return val1 === val2;
90 | }
--------------------------------------------------------------------------------
/lib/tests/branchTests.js:
--------------------------------------------------------------------------------
1 |
7 |
8 | require(['branch'], function (branch) {
9 |
10 | module('Branch API - Module');
11 | test('tests', function() {
12 | var branches = branch.initWithKey(apikey);
13 | var branchId = getFirstBranchId(branches);
14 |
15 | ok(testGetAllBranches(branches), 'Test Get all branches');
16 | ok(testGetBranchById(branches, branchId), 'Test Get branch by id');
17 | });
18 | });
19 |
20 |
21 | function testGetAllBranches(branches) {
22 | var res = branches.getAll();
23 | if (res.length > 0) {
24 | return !equals(res[0].name, "");
25 | }
26 | return false;
27 | }
28 |
29 | function testGetBranchById(branches, branchId) {
30 | var res = branches.getBranch(branchId)._id;
31 | return equals(res, branchId);
32 | }
33 |
34 | function getFirstBranchId(branches) {
35 | return branches.getAll()[0]._id;
36 | }
37 |
38 | function equals(val1, val2) {
39 | return val1 === val2;
40 | }
--------------------------------------------------------------------------------
/lib/tests/customerTests.js:
--------------------------------------------------------------------------------
1 |
7 |
8 | require(['customer'], function (customer) {
9 |
10 | module('Customer API - Module');
11 | test('tests', function() {
12 | var customers = customer.initWithKey(apikey);
13 | var customerId = getFirstCustomerId(customers);
14 | var accountId = '569ff9543921211200ef22a7';
15 | var newCustDetails ="{ \"first_name\": \"Missy\", \"last_name\": \"Elliot\", \"address\": { \"street_number\": \"1\", \"street_name\": \"Capital One Dr.\", \"city\": \"McLean\", \"state\": \"VA\", \"zip\": \"22102\" } }"
16 | var customerInfo = "{\"address\": {\"street_number\": \"8020\",\"street_name\": \"Greenroad Dr\",\"city\": \"McLean\",\"state\": \"VA\",\"zip\": \"22102\"}}";
17 |
18 | ok(testCreateCustomer(customers, newCustDetails), 'Test Create a customer');
19 | ok(testGetCustomers(customers), 'Test Get all customers');
20 | ok(testCustomerById(customers, customerId), 'Test Get customer by id');
21 | ok(testCustomerByAcctId(customers, accountId, customerId), 'Test Get customer that owns the specified account');
22 | ok(testUpdateCustomer(customers, customerId, customerInfo), 'Test Update a specific existing customer');
23 | });
24 | });
25 |
26 | function testCreateCustomer(customers, newCustDetails) {
27 | var respCode = customers.createCustomer(newCustDetails);
28 | return respCode == 201;
29 | }
30 |
31 | function testGetCustomers(customers) {
32 | var res = customers.getCustomers();
33 | return equals(res[0].first_name, 'John');
34 | }
35 |
36 | function testCustomerById(customers, customerId) {
37 | var cFirstName = customers.getCustomerById(customerId).first_name;
38 | return equals(cFirstName, 'John');
39 | }
40 |
41 | function testUpdateCustomer(customers, customerId, customerInfo) {
42 | var respCode = customers.updateCustomer(customerId, customerInfo);
43 | return equals(respCode, 202);
44 | }
45 |
46 | function testCustomerByAcctId(customers, accountId, customerId) {
47 | var cID = customers.getCustomerByAcountId(accountId)._id;
48 | return equals(cID, customerId);
49 | }
50 |
51 | function getFirstCustomerId(customers) {
52 | return customers.getCustomers()[0]._id;
53 | }
54 |
55 | function equals(val1, val2) {
56 | return val1 === val2;
57 | }
--------------------------------------------------------------------------------
/lib/tests/depositTests.js:
--------------------------------------------------------------------------------
1 |
7 |
8 | require(['deposit', 'account'], function (deposit, account) {
9 |
10 | module('Deposit API - Module');
11 | test('tests', function() {
12 | var deposits = deposit.initWithKey(apikey);
13 | var accounts = account.initWithKey(apikey);
14 | var accountID = getFirstAccountId(accounts);
15 |
16 | var sampleDeposit = "{\"medium\": \"balance\",\"amount\": 100000,\"description\": \"test\"}";
17 | var sampleDepositUpdate = "{\"medium\": \"balance\",\"amount\": 205000,\"description\": \"test\"}";
18 |
19 | ok(testCreateDeposit(deposits, accountID, sampleDeposit), 'Test Create a deposit');
20 |
21 | var depositID = getFirstDepositId(deposits, accountID);
22 | var lastDepositId = getLastDepositId(deposit, accountID);
23 | ok(testGetAllDepositsByAcctId(deposits, accountID), 'Test Get all deposits');
24 | ok(testGetDepositById(deposits, depositID), 'Test Get deposit by id');
25 |
26 | ok(testUpdateDeposit(deposits, depositID, sampleDepositUpdate), 'Test Update a specific existing deposit');
27 | ok(testDeleteDeposit(deposits, depositID), 'Test Delete a specific existing deposit');
28 | });
29 | });
30 |
31 |
32 | function testGetAllDepositsByAcctId(deposits, accountID) {
33 | var res = deposits.getAllByAccountId(accountID);
34 | if (res.length > 0) {
35 | return equals(res[0].payee_id, accountID);
36 | } else {
37 | return false;
38 | }
39 | }
40 |
41 | function testGetDepositById(deposits, depositID) {
42 | var res = deposits.getDepositById(depositID)._id;
43 | return equals(res, depositID);
44 | }
45 |
46 | function testCreateDeposit(deposits, accountID, sampleDeposit) {
47 | var respCode = deposits.createDeposit(accountID, sampleDeposit);
48 | return equals(respCode, 201);
49 | }
50 |
51 | function testUpdateDeposit(deposits, depositID, sampleDepositUpdate) {
52 | var respCode = deposits.updateDeposit(depositID, sampleDepositUpdate);
53 | return equals(respCode, 202);
54 | }
55 |
56 | function testDeleteDeposit(deposits, depositID) {
57 | var respCode = deposits.deleteDeposit(depositID);
58 | return equals(respCode, 200);
59 | }
60 |
61 | function getFirstAccountId(accounts) {
62 | return accounts.getAllAccounts()[0]._id;
63 | }
64 |
65 | function getFirstDepositId(deposits, accountID) {
66 | var res = deposits.getAllByAccountId(accountID)[0];
67 | return res._id;
68 | }
69 |
70 | function getLastDepositId(deposits, accountID) {
71 | return deposits.getAllByAccountId(accountID).pop()._id;
72 | }
73 |
74 | function equals(val1, val2) {
75 | return val1 === val2;
76 | }
--------------------------------------------------------------------------------
/lib/tests/merchantTests.js:
--------------------------------------------------------------------------------
1 |
7 |
8 | require(['merchant'], function (merchant) {
9 |
10 | module('Merchant API - Module');
11 | test('tests', function() {
12 | var merchants = merchant.initWithKey(apikey);
13 | var merchantID = getFirstMerchantId(merchants);
14 |
15 | var sampleMerchant = '{ "name": "MVP LLC", "category": ["Residential"], "address": { "street_number": "12095", "street_name": "Oakload Park Ave.", "city": "Arlington", "state": "VA", "zip": "22192" }, "geocode": { "lat": 21, "lng": -10 } }';
16 | var sampleMerchantUpdate = "{ \"name\": \"Best Productions\", \"category\": [\"Entertainment\"], \"address\": { \"street_number\": \"5901\", \"street_name\": \"Lafayette St.\", \"city\": \"Brooklyn\", \"state\": \"NY\", \"zip\": \"07009\" }, \"geocode\": { \"lat\": 33, \"lng\": -1 } }";
17 |
18 | ok(testGetAllMerchants(merchants), 'Test Get all merchants');
19 | ok(testGetMerchantById(merchants, merchantID), 'Test Get merchant by id');
20 | ok(testCreateMerchant(merchants, sampleMerchant), 'Test Create a merchant');
21 | ok(testUpdateMerchant(merchants, merchantID, sampleMerchantUpdate), 'Test Update a specific existing merchant');
22 | });
23 | });
24 |
25 |
26 | function testGetAllMerchants(merchants) {
27 | var res = merchants.getAll().data;
28 | if (res.length > 0) {
29 | return !equals(res[0].name, "");
30 | }
31 | return false;
32 | }
33 |
34 | function testGetMerchantById(merchants, merchantID) {
35 | var res = merchants.getMerchant(merchantID)._id;
36 | return equals(res, merchantID);
37 | }
38 |
39 | function testCreateMerchant(merchants, sampleMerchant) {
40 | var respCode = merchants.createMerchant(sampleMerchant);
41 | return equals(respCode, 201);
42 | }
43 |
44 | function testUpdateMerchant(merchants, merchantID, sampleMerchantUpdate) {
45 | var respCode = merchants.updateMerchant(merchantID, sampleMerchantUpdate);
46 | return equals(respCode, 202);
47 | }
48 |
49 | function getFirstMerchantId(merchants) {
50 | return merchants.getAll().data[0]._id;
51 | }
52 |
53 | function equals(val1, val2) {
54 | return val1 === val2;
55 | }
--------------------------------------------------------------------------------
/lib/tests/purchaseTests.js:
--------------------------------------------------------------------------------
1 |
7 |
8 | require(['purchase', 'account', 'merchant'], function (purchase, account, merchant) {
9 |
10 | module('Purchase API - Module');
11 | test('tests', function() {
12 | var purchases = purchase.initWithKey(apikey);
13 | var accounts = account.initWithKey(apikey);
14 | var merchants = merchant.initWithKey(apikey);
15 |
16 | var accountID = getFirstAccountId(accounts);
17 | var purchaseID = getFirstPurchaseId(purchases, accountID);
18 | var lastPurchaseId = getLastPurchaseId(purchases, accountID);
19 | var merchantID = getFirstMerchantId(purchases, accountID);
20 |
21 | var samplePurchase = '{ "merchant_id": "55e94a6cf8d8770528e6196d", "medium": "balance", "purchase_date": "2015-12-02", "amount": 0, "status": "pending", "description": "string" }';
22 | var samplePurchaseUpdate = '{ "payer_id": "string", "medium": "balance", "amount": 0, "description": "string" }';
23 |
24 | if (merchantID != null) {
25 | ok(testGetPurchasesForParams(purchases, accountID, merchantID), 'Test Get all purchases by account and merchant');
26 | ok(testGetPurchasesByMerchant(purchases, merchantID), 'Test Get all purchases by merchant');
27 | }
28 |
29 | ok(testGetAllPurchases(purchases, accountID), 'Test Get all purchases');
30 |
31 | if (purchaseID != null) {
32 | ok(testGetPurchaseById(purchases, purchaseID), 'Test Get purchase by id');
33 | ok(testUpdatePurchase(purchases, purchaseID, samplePurchaseUpdate), 'Test Update a specific existing purchase');
34 | ok(testDeletePurchase(purchases, purchaseID), 'Test Delete a specific existing purchase');
35 | }
36 |
37 | ok(testCreatePurchase(purchases, accountID, samplePurchase), 'Test Create a purchase');
38 |
39 | });
40 | });
41 |
42 |
43 | function testGetAllPurchases(purchases, accountID) {
44 | var res = purchases.getAll(accountID);
45 | return evaluatePurchases(res);
46 | }
47 |
48 | function testGetPurchasesForParams(purchases, accountID, merchantID) {
49 | var res = purchases.getAllByAcctAndMerchant(accountID, merchantID);
50 | return evaluatePurchases(res);
51 | }
52 |
53 | function testGetPurchasesByMerchant(purchases, merchantID) {
54 | var res = purchases.getAllByMerchant(merchantID);
55 | return evaluatePurchases(res);
56 | }
57 |
58 | function testGetPurchaseById(purchases, purchaseID) {
59 | var res = purchases.getPurchase(purchaseID);
60 | return evaluatePurchases(res);
61 | }
62 |
63 | function testCreatePurchase(purchases, accountID, samplePurchase) {
64 | var respCode = purchases.createPurchase(accountID, samplePurchase);
65 | return equals(respCode, 201);
66 | }
67 |
68 | function testUpdatePurchase(purchases, purchaseID, samplePurchaseUpdate) {
69 | var respCode = purchases.updatePurchase(purchaseID, samplePurchaseUpdate);
70 | return equals(respCode, 202);
71 | }
72 |
73 | function testDeletePurchase(purchases, purchaseID) {
74 | var respCode = purchases.deletePurchase(purchaseID);
75 | return equals(respCode, 200);
76 | }
77 |
78 | function evaluatePurchases(res) {
79 | if (res.length > 0) {
80 | return !equals(res[0]._id, "");
81 | } else {
82 | return res.length == 0;
83 | }
84 | }
85 |
86 | function getFirstAccountId(accounts) {
87 | return accounts.getAllAccounts()[0]._id;
88 | }
89 |
90 | function getFirstPurchaseId(purchases, accountID) {
91 | var res = purchases.getAll(accountID);
92 | if (res.length > 0) {
93 | return res._id;
94 | }
95 | return null;
96 | }
97 |
98 | function getLastPurchaseId(purchases, accountID){
99 | var res = purchases.getAll(accountID);
100 | if (res.length > 0) {
101 | return res.pop()._id;
102 | }
103 | return null;
104 | }
105 |
106 | function getFirstMerchantId(purchases, accountID) {
107 | var res = purchases.getAll(accountID);
108 | if (res.length > 0) {
109 | return res.merchant_id;
110 | }
111 | return null;
112 | }
113 |
114 | function equals(val1, val2) {
115 | return val1 === val2;
116 | }
--------------------------------------------------------------------------------
/lib/tests/transferTests.js:
--------------------------------------------------------------------------------
1 |
7 |
8 | require(['transfer', 'account'], function (transfer, account) {
9 |
10 | module('Transfer API - Module');
11 | test('tests', function() {
12 | var transfers = transfer.initWithKey(apikey);
13 | var accounts = account.initWithKey(apikey);
14 | var paymentType = ["payer", "payee"];
15 |
16 | var accountID = getFirstAccountId(accounts);
17 | ok(testGetAllTransfers(transfers, accountID), 'Test Get all transfers');
18 | var sampleTransfer = "{ \"medium\": \"balance\", \"payee_id\": \""+accountID+"\", \"amount\": 4525, \"transaction_date\": \"2016-01-22\", \"status\": \"pending\", \"description\": \"Transfer - Savings\" }";
19 |
20 | var transferID = getFirstTransferId(transfers, accountID, paymentType[0]);
21 | ok(testTransferById(transfers, transferID), 'Test Get transfer by id');
22 | ok(testCreateTransfer(transfers, accountID, sampleTransfer), 'Test Create a transfer');
23 |
24 | var lastAccountID = getLastAccountId(accounts);
25 | var sampleTransferUpdate = "{ \"medium\": \"balance\", \"payee_id\": \""+lastAccountID+"\", \"amount\": 100, \"description\": \"string\" }";
26 | ok(testUpdateTransfer(transfers, transferID, sampleTransferUpdate), 'Test Update a specific existing transfer');
27 | var lastTransferID = getLastTransferId(transfers, accountID, paymentType[0]);
28 | ok(testDeleteTransfer(transfers, transferID), 'Test Delete a specific existing transfer');
29 |
30 | });
31 | });
32 |
33 | function testGetAllTransfers(transfers, accountID, type) {
34 | var res = transfers.getAll(accountID, type);
35 | if (res.length > 0) {
36 | return equals(res[0].payer_id, accountID);
37 | }
38 | return false;
39 | }
40 |
41 | function testTransferById(transfers, transferID) {
42 | var res = transfers.getTransferById(transferID);
43 | return equals(res._id, transferID);
44 | }
45 |
46 | function testCreateTransfer(transfers, accountID, sampleTransfer) {
47 | var respCode = transfers.createTransfer(accountID, sampleTransfer);
48 | return equals(respCode, 201);
49 | }
50 |
51 | function testUpdateTransfer(transfers, transferID, sampleTransferUpdate) {
52 | var respCode = transfers.updateTransfer(transferID, sampleTransferUpdate);
53 | return equals(respCode, 202);
54 | }
55 |
56 | function testDeleteTransfer(transfers, transferID) {
57 | var respCode = transfers.deleteTransfer(transferID);
58 | return equals(respCode, 204);
59 | }
60 |
61 | function getFirstTransferId(transfers, accountID, type) {
62 | return transfers.getAll(accountID, type)[0]._id;
63 | }
64 |
65 | function getLastTransferId(transfers, accountID, type) {
66 | return transfers.getAll(accountID, type).pop()._id;
67 | }
68 |
69 | function getFirstAccountId(accounts) {
70 | return accounts.getAllAccounts()[0]._id;
71 | }
72 |
73 | function getLastAccountId(accounts) {
74 | return accounts.getAllAccounts().pop()._id;
75 | }
76 |
77 | function equals(val1, val2) {
78 | return val1 === val2;
79 | }
--------------------------------------------------------------------------------
/lib/tests/withdrawalTests.js:
--------------------------------------------------------------------------------
1 |
7 |
8 | require(['withdrawal', 'account'], function (withdrawal, account) {
9 |
10 | module('Withdrawal API - Module');
11 | test('tests', function() {
12 | var withdrawals = withdrawal.initWithKey(apikey);
13 | var accounts = account.initWithKey(apikey);
14 |
15 | var accountID = getFirstAccountId(accounts);
16 | var withdrawalID = getFirstWithdrawalId(withdrawals, accountID);
17 | var lastWithdrawID = getLastWithdrawalId(withdrawals, accountID);
18 |
19 | var sampleWithdrawal = "{ \"medium\": \"balance\", \"transaction_date\": \"2016-01-22\", \"status\": \"completed\", \"amount\": 25, \"description\": \"Teller withdrawal\" }";
20 | var sampleWithdrawUpdate = '{ "medium": "balance", "amount": 52000, "description": "update" }';
21 |
22 | ok(testGetAllByAcctId(withdrawals, accountID), 'Test Get all withdrawals');
23 | ok(testGetWithdrawalById(withdrawals, withdrawalID), 'Test Get withdrawal by id');
24 | ok(testCreateWithdrawal(withdrawals, accountID, sampleWithdrawal), 'Test Create a withdrawal');
25 | ok(testUpdateWithdrawal(withdrawals, withdrawalID, sampleWithdrawUpdate), 'Test Update a specific existing withdrawal');
26 | ok(testDeleteWithdrawal(withdrawals, lastWithdrawID), 'Test Delete a specific existing withdrawal');
27 |
28 | });
29 | });
30 |
31 | function testGetAllByAcctId(withdrawals, accountID) {
32 | var res = withdrawals.getAllByAccountId(accountID);
33 | if (res.length > 0) {
34 | return equals(res[0].payer_id, accountID);
35 | }
36 | return false;
37 | }
38 |
39 | function testGetWithdrawalById(withdrawals, withdrawalID) {
40 | var res = withdrawals.getWithdrawalById(withdrawalID);
41 | return equals(res._id, withdrawalID);
42 | }
43 |
44 | function testCreateWithdrawal(withdrawals, accountID, sampleWithdrawal) {
45 | var respCode = withdrawals.createWithdrawal(accountID, sampleWithdrawal);
46 | return equals(respCode, 201);
47 | }
48 |
49 | function testUpdateWithdrawal(withdrawals, withdrawalID, sampleWithdrawUpdate) {
50 | var respCode = withdrawals.updateWithdrawalById(withdrawalID, sampleWithdrawUpdate);
51 | return equals(respCode, 202);
52 | }
53 |
54 | function testDeleteWithdrawal(withdrawals, withdrawalID) {
55 | var respCode = withdrawals.deleteWithdrawals(withdrawalID);
56 | return equals(respCode, 204);
57 | }
58 |
59 | function getFirstWithdrawalId(withdrawals, accountID) {
60 | return withdrawals.getAllByAccountId(accountID)[0]._id;
61 | }
62 |
63 | function getLastWithdrawalId(withdrawals, accountID) {
64 | return withdrawals.getAllByAccountId(accountID).pop()._id;
65 | }
66 |
67 | function getFirstAccountId(accounts) {
68 | return accounts.getAllAccounts()[0]._id;
69 | }
70 |
71 | function equals(val1, val2) {
72 | return val1 === val2;
73 | }
--------------------------------------------------------------------------------
/lib/transfer.js:
--------------------------------------------------------------------------------
1 | define('transfer', function (require) {
2 | "use strict";
3 | var Config = require('capital_one');
4 |
5 | var Transfer = {
6 | initWithKey: function(apiKey) {
7 | Config.setApiKey(apiKey);
8 | return this;
9 | },
10 | urlWithEntity: function() {
11 | return Config.baseUrl+'/transfers/';
12 | },
13 | urlWithAccountEntity: function() {
14 | return Config.baseUrl+'/accounts/'
15 | },
16 | apiKey: function() {
17 | return Config.apiKey;
18 | },
19 | /**
20 | # @Method: getAll
21 | # @Brief: Get all transfers for a specific account
22 | # @Parameters: AccountID, Type [Optional] (ex. payer or payee)
23 | # @Returns an array of JSON Objects containing the transfers for that account.
24 | **/
25 | getAll: function(accID, type) {
26 | var transfers;
27 | var requestUrl;
28 | if (typeof type === "undefined" || type === null) {
29 | requestUrl = 'key='+this.apiKey();
30 | } else {
31 | requestUrl = 'type='+type+'&key='+this.apiKey();
32 | }
33 | var request = $.ajax({
34 | url: this.urlWithAccountEntity()+accID+'/transfers',
35 | data: requestUrl,
36 | async: false,
37 | dataType: 'json'
38 | });
39 |
40 | request.complete(function(results) {
41 | transfers = results.responseJSON;
42 | });
43 | return transfers;
44 | },
45 | /**
46 | # @Method: getTransferById
47 | # @Brief: Get a single transfer for a given ID
48 | # @Parameters: TransferId
49 | # @Returns a JSON Object
50 | **/
51 | getTransferById: function(id) {
52 | var transfer;
53 | var request = $.ajax({
54 | url: this.urlWithEntity()+id,
55 | data: 'key='+this.apiKey(),
56 | async: false,
57 | dataType: 'json'});
58 |
59 | request.complete(function(results) {
60 | transfer = results.responseJSON;
61 | });
62 | return transfer;
63 | },
64 | /**
65 | # @Method: createTransfer
66 | # @Brief: Creates a new transfer
67 | # @Parameters: toAccountId, TransferObject
68 | # TransferObject formatted as follows:
69 | # {
70 | # "medium": "balance",
71 | # "payee_id": "string",
72 | # "amount": 0,
73 | # "transaction_date": "string",
74 | # "status": "string",
75 | # "desciption": "string"
76 | # }
77 | # @Returns http response code
78 | **/
79 | createTransfer: function(toAcc, json) {
80 | var respCode;
81 | var request = $.ajax({
82 | url: this.urlWithAccountEntity()+toAcc+'/withdrawals?key='+this.apiKey(),
83 | data: json,
84 | contentType: 'application/json',
85 | async: false,
86 | type: 'POST'
87 | });
88 | request.complete(function(jqXHR, textStatus) {
89 | respCode = jqXHR.status;
90 | });
91 | return respCode;
92 | },
93 | /**
94 | # @Method: updateTransfer
95 | # @Brief: Updates an existing transfer
96 | # @Parameters: transferId, TransferObject
97 | # TransferObject formatted as follows:
98 | # {
99 | # "medium": "balance",
100 | # "payee_id": "string",
101 | # "amount": 0,
102 | # "desciption": "string"
103 | # }
104 | # @Returns http response code
105 | **/
106 | updateTransfer: function(id, json){
107 | var respCode;
108 | var request = $.ajax({
109 | url: this.urlWithEntity()+id+'/?key='+this.apiKey(),
110 | data: json,
111 | contentType: 'application/json',
112 | async: false,
113 | type: 'PUT'
114 | });
115 | request.complete(function(jqXHR, textStatus){
116 | respCode = jqXHR.status;
117 | });
118 | return respCode;
119 | },
120 | /**
121 | # @Method: deleteTransfer
122 | # @Brief: Deletes a specified transfer
123 | # @Parameters: transferID
124 | # @Returns http response code.
125 | **/
126 | deleteTransfer: function(id) {
127 | var respCode;
128 | var request = $.ajax({
129 | url: this.urlWithEntity()+id+'?key='+this.apiKey(),
130 | async: false,
131 | type: 'DELETE'
132 | });
133 | request.complete(function(jqXHR, textStatus) {
134 | respCode = jqXHR.status;
135 | });
136 | return respCode;
137 | }
138 | };
139 | return Transfer;
140 | });
141 |
--------------------------------------------------------------------------------
/lib/unit_tests.html:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
10 |
11 | Nessie Javascript SDK Tests
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/lib/withdrawal.js:
--------------------------------------------------------------------------------
1 | define('withdrawal', function (require) {
2 | "use strict";
3 | var Config = require('capital_one');
4 |
5 | var Withdrawal = {
6 | initWithKey: function(apiKey) {
7 | Config.setApiKey(apiKey);
8 | return this;
9 | },
10 | urlWithEntity: function() {
11 | return Config.baseUrl+'/withdrawals/';
12 | },
13 | urlWithAccountEntity: function() {
14 | return Config.baseUrl+'/accounts/'
15 | },
16 | apiKey: function() {
17 | return Config.apiKey;
18 | },
19 | /**
20 | # @Method: getAllByAccountId
21 | # @Brief: Get all withdrawals for a specific account
22 | # @Parameters: AccountID
23 | # @Returns an array of JSON Objects containing the withdrawals for that account.
24 | **/
25 | getAllByAccountId: function(accID) {
26 | var withdrawals;
27 | var request = $.ajax({
28 | url: this.urlWithAccountEntity()+accID+'/withdrawals',
29 | data: 'key='+this.apiKey(),
30 | async: false,
31 | dataType: 'json'
32 | });
33 |
34 | request.complete(function(results) {
35 | withdrawals = results.responseJSON;
36 | });
37 | return withdrawals;
38 | },
39 | /**
40 | # @Method: getWithdrawalById
41 | # @Brief: Get a single withdrawal for a given ID
42 | # @Parameters: WithdrawalId
43 | # @Returns a JSON Object
44 | **/
45 | getWithdrawalById: function(id) {
46 | var withdrawal;
47 | var request = $.ajax({
48 | url: this.urlWithEntity()+id,
49 | data: 'key='+this.apiKey(),
50 | async: false,
51 | dataType: 'json'});
52 |
53 | request.complete(function(results) {
54 | withdrawal = results.responseJSON;
55 | });
56 | return withdrawal;
57 | },
58 | /**
59 | # @Method: createWithdrawal
60 | # @Brief: Creates a new withdrawal
61 | # @Parameters: toAccountId, Withdrawalobject
62 | # Withdrawalobject formatted as follows:
63 | # {
64 | # "medium": "balance",
65 | # "transaction_date": "string",
66 | # "status": "pending",
67 | # "amount": 0,
68 | # "desciption": "string"
69 | # }
70 | # @Returns http response code
71 | **/
72 | createWithdrawal: function(toAcc, json) {
73 | var respCode;
74 | var request = $.ajax({
75 | url: this.urlWithAccountEntity()+toAcc+'/withdrawals?key='+this.apiKey(),
76 | data: json,
77 | contentType: 'application/json',
78 | async: false,
79 | type: 'POST'
80 | });
81 | request.complete(function(jqXHR, textStatus) {
82 | respCode = jqXHR.status;
83 | });
84 | return respCode;
85 | },
86 | /**
87 | # @Method: updateWithdrawal
88 | # @Brief: Updates an existing withdrawal
89 | # @Parameters: WithdrawalId, Withdrawalobject
90 | # Withdrawalobject formatted as follows:
91 | # {
92 | # "medium": "balance",
93 | # "transaction_date": "string",
94 | # "status": "pending",
95 | # "amount": 0,
96 | # "desciption": "string"
97 | # }
98 | # @Returns http response code
99 | **/
100 | updateWithdrawalById: function(id, json){
101 | var respCode;
102 | var request = $.ajax({
103 | url: this.urlWithEntity()+id+'/?key='+this.apiKey(),
104 | data: json,
105 | contentType: 'application/json',
106 | async: false,
107 | type: 'PUT'
108 | });
109 | request.complete(function(jqXHR, textStatus){
110 | respCode = jqXHR.status;
111 | });
112 | return respCode;
113 | },
114 | /**
115 | # @Method: deleteWithdrawal
116 | # @Brief: Deletes a specified withdrawal from a specified account.
117 | # @Parameters: WithdrawalID
118 | # @Returns http response code.
119 | # @Note: This does not actually delete the withdrawal from the database, it only sets its status to 'cancelled'
120 | **/
121 | deleteWithdrawals: function(id) {
122 | var respCode;
123 | var request = $.ajax({
124 | url: this.urlWithEntity()+id,
125 | data: {'key': this.apiKey()},
126 | async: false,
127 | type: 'DELETE'
128 | });
129 | request.complete(function(jqXHR, textStatus) {
130 | respCode = jqXHR.status;
131 | });
132 | return respCode;
133 | }
134 | };
135 | return Withdrawal;
136 | });
137 |
--------------------------------------------------------------------------------