Skip to content

Commit a28ea44

Browse files
committed
Merge pull request #118 from teamsnap/payment-transaction-changes
memberPaymentTransaction, persistence, tests, and docs
2 parents 837d60b + 006f655 commit a28ea44

File tree

9 files changed

+148
-13
lines changed

9 files changed

+148
-13
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
# TeamSnap JavaScript SDK CHANGELOG
22

3+
### Feb 26, 2016 // Version 1.11.0
4+
- Adds `memberPaymentTransaction` method.
5+
- Adds persistence wrapper to `memberPaymentTransaction` to reload `teamFee` and `memberBalance`.
6+
7+
---
8+
39
### Feb 17, 2016 // Version 1.10.0
410
- Adds `inviteMemberEmailAddresses` method.
511
- Lock down dependencies while we investigate upgrading to latest and greatest.
12+
613
---
714

815
### Feb 15, 2016 // Version 1.9.0

docs/collections/member_payments.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
- [loadMemberPayments](#loadMemberPayments)
66
- [saveMemberPayment](#saveMemberPayment)
7+
- [memberPaymentTransaction](#memberPaymentTransaction)
78

89

910
---
@@ -47,3 +48,24 @@ Saves a `memberPayment` item.
4748
// Saves memberPayment item.
4849
teamsnap.saveMemberPayment(memberPayment);
4950
```
51+
52+
53+
---
54+
55+
56+
<a id="memberPaymentTransaction"></a>
57+
## `memberPaymentTransaction(memberPaymentId, amount, note, callback)`
58+
Creates a `memberPaymentTransaction`.
59+
60+
### Params
61+
* `memberPaymentId`: [id, object] - `memberPaymentId` or `memberPayment` item to be saved.
62+
* `amount`: [int, float] - The transaction amount.
63+
* `note`: [string] - A note for the transaction (optional).
64+
* `callback`: [function] - callback to be executed when the operation completes.
65+
66+
### Examples
67+
```javascript
68+
// ~~~~~
69+
// Creates memberPaymentTransaction.
70+
teamsnap.memberPaymentTransaction(1, 5.00, 'paid by check');
71+
```

lib/teamsnap.js

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1532,6 +1532,28 @@ exports.saveMemberPayment = function(memberPayment, callback) {
15321532
return this.saveItem(memberPayment, callback);
15331533
};
15341534

1535+
exports.memberPaymentTransaction = function(memberPaymentId, amount, note, callback) {
1536+
var params;
1537+
if (!this.isItem(memberPaymentId)) {
1538+
throw new TSArgsError('teamsnap.memberPaymentTransaction', "must provide a `memberPaymentId`");
1539+
}
1540+
if (this.isItem(memberPaymentId)) {
1541+
memberPaymentId = memberPaymentId.id;
1542+
}
1543+
if (!amount) {
1544+
throw new TSArgsError('teamsnap.memberPaymentTransaction', "must provide an `amount`");
1545+
}
1546+
if (typeof note === 'function') {
1547+
callback = note;
1548+
}
1549+
params = {
1550+
memberPaymentId: memberPaymentId,
1551+
amount: amount,
1552+
note: note
1553+
};
1554+
return this.collections.memberPayments.exec('transaction', params).pop().callback(callback);
1555+
};
1556+
15351557
});
15361558

15371559
require.register("collections/memberPhoneNumbers", function(exports, require, module) {
@@ -4738,7 +4760,7 @@ modifySDK = function(sdk) {
47384760
}).callback(callback);
47394761
};
47404762
});
4741-
return wrapMethod(sdk, 'invite', function(invite) {
4763+
wrapMethod(sdk, 'invite', function(invite) {
47424764
return function(options, callback) {
47434765
return invite.call(this, options).then(function(result) {
47444766
var contactId, memberId;
@@ -4760,6 +4782,22 @@ modifySDK = function(sdk) {
47604782
}).callback(callback);
47614783
};
47624784
});
4785+
return wrapMethod(sdk, 'memberPaymentTransaction', function(memberPaymentTransaction) {
4786+
return function(memberPaymentId, amount, note, callback) {
4787+
return memberPaymentTransaction.call(this, memberPaymentId, amount, note).then(function(result) {
4788+
var memberId, teamFeeId;
4789+
memberId = result.memberId;
4790+
teamFeeId = result.teamFeeId;
4791+
return promises.when(sdk.loadMemberBalances({
4792+
memberId: memberId
4793+
}), sdk.loadTeamFees({
4794+
id: teamFeeId
4795+
})).then(function() {
4796+
return result;
4797+
});
4798+
}).callback(callback);
4799+
};
4800+
});
47634801
};
47644802

47654803
revertSDK = function(sdk) {
@@ -5805,7 +5843,7 @@ ref = require('./model'), Collection = ref.Collection, Item = ref.Item;
58055843
require('./errors');
58065844

58075845
TeamSnap = (function() {
5808-
TeamSnap.prototype.version = '1.10.0';
5846+
TeamSnap.prototype.version = '1.11.0';
58095847

58105848
TeamSnap.prototype.promises = promises;
58115849

lib/teamsnap.min.js

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "teamsnap.js",
3-
"version": "1.10.0",
3+
"version": "1.11.0",
44
"description": "A JavaScript library for using the TeamSnap API.",
55
"author": "Jacob Wright with TeamSnap (http://www.teamsnap.com)",
66
"homepage": "https://github.com/teamsnap/teamsnap-javascript-sdk",

src/collections/memberPayments.coffee

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,19 @@ exports.saveMemberPayment = (memberPayment, callback) ->
1919
return @reject 'You must choose a member.', 'memberId', callback
2020

2121
@saveItem memberPayment, callback
22+
23+
exports.memberPaymentTransaction = (memberPaymentId, amount, note, callback) ->
24+
unless @isItem memberPaymentId
25+
throw new TSArgsError 'teamsnap.memberPaymentTransaction', "must provide
26+
a `memberPaymentId`"
27+
if @isItem memberPaymentId
28+
memberPaymentId = memberPaymentId.id
29+
unless amount
30+
throw new TSArgsError 'teamsnap.memberPaymentTransaction', "must provide
31+
an `amount`"
32+
if typeof note is 'function'
33+
callback = note
34+
params = memberPaymentId: memberPaymentId, amount: amount, note: note
35+
36+
@collections.memberPayments.exec('transaction', params)
37+
.pop().callback callback

src/persistence.coffee

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,8 @@ modifySDK = (sdk) ->
193193
# 8. deleteTrackedItem needs to remove trackedItemStatuses
194194
# 9. deleteTeam needs to remove all related data except plan and sport
195195
# 10. deleteForumTopic needs to delete all related posts
196+
# 11. memberEmailAddresses need to reload when invite is sent
197+
# 12. teamFee and memberBalance needs to reload after transaction
196198

197199
# Load related records when a member is created
198200
wrapSave sdk, 'saveMember', (member) ->
@@ -683,6 +685,19 @@ modifySDK = (sdk) ->
683685
).callback callback
684686

685687

688+
wrapMethod sdk, 'memberPaymentTransaction', (memberPaymentTransaction) ->
689+
(memberPaymentId, amount, note, callback) ->
690+
memberPaymentTransaction.call(this, memberPaymentId, amount, note)
691+
.then((result) ->
692+
memberId = result.memberId
693+
teamFeeId = result.teamFeeId
694+
promises.when(
695+
sdk.loadMemberBalances(memberId: memberId)
696+
sdk.loadTeamFees(id: teamFeeId)
697+
).then -> result
698+
).callback callback
699+
700+
686701
revertSDK = (sdk) ->
687702
revertWrapMethod sdk, 'saveMember'
688703
revertWrapMethod sdk, 'deleteMember'

src/teamsnap.coffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ promises = require './promises'
33
require './errors'
44

55
class TeamSnap
6-
version: '1.10.0'
6+
version: '1.11.0'
77
promises: promises
88
when: promises.when
99
TeamSnap: TeamSnap

test/memberPayments.coffee

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,44 @@
1+
memberPayment = {}
2+
13
describe 'Member Payments', ->
24

3-
it 'should be able to load all member payments for team', (done) ->
4-
teamsnap.loadMemberPayments team.id, (err, result) ->
5-
expect(err).to.be.null
6-
result.should.be.an('array')
7-
done()
5+
beforeEach (done) ->
6+
team.members = [
7+
{
8+
id: 1,
9+
firstName: 'Ownie',
10+
lastName: 'Owner',
11+
memberPayments: [
12+
{
13+
type: 'memberPayment',
14+
id: 222,
15+
amountDue: 100.00,
16+
amountPaid: 50.00,
17+
memberId: 1,
18+
teamId: team.id
19+
20+
}
21+
]
22+
}
23+
]
24+
memberPayment = team.members[0].memberPayments[0]
25+
done()
26+
27+
describe 'loadMemberPayments', ->
28+
it 'should be able to load all member payments for team', ->
29+
teamsnap.loadMemberPayments team.id, (err, result) ->
30+
expect(err).to.be.null
31+
result.should.be.an('array')
32+
33+
describe 'memberPaymentTransaction', ->
34+
it 'should accept a memberPayment object', ->
35+
teamsnap.memberPaymentTransaction memberPayment, 4, (err, result) ->
36+
result.id.should.equal 222
37+
38+
it 'should accept a memberPaymentId', ->
39+
teamsnap.memberPaymentTransaction memberPayment.id, 10.00, (err, result) ->
40+
result.id.should.equal 222
41+
42+
it 'should adjust memberPayment.amoutPaid', ->
43+
teamsnap.memberPaymentTransaction memberPayment.id, 10.00, (err, result) ->
44+
result.amountPaid.should.equal 90.00

0 commit comments

Comments
 (0)