Skip to content

Commit

Permalink
Fixed optional masspay params. Whitespace. Added masspay to README.
Browse files Browse the repository at this point in the history
  • Loading branch information
nanek committed Jul 14, 2014
1 parent df8eed3 commit 5ef97cf
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 106 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,22 @@ reused.
* pending(oauth_token, callback)
* withdraw(oauth_token, pin, sourceId, amount, fn)

[MassPay](https://developers.dwolla.com/dev/docs/masspay)
* createMassPayJob(oauth_token, fundsSource, pin, items[, params], fn)
* getMassPayJob(oauth_token, job_id, fn)
* getMassPayJobItems(oauth_token, job_id[, params], fn)

All optional parameters are passed in as an optional object before the callback.

## Sandbox Support

If you desire to test your application with Dwolla's UAT sandbox, you can
If you desire to test your application with Dwolla's UAT sandbox, you can
dynamically toggle between sandbox and production mode by toggling the sandbox flag.

dwolla = require('dwolla');
dwolla.sandbox = true;

The sandbox environment is disabled by default.
The sandbox environment is disabled by default.

### How to obtain a Dwolla OAuth2 token

Expand Down
6 changes: 3 additions & 3 deletions examples/fundingSources.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ dwolla.fundingSources(c.token, function(err, data) {
console.log(data);
});

// Example 2: Get information for funding source with ID '999999' for
// Example 2: Get information for funding source with ID '999999' for
// current user's OAuth token

dwolla.fundingSourceById(c.token, '999999', function(err, data) {
Expand All @@ -24,9 +24,9 @@ dwolla.addFundingSource(c.token, '99999999', '99999999', 'Checking', 'My bank',
console.log(data);
});

// Example 4: Verify a funding source added with ID '999999' and
// Example 4: Verify a funding source added with ID '999999' and
// mini-deposit amounts of $0.02 and $0.07.
dwolla.verifyFundingSource(c.token, 0.02, 0.07, '999999', function(err, data) {
if (err) { console.log(err); }
console.log(data);
});
});
8 changes: 4 additions & 4 deletions examples/masspay.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ items.push(transaction1);

var fS = "Balance";

// Optional parameters can be passed in place of null
// NOTE: Optional parameters can also be passed in.
// View MassPay documentation here: https://developers.dwolla.com/dev/docs/masspay

// Create MassPay job (masspay/create)
dwolla.createMassPayJob(c.token, fS, c.pin, items, null, function(err, data) {
dwolla.createMassPayJob(c.token, fS, c.pin, items, function(err, data) {
if (err) { console.log(err); }
console.log(data);
});
Expand All @@ -27,7 +27,7 @@ dwolla.getMassPayJob(c.token, jobId, function(err, data) {
});

// Get all transactions from MassPay Job (masspay/jobs/items)
dwolla.getMassPayJobItems(c.token, jobId, null, function(err, data) {
dwolla.getMassPayJobItems(c.token, jobId, function(err, data) {
if (err) { console.log(err); }
console.log(data);
});
});
189 changes: 92 additions & 97 deletions lib/dwolla.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ function _post(path, post_data, fn) {
}

/**
* Toggle to use the UAT sandbox environment or the actual production Dwolla environment.
* Toggle to use the UAT sandbox environment or the actual production Dwolla environment.
*
* You can read more about the sandboxed environment below:
* You can read more about the sandboxed environment below:
* https://developers.dwolla.com/dev/pages/sandbox
**/

Expand Down Expand Up @@ -561,107 +561,102 @@ exports.withdraw = function(oauth_token, pin, sourceId, amount, fn) {
_post('/fundingsources/' + sourceId + '/withdraw', params, fn);
};

/**
* Creates a MassPay Job for the user for the authorized access token.
* Takes an array of objects, each containing amount, destination,
* destinationType, and note as items.
*
* https://developers.dwolla.com/dev/docs/masspay/create
* Required arguments:
*
* @param {String} oauth_token
* @param {string} fundsSource
* @param {int} pin
* @param {array} items
* @param {object} params
* @param {function} fn
*
* Optional params:
*
* boolean assumeCosts
* string userJobId
*
**/

exports.createMassPayJob = function(oauth_token, fundsSource, pin, items, params, fn) {
// params are optional
if (!fn || typeof params !== 'function') {
fn = params;
params = {};
}

if (typeof fn !== 'function') { throw new Error('Missing callback'); }
if (!oauth_token) { throw new Error('Missing arg oauth_token'); }
if (!pin) { throw new Error('Missing arg pin'); }
if (!fundsSource) { throw new Error('Missing arg fundsSource'); }
if (!items) { throw new Error('Missing arg items'); }

params = params || {};
params.oauth_token = oauth_token;
params.fundsSource = fundsSource;
params.pin = pin;
params.items = items;
_post('/masspay/', params, fn);
}
/**
* Creates a MassPay Job for the user for the authorized access token.
* Takes an array of objects, each containing amount, destination,
* destinationType, and note as items.
*
* https://developers.dwolla.com/dev/docs/masspay/create
*
* Required arguments:
*
* @param {String} oauth_token
* @param {string} fundsSource
* @param {int} pin
* @param {array} items
* @param {object} params
* @param {function} fn
*
* Optional params:
*
* boolean assumeCosts
* string userJobId
*
**/
exports.createMassPayJob = function(oauth_token, fundsSource, pin, items, params, fn) {
// params are optional
if (!fn && typeof params === 'function') {
fn = params;
params = {};
}

/**
* Fetches details about an existing MassPay Job, given a job_id.
*
* https://developers.dwolla.com/dev/docs/masspay/job
if (typeof fn !== 'function') { throw new Error('Missing callback'); }
if (!oauth_token) { throw new Error('Missing arg oauth_token'); }
if (!pin) { throw new Error('Missing arg pin'); }
if (!fundsSource) { throw new Error('Missing arg fundsSource'); }
if (!items) { throw new Error('Missing arg items'); }

* Required arguments:
*
* @param {String} oauth_token
* @param {string} job_id
* @param {function} fn
*
**/
params = params || {};
params.oauth_token = oauth_token;
params.fundsSource = fundsSource;
params.pin = pin;
params.items = items;
_post('/masspay/', params, fn);
};

exports.getMassPayJob = function(oauth_token, job_id, fn) {
if (typeof fn !== 'function') { throw new Error('Missing callback'); }
if (!job_id) { throw new Error('Missing Job ID'); }
if (!oauth_token) { throw new Error('Missing arg oauth_token'); }
/**
* Fetches details about an existing MassPay Job, given a job_id.
*
* https://developers.dwolla.com/dev/docs/masspay/job
*
* Required arguments:
*
* @param {String} oauth_token
* @param {string} job_id
* @param {function} fn
*
**/
exports.getMassPayJob = function(oauth_token, job_id, fn) {
if (typeof fn !== 'function') { throw new Error('Missing callback'); }
if (!job_id) { throw new Error('Missing Job ID'); }
if (!oauth_token) { throw new Error('Missing arg oauth_token'); }

params = {};
params.oauth_token = oauth_token;
params = {};
params.oauth_token = oauth_token;

_request('/masspay/' + job_id, params, fn)
}
_request('/masspay/' + job_id, params, fn);
};

/**
* Fetches all Items for a MassPay Job, given a job_id.
*
* https://developers.dwolla.com/dev/docs/masspay/jobs/items
* Required arguments:
*
* @param {String} oauth_token
* @param {string} job_id
* @param {function} fn
*
* Optional arguments:
*
* @param {integer} limit
* @param {integer} skip
*
**/

exports.getMassPayJobItems = function(oauth_token, job_id, params, fn) {
if (typeof fn !== 'function') { throw new Error('Missing callback'); }

// params are optional
if (!fn || typeof params !== 'function') {
fn = params;
params = {};
}
/**
* Fetches all Items for a MassPay Job, given a job_id.
*
* https://developers.dwolla.com/dev/docs/masspay/jobs/items
*
* Required arguments:
*
* @param {String} oauth_token
* @param {string} job_id
* @param {function} fn
*
* Optional arguments:
*
* @param {integer} limit
* @param {integer} skip
*
**/
exports.getMassPayJobItems = function(oauth_token, job_id, params, fn) {
// params are optional
if (!fn && typeof params === 'function') {
fn = params;
params = {};
}

if (!job_id) { throw new Error('Missing Job ID'); }
if (typeof fn !== 'function') { throw new Error('Missing callback'); }
if (!oauth_token) { throw new Error('Missing arg oauth_token'); }
if (!job_id) { throw new Error('Missing Job ID'); }
if (typeof fn !== 'function') { throw new Error('Missing callback'); }
if (!oauth_token) { throw new Error('Missing arg oauth_token'); }

params = params || {};
params.oauth_token = oauth_token;
params = params || {};
params.oauth_token = oauth_token;

_request('/masspay/' + job_id + '/items', params, fn)
}
_request('/masspay/' + job_id + '/items', params, fn);
};

0 comments on commit 5ef97cf

Please sign in to comment.