Skip to content

Commit

Permalink
updating the readme, v1.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewfl committed Feb 28, 2014
1 parent 1f179d6 commit 96b5569
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 95 deletions.
120 changes: 26 additions & 94 deletions README.md
@@ -1,9 +1,9 @@
Balanced Node.js library
=========

[![Build Status](https://travis-ci.org/balanced/balanced-node.png?branch=master)](https://travis-ci.org/balanced/balanced-node)
[![Build Status](https://travis-ci.org/balanced/balanced-node.png?branch=rev1)](https://travis-ci.org/balanced/balanced-node)

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).

The Balanced Payments API located here: https://www.balancedpayments.com/docs/api.

Expand All @@ -15,112 +15,44 @@ into a terminal window:
npm install balanced-official
```

Testing
-------

By running test/test.js you may test most of the functionality and use cases for balanced against the Balanced Payments API as well as see examples for invoking each of the methods exposed (jsDoc to come soon). In order to run the tests, you must edit the test.js file to include the marketplace_uri and secret values to the nbalanced module (just as if you were using it yourself). Here is where you would plug in your test account credentials supplied on your Balanced Payments Dashboard.

```js
var api = new balanced({
marketplace_uri: "/v1/marketplaces/:marketplace-id", // test marketplace
secret: ":secret" // test secret
});
```

As a word of *caution*, running through all of the tests will generate a lot of garbage in your test account, you have been forewarned.

Basic Usage
-----------

```js
var balanced = require('balanced');

var api = new balanced({
marketplace_uri: "/v1/marketplaces/:marketplace-id",
secret: ":secret"
});

// Create a credit card
// NOTE: Cards is a property of balanced() and already has API context.
api.Cards.create({
card_number: "5105105105105100",
expiration_year: 2020,
expiration_month: 12,
security_code: "123"
}, function (err, object) {
if (err) {
console.error("api.Cards.create", err);
throw err;
}
myCard = object;
console.log("Created new Card:", myCard.uri);
next("api.Cards.create");
});
```
var balanced = require('balanced-official');

Customers
---------
balanced.configure('api-secret-key');

`Customers` are the best way to manage an entity's bank accounts, cards and transactions
in the Balanced API and supercede the functionality previously provided by Accounts. Customers
were created to simplify merchant underwriting so that you can accept money on a vendors behalf.
var customer = balanced.marketplace.customers.create();

Because of this, the balanced Customer prototype has an additional function called balanced, which takes an account object (containing the URI of the account, or from the Customers.(create | get | list) functions). This function returns a new balanced() instance with the customer as the context for all actions against it (e.g. a new bank account will be created for that customer automatically).

```js
// Customers are special, because accounts change API context so that bank account, cards, etc.
// that are created for a specific account, are done so without the need for additional URI tracking
// or contextual clues.

var newCustomerApi;
api.Customers.create({ name: "Valued Customer" }, function (err, newCustomer) {
if (err) {
console.error("api.Customer.create", err);
throw err;
}
// Here we get an customer specific context of balanced() to work with. This is necessary for
// customer specific actions.
newCustomerApi = api.Customer.balanced(newCustomer);
console.log("Created new Customer:", newCustomer.uri);
var card = balanced.marketplace.cards.create({
'number': '4111111111111111',
'expiration_year': '2016',
'expiration_month': '12',
'cvv': '123'
});
```

Which now allows us to do:

```js
// add a bank account to the customer without having to specify the customer_uri
newCustomerApi.Customers.addBankAccount(tokenized_bank_account_uri, function(err, response){ ... })
card.associate_to_customer(customer)
.debit(5000)
.then(function (debit) {
// save the result of the debit
}, function (err) {
// record the error message
});;
```

Accounts (deprecated)
--------
[More examples](https://github.com/balanced/balanced-node/blob/rev1/test/test.js)

Accounts are a special concept in the Balanced API. An account tracks a specific person or business whom may have many cards, bank accounts and transactions. The Balanced API also has specific and special use cases for dealing and interacting with accounts.

Because of this, the balanced Accounts prototype has an additional function called balanced, which takes an account object (containing the URI of the account, or from the Accounts.(create | get | list) functions). This function returns a new balanced() instance with the account as the context for all actions against it (e.g. a new bank account will be created for that account automatically).
Testing
-------

```js
// Accounts are special, because accounts change API context so that bank account, cards, etc.
// that are created for a specific account, are done so without the need for additional URI tracking
// or contextual clues.
api.Accounts.create(function (err, object) {
if (err) {
console.error("api.Accounts.create", err);
throw err;
}
var myAccount = object;
// Here we get an account specific context of balanced() to work with. This is necessary for
// account specific actions.
api = api.Accounts.balanced(myAccount);
console.log("Created new Account:", myAccount.uri);
});
To run the tests in a terminal run
```
npm test
```

Or, we can also take a quick and dirty approach if all we have is the account URI:

```js
// Here we create an instance of balanced for our account and create a bank account in one line.
api.Accounts.nbalannced({
uri: "/v1/marketplaces/:marketplace-id/accounts/:account-id"
}).BankAccounts.create({/*...*/}, function (err, object){/*...*/});
To run a specific test, you can do
```
node test/tests.js [test name]
```
2 changes: 1 addition & 1 deletion package.json
@@ -1,7 +1,7 @@
{
"name": "balanced-official-beta",
"description": "Offical Balanced Payments API Client for node.js, https://www.balancedpayments.com/docs/api",
"version": "1.0.2",
"version": "1.0.3",

This comment has been minimized.

Copy link
@mjallday

mjallday Feb 28, 2014

Contributor

wow, this is just a build version bump? ;)

This comment has been minimized.

Copy link
@matthewfl

matthewfl Feb 28, 2014

Author Contributor

wanted to push the latest version to npm (as the -beta)

This comment has been minimized.

Copy link
@matthewfl

matthewfl Feb 28, 2014

Author Contributor

and the interface hasn't lost any features, only internal redactors and additional stuff added

"author": "Balanced Payments",
"contributors": [
"matthewfl, matthew@balancedpayments.com"
Expand Down

0 comments on commit 96b5569

Please sign in to comment.