balanced-node-new
Advanced tools
Comparing version 0.4.3 to 0.4.4
@@ -65,14 +65,16 @@ function balanced() { | ||
function createModuleMethod(data, name, json) { | ||
function _makeCall(options, urlOptions, callback) { | ||
function _makeCall(uriOptions, options, callback) { | ||
if(arguments.length === 1) { | ||
callback = options; | ||
options = undefined; | ||
urlOptions = {}; | ||
uriOptions = {}; | ||
} | ||
if(arguments.length === 2) { | ||
callback = urlOptions; | ||
urlOptions = options; | ||
callback = options; | ||
if(typeof uriOptions === 'object') { | ||
options = uriOptions; | ||
} | ||
} | ||
if(!urlOptions) { | ||
urlOptions = {}; | ||
if(!uriOptions) { | ||
uriOptions = {}; | ||
} | ||
@@ -85,18 +87,22 @@ | ||
urlOptions.marketplace_uri = $scope.requestOptions.marketplace_uri; | ||
if(urlOptions) { | ||
var pathPieces = data.path.split('/'); | ||
for(var i = 0; i < pathPieces.length; i++) { | ||
if(pathPieces[i].indexOf(':') >= 0) { | ||
var variablePieces = pathPieces[i].substr(1).split('.'); | ||
var newVar = urlOptions; | ||
if(variablePieces.length === 1 && typeof urlOptions != 'object') { | ||
newVar = urlOptions; | ||
} else { | ||
for(var j = 0; j < variablePieces.length; j++) { | ||
newVar = newVar[variablePieces[j]]; | ||
if(typeof uriOptions === 'string') { | ||
data.path = uriOptions; | ||
} else { | ||
uriOptions.marketplace_uri = $scope.requestOptions.marketplace_uri; | ||
if(uriOptions) { | ||
var pathPieces = data.path.split('/'); | ||
for(var i = 0; i < pathPieces.length; i++) { | ||
if(pathPieces[i].indexOf(':') >= 0) { | ||
var variablePieces = pathPieces[i].substr(1).split('.'); | ||
var newVar = uriOptions; | ||
if(variablePieces.length === 1 && typeof uriOptions != 'object') { | ||
newVar = uriOptions; | ||
} else { | ||
for(var j = 0; j < variablePieces.length; j++) { | ||
newVar = newVar[variablePieces[j]]; | ||
} | ||
} | ||
pathPieces[i] = newVar; | ||
data.path = pathPieces.join('/'); | ||
} | ||
pathPieces[i] = newVar; | ||
data.path = pathPieces.join('/'); | ||
} | ||
@@ -103,0 +109,0 @@ } |
{ | ||
"name": "balanced-node-new", | ||
"description": "Offical Balanced Payments API Client for node.js, https://www.balancedpayments.com/docs/api", | ||
"version": "0.4.3", | ||
"version": "0.4.4", | ||
"author": "Balanced Payments / uh-sem-blee, Co. | typefoo", | ||
@@ -6,0 +6,0 @@ "contributors": [ |
@@ -6,3 +6,3 @@ Balanced Node.js library | ||
The official Node.js library for [Balanced Payments](https://www.balancedpayments.com). Originally written by [Tenor Enterprises](http://tenorent.com/). | ||
The official Node.js library for [Balanced Payments](https://www.balancedpayments.com). Written by [uh-sem-blee, Co.](http://www.uh-sem-blee.com) | ||
@@ -75,3 +75,7 @@ The Balanced Payments API located here: https://www.balancedpayments.com/docs/api. | ||
```js | ||
balanced.customer.add_bank({bank_account_uri: <bank_account_uri>}, {customer_id: newCustomer.customer_uri}, function(err, response){ ... }) | ||
balanced.customer.add_bank(newCustomer.uri, { | ||
bank_account_uri: <bank_account_uri> | ||
}, function(err, response){ ... }) | ||
``` | ||
In this API call we use the customer's URI as the request path and a JSON packet of required data. |
@@ -71,3 +71,3 @@ var https = require('https'), | ||
var data = null; | ||
var urlOptions = null; | ||
var uriOptions = null; | ||
@@ -92,15 +92,6 @@ if(action.data) { | ||
} | ||
if(action.urlOptions) { | ||
urlOptions = action.urlOptions; | ||
var urlKeys = Object.keys(urlOptions); | ||
for(i = 0; i < urlKeys.length; i++) { | ||
var d = urlOptions[urlKeys[i]]; | ||
if(typeof d !== 'string') { | ||
continue; | ||
} | ||
console.log('Trying to replace a url argument'); | ||
console.log(urlKeys); | ||
console.log(d); | ||
if(d.indexOf(':') >= 0 && d.indexOf('://') === -1) { | ||
var variablePieces = d.substr(1).split('.'); | ||
if(action.uriOptions) { | ||
if(typeof action.uriOptions === 'string') { | ||
if(action.uriOptions.indexOf(':') >= 0 && action.uriOptions.indexOf('://') === -1) { | ||
var variablePieces = action.uriOptions.substr(1).split('.'); | ||
var newVar = testObjects; | ||
@@ -110,9 +101,30 @@ for(var j = 0; j < variablePieces.length; j++) { | ||
} | ||
urlOptions[urlKeys[i]] = newVar; | ||
uriOptions = newVar; | ||
console.log('URL Option replaced:' + newVar); | ||
} | ||
} else { | ||
uriOptions = action.uriOptions; | ||
var urlKeys = Object.keys(uriOptions); | ||
for(i = 0; i < urlKeys.length; i++) { | ||
var d = uriOptions[urlKeys[i]]; | ||
if(typeof d !== 'string') { | ||
continue; | ||
} | ||
console.log('Trying to replace a url argument'); | ||
console.log(urlKeys); | ||
console.log(d); | ||
if(d.indexOf(':') >= 0 && d.indexOf('://') === -1) { | ||
var variablePieces = d.substr(1).split('.'); | ||
var newVar = testObjects; | ||
for(var j = 0; j < variablePieces.length; j++) { | ||
newVar = newVar[variablePieces[j]]; | ||
} | ||
uriOptions[urlKeys[i]] = newVar; | ||
console.log('URL Option replaced:' + newVar); | ||
} | ||
} | ||
} | ||
} | ||
balanced[action.module][action.method](data, urlOptions, function(err, res) { | ||
balanced[action.module][action.method](uriOptions, data, function(err, res) { | ||
if(err) { | ||
@@ -119,0 +131,0 @@ var ret = { |
@@ -26,7 +26,5 @@ module.exports = { | ||
method: 'id', | ||
urlOptions: { | ||
bank_account_id: ':bank.create.id' | ||
} | ||
uriOptions: ':bank.create.uri' | ||
} | ||
} | ||
} |
@@ -22,5 +22,3 @@ module.exports = { | ||
method: 'id', | ||
urlOptions: { | ||
card_id: ':cards.create.id' | ||
} | ||
uriOptions: ':cards.create.uri' | ||
}, | ||
@@ -35,7 +33,5 @@ update: { | ||
}, | ||
urlOptions: { | ||
card_id: ':cards.create.id' | ||
} | ||
uriOptions: ':cards.create.uri' | ||
} | ||
} | ||
} |
@@ -14,3 +14,6 @@ module.exports = { | ||
module: 'customer', | ||
method: 'list' | ||
method: 'list', | ||
data: { | ||
name: 'John' | ||
} | ||
}, | ||
@@ -20,5 +23,3 @@ id: { | ||
method: 'id', | ||
urlOptions: { | ||
customer_id: ':customers.create.id' | ||
} | ||
uriOptions: ':customers.create.uri' | ||
}, | ||
@@ -31,5 +32,3 @@ add_card: { | ||
}, | ||
urlOptions: { | ||
customer_id: ':customers.create.id' | ||
} | ||
uriOptions: ':customers.create.uri' | ||
}, | ||
@@ -42,5 +41,3 @@ add_bank: { | ||
}, | ||
urlOptions: { | ||
customer_id: ':customers.create.id' | ||
} | ||
uriOptions: ':customers.create.uri' | ||
}, | ||
@@ -50,5 +47,3 @@ verify_bank: { | ||
method: 'init_bank_account_verification', | ||
urlOptions: { | ||
bank_account_id: ':bank.create.id' | ||
} | ||
uriOptions: ':bank.create.verifications_uri' | ||
}, | ||
@@ -62,8 +57,5 @@ confirm_bank_account: { | ||
}, | ||
urlOptions: { | ||
bank_account_id: ':bank.create.id', | ||
verification_id: ':customers.verify_bank.id' | ||
} | ||
uriOptions: ':customers.verify_bank.uri' | ||
} | ||
} | ||
} |
@@ -11,7 +11,5 @@ module.exports = { | ||
}, | ||
urlOptions: { | ||
bank_account_id: ':bank.create.id' | ||
} | ||
uriOptions: ':bank.create.credits_uri' | ||
} | ||
} | ||
} |
@@ -13,7 +13,5 @@ module.exports = { | ||
}, | ||
urlOptions: { | ||
customer_id: ':customers.create.id' | ||
} | ||
uriOptions: ':customers.create.debits_uri' | ||
} | ||
} | ||
} |
@@ -12,7 +12,5 @@ module.exports = { | ||
}, | ||
urlOptions: { | ||
customer_id: ':customers.create.id' | ||
} | ||
uriOptions: ':customers.create.refunds_uri' | ||
} | ||
} | ||
} |
@@ -18,5 +18,3 @@ module.exports = { | ||
}, | ||
urlOptions: { | ||
account_id: ':accounts.create.id' | ||
} | ||
uriOptions: ':accounts.create.uri' | ||
}, | ||
@@ -29,5 +27,3 @@ add_bank: { | ||
}, | ||
urlOptions: { | ||
account_id: ':accounts.create.id' | ||
} | ||
uriOptions: ':accounts.create.uri' | ||
}, | ||
@@ -34,0 +30,0 @@ add_underwriter: { |
@@ -12,7 +12,5 @@ module.exports = { | ||
method: 'id', | ||
urlOptions: { | ||
event_id: ':events.list.items.0.id' | ||
} | ||
uriOptions: ':events.list.items.0.uri' | ||
} | ||
} | ||
} |
@@ -8,5 +8,3 @@ module.exports = { | ||
method: 'delete', | ||
urlOptions: { | ||
bank_account_id: ':bank.create.id' | ||
} | ||
uriOptions: ':bank.create.uri' | ||
}, | ||
@@ -16,5 +14,3 @@ delete_card: { | ||
method: 'delete', | ||
urlOptions: { | ||
card_id: ':cards.create.id' | ||
} | ||
uriOptions: ':cards.create.uri' | ||
}, | ||
@@ -24,7 +20,5 @@ delete_customer: { | ||
method: 'delete', | ||
urlOptions: { | ||
customer_id: ':customers.create.id' | ||
} | ||
uriOptions: ':customers.create.uri' | ||
} | ||
} | ||
} |
38925
79
1449