Skip to content

Commit

Permalink
Merge pull request #49 from OpenSaasAU/master
Browse files Browse the repository at this point in the history
Change createPayment to newPayment and add multi-payment put
  • Loading branch information
jordanwalsh23 authored Jul 5, 2017
2 parents 2f4e41b + 8bb8957 commit 67e4b7d
Show file tree
Hide file tree
Showing 5 changed files with 2,450 additions and 6 deletions.
35 changes: 34 additions & 1 deletion docs/Payments.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ The entity helper that has been created for the payments functions exists in the

This helper contains the following functions:

* `createPayment(data[, options])`
* `newPayment(data[, options])`
* `getPayments([options])`
* `getPayment(id[, modifiedAfter])`
* `savePayments(data[, options])`

### Creating a new payment

Expand Down Expand Up @@ -148,3 +149,35 @@ xeroClient.core.payments.getPayment(somePaymentID)
})
});
```

### Creating multiple payments in one go

You can use the helper function `savePayments` to save an array of payments in one go.

The following code provides guidance on how to set this up:

```javascript

var samplePayment1 = {
//some item...
};

var samplePayment2 = {
//some item...
};

var payments = [];

payments.push(xeroClient.core.payments.newPayment(samplePayment1));
payments.push(xeroClient.core.payments.newPayment(samplePayment));

xeroClient.core.items.savePayments(payments)
.then(function(payments) {
//Payments have been created
var payment1 = payments.entities[0];
var payment2 = payments.entities[1];
})
.catch(function(err) {
//Some error occurred
});
```
2 changes: 1 addition & 1 deletion lib/entities/accounting/payment.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ var Payment = Entity.extend(PaymentSchema, {
return this.application.putOrPostEntity(method, path, xml, {
entityPath: 'Payments.Payment',
entityConstructor: function(data) {
return self.application.core.payments.createPayment(data);
return self.application.core.payments.newPayment(data);
}
});
}
Expand Down
14 changes: 12 additions & 2 deletions lib/entity_helpers/accounting/payments.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var Payments = EntityHelper.extend({
constructor: function(application, options) {
EntityHelper.call(this, application, Object.assign({ entityName: 'Payment', entityPlural: 'Payments' }, options));
},
createPayment: function(data, options) {
newPayment: function(data, options) {
return new Payment(this.application, data, options);
},
getPayment: function(id, modifiedAfter) {
Expand All @@ -17,11 +17,21 @@ var Payments = EntityHelper.extend({
return _.first(payments);
})
},
savePayments: function(payments, options) {
return this.saveEntities(payments, this.setUpOptions(options));
},
getPayments: function(options) {
var self = this;
var clonedOptions = _.clone(options || {});
clonedOptions.entityConstructor = function(data) { return self.createPayment(data) };
clonedOptions.entityConstructor = function(data) { return self.newPayment(data) };
return this.getEntities(clonedOptions)
},
setUpOptions: function(options) {
var self = this;
var clonedOptions = _.clone(options || {});
clonedOptions.entityPath = 'Payments.Payment';
clonedOptions.entityConstructor = function(data) { return self.newPayment(data) };
return clonedOptions;
}
})

Expand Down
Loading

0 comments on commit 67e4b7d

Please sign in to comment.