Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
Current Version
-

2.7.0 November 6, 2017
- Add get orders by button ref

2.6.0 July 19, 2017
- Add `customers` resource

Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,16 @@ client.orders.get('btnorder-XXX', function(err, res) {
});
```

##### Get by Button Ref

```javascript
var client = require('@button/button-client-node')('sk-XXX');

client.orders.getByBtnRef('srctok-XXX', function (err, res) {
// ...
});
```

##### Update

```javascript
Expand Down
15 changes: 15 additions & 0 deletions lib/resources/orders.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,21 @@ function orders(requestOptions, maybePromiseRequest) {

return maybePromiseRequest(options, callback);
},
getByBtnRef: function get(btnRef, callback) {
//
// Lists orders by btn_ref.
//
// @param {string} btnRef the button attribution token
// @callback invoked iff config.promise isn't valid
// @returns {Object=} a promise or undefined, depending on
// `config.promise`
var options = merge(requestOptions, {
method: 'GET',
path: '/v1/order/btn-ref/' + btnRef
});

return maybePromiseRequest(options, callback);
},
create: function create(order, callback) {
//
// Creates an order.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@button/button-client-node",
"version": "2.6.0",
"version": "2.7.0",
"description": "node.js client for the Button Order API",
"repository": {
"type": "git",
Expand Down
29 changes: 29 additions & 0 deletions test/lib/resources/orders-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,35 @@ describe('lib/resources/orders', function() {

});

describe('#getByBtnRef', function() {

beforeEach(function() {
this.btnRef = 'srctok-XXX';
this.order = { 'button_order_id': 'srctok-XXX' };
this.scope = nock('https://api.usebutton.com:443')
.get('/v1/order/btn-ref/' + this.btnRef)
.reply(200, { meta: { status: 'ok' }, 'objects': [this.order] });
});

it('gets an order with a callback', function(done) {
this.callbackClient.getByBtnRef(this.btnRef, function(err, res) {
expect(err).to.be(null);
expect(res.data[0]).to.eql(this.order);
this.scope.done();
done();
}.bind(this));
});

it('gets an order with a promise', function(done) {
this.promiseClient.getByBtnRef(this.btnRef).then(function(result) {
expect(result.data[0]).to.eql(this.order);
this.scope.done();
done();
}.bind(this)).catch(done);
});

});

describe('#create', function() {

beforeEach(function() {
Expand Down