Skip to content

Commit 4f567c9

Browse files
committed
Merge pull request #40 from teamsnap/payments
Payments
2 parents 06e7ce9 + 2da30c1 commit 4f567c9

File tree

13 files changed

+428
-9
lines changed

13 files changed

+428
-9
lines changed

lib/teamsnap.js

Lines changed: 118 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1338,7 +1338,20 @@ exports.loadMemberPayments = function(params, callback) {
13381338
} else if (!(params && typeof params === 'object')) {
13391339
throw new TSArgsError('teamsnap.loadMemberPayments', 'must provide a teamId or query parameters');
13401340
}
1341-
return this.loadItem('memberPayment', params, callback);
1341+
return this.loadItems('memberPayment', params, callback);
1342+
};
1343+
1344+
exports.saveMemberPayment = function(memberPayment, callback) {
1345+
if (!memberPayment) {
1346+
throw new TSArgsError('teamsnap.saveMemberPayment', '`memberPayment` must be provided');
1347+
}
1348+
if (!this.isItem(memberPayment, 'memberPayment')) {
1349+
throw new TSArgsError('teamsnap.saveMemberPayment', "`memberPayment.type` must be 'memberPayment'");
1350+
}
1351+
if (!memberPayment.memberId) {
1352+
return this.reject('You must choose a member.', 'memberId', callback);
1353+
}
1354+
return this.saveItem(memberPayment, callback);
13421355
};
13431356

13441357
});
@@ -1681,6 +1694,48 @@ exports.deleteOpponent = function(opponent, callback) {
16811694

16821695
});
16831696

1697+
require.register("collections/paymentNotes", function(exports, require, module) {
1698+
exports.loadPaymentNotes = function(params, callback) {
1699+
if (this.isId(params)) {
1700+
params = {
1701+
teamId: params
1702+
};
1703+
} else if (!(params && typeof params === 'object')) {
1704+
throw new TSArgsError('teamsnap.loadPaymentNotes', 'must provide a teamId or query parameters');
1705+
}
1706+
return this.loadItems('paymentNote', params, callback);
1707+
};
1708+
1709+
exports.createPaymentNote = function(data) {
1710+
return this.createItem(data, {
1711+
type: 'paymentNote'
1712+
});
1713+
};
1714+
1715+
exports.savePaymentNote = function(paymentNote, callback) {
1716+
if (!paymentNote) {
1717+
throw new TSArgsError('teamsnap.savePaymentNote', '`paymentNote` must be provided');
1718+
}
1719+
if (!this.isItem(paymentNote, 'paymentNote')) {
1720+
throw new TSArgsError('teamsnap.savePaymentNote', "`paymentNote.type` must be 'paymentNote'");
1721+
}
1722+
if (!paymentNote.teamId) {
1723+
return this.reject('You must choose a team.', 'teamId', callback);
1724+
}
1725+
if (!paymentNote.memberPaymentId) {
1726+
return this.reject('You must specify a memberPaymentId.', 'memberPaymentId', callback);
1727+
}
1728+
if (!paymentNote.note) {
1729+
return this.reject('You must provide a note.', 'note', callback);
1730+
}
1731+
if (!paymentNote.description) {
1732+
return this.reject('You must provide a description.', 'description', callback);
1733+
}
1734+
return this.saveItem(paymentNote, callback);
1735+
};
1736+
1737+
});
1738+
16841739
require.register("collections/plans", function(exports, require, module) {
16851740
exports.loadPlans = function(params, callback) {
16861741
if (!(params && typeof params === 'object')) {
@@ -1800,6 +1855,62 @@ exports.loadTeamFees = function(params, callback) {
18001855
return this.loadItems('teamFee', params, callback);
18011856
};
18021857

1858+
exports.createTeamFee = function(data) {
1859+
return this.createItem(data, {
1860+
type: 'teamFee'
1861+
});
1862+
};
1863+
1864+
exports.saveTeamFee = function(teamFee, callback) {
1865+
if (!teamFee) {
1866+
throw new TSArgsError('teamsnap.saveTeamFee', '`teamFee` must be provided');
1867+
}
1868+
if (!this.isItem(teamFee, 'teamFee')) {
1869+
throw new TSArgsError('teamsnap.saveTeamFee', "`teamFee.type` must be 'teamFee'");
1870+
}
1871+
if (!teamFee.teamId) {
1872+
return this.reject('You must choose a team.', 'teamId', callback);
1873+
}
1874+
if (!teamFee.description) {
1875+
return this.reject('You must provide a team fee description.', 'description', callback);
1876+
}
1877+
if (!teamFee.amount) {
1878+
return this.reject('You must provide a fee amount.', 'description', callback);
1879+
}
1880+
return this.saveItem(teamFee, callback);
1881+
};
1882+
1883+
exports.deleteTeamFee = function(teamFee, callback) {
1884+
if (!teamFee) {
1885+
throw new TSArgsError('teamsnap.deleteTeamFee', '`teamFee` must be provided');
1886+
}
1887+
return this.deleteItem(teamFee, callback);
1888+
};
1889+
1890+
});
1891+
1892+
require.register("collections/teamPaypalPreferences", function(exports, require, module) {
1893+
exports.teamPaypalPreferences = function(params, callback) {
1894+
if (this.isId(params)) {
1895+
params = {
1896+
teamId: params
1897+
};
1898+
} else if (!(params && typeof params === 'object')) {
1899+
throw new TSArgsError('teamsnap.teamPaypalPreferences', 'must provide a teamId or query parameters');
1900+
}
1901+
return this.loadItem('teamPaypalPreferences', params, callback);
1902+
};
1903+
1904+
exports.saveTeamPaypalPreferences = function(teamPaypalPreferences, callback) {
1905+
if (!teamPaypalPreferences) {
1906+
throw new TSArgsError('teamsnap.saveTeamPaypalPreferences', "`teamPaypalPreferences` must be provided");
1907+
}
1908+
if (!this.isItem(teamPaypalPreferences, 'teamPaypalPreferences')) {
1909+
throw new TSArgsError('teamsnap.saveTeamPaypalPreferences', "`teamPaypalPreferences.type` must be 'teamPaypalPreferences'");
1910+
}
1911+
return this.saveItem(teamPaypalPreferences, callback);
1912+
};
1913+
18031914
});
18041915

18051916
require.register("collections/teamPreferences", function(exports, require, module) {
@@ -4345,6 +4456,8 @@ add(require('./collections/opponents'));
43454456

43464457
add(require('./collections/opponentResults'));
43474458

4459+
add(require('./collections/paymentNotes'));
4460+
43484461
add(require('./collections/plans'));
43494462

43504463
add(require('./collections/sponsors'));
@@ -4353,6 +4466,8 @@ add(require('./collections/sports'));
43534466

43544467
add(require('./collections/teamFees'));
43554468

4469+
add(require('./collections/teamPaypalPreferences'));
4470+
43564471
add(require('./collections/teamPreferences'));
43574472

43584473
add(require('./collections/teamPublicSites'));
@@ -4437,7 +4552,7 @@ var plural, pluralLookup, singularLookup, teamTypes, teamsnap, type, typeLookup,
44374552

44384553
teamsnap = exports;
44394554

4440-
types = ['user', 'assignment', 'availability', 'broadcastSms', 'contact', 'contactEmailAddress', 'contactPhoneNumber', 'customDatum', 'customField', 'leagueCustomDatum', 'leagueCustomField', 'divisionLocation', 'divisionMember', 'divisionMemberPreferences', 'event', 'forumPost', 'forumSubscription', 'forumTopic', 'leagueRegistrantDocument', 'location', 'member', 'memberEmailAddress', 'memberFile', 'memberLink', 'memberPayment', 'memberPhoneNumber', 'memberPreferences', 'opponent', 'opponentResults', 'plan', 'smsGateway', 'sponsor', 'sport', 'team', 'teamFee', 'teamPreferences', 'teamPublicSite', 'teamResults', 'timeZone', 'trackedItem', 'trackedItemStatus'];
4555+
types = ['user', 'assignment', 'availability', 'broadcastSms', 'contact', 'contactEmailAddress', 'contactPhoneNumber', 'customDatum', 'customField', 'leagueCustomDatum', 'leagueCustomField', 'divisionLocation', 'divisionMember', 'divisionMemberPreferences', 'event', 'forumPost', 'forumSubscription', 'forumTopic', 'leagueRegistrantDocument', 'location', 'member', 'memberEmailAddress', 'memberFile', 'memberLink', 'memberPayment', 'memberPhoneNumber', 'memberPreferences', 'opponent', 'opponentResults', 'paymentNote', 'plan', 'smsGateway', 'sponsor', 'sport', 'team', 'teamFee', 'teamPaypalPreferences', 'teamPreferences', 'teamPublicSite', 'teamResults', 'timeZone', 'trackedItem', 'trackedItemStatus'];
44414556

44424557
teamTypes = types.slice();
44434558

@@ -4461,6 +4576,7 @@ pluralLookup = {
44614576
memberPreferences: 'membersPreferences',
44624577
divisionMemberPreferences: 'divisionMembersPreferences',
44634578
opponentResults: 'opponentsResults',
4579+
teamPaypalPreferences: 'teamsPaypalPreferences',
44644580
teamPreferences: 'teamsPreferences',
44654581
teamResults: 'teamsResults',
44664582
customDatum: 'customData',

lib/teamsnap.min.js

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

lib/test/js/test.js

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5553,6 +5553,19 @@ describe('Member Links', function() {
55535553

55545554
});
55555555

5556+
require.register("test/memberPayments", function(exports, require, module) {
5557+
describe('Member Payments', function() {
5558+
return it('should be able to load all member payments for team', function(done) {
5559+
return teamsnap.loadMemberPayments(team.id, function(err, result) {
5560+
expect(err).to.be["null"];
5561+
result.should.be.an('array');
5562+
return done();
5563+
});
5564+
});
5565+
});
5566+
5567+
});
5568+
55565569
require.register("test/memberPhoneNumbers", function(exports, require, module) {
55575570
describe('Member Phone Numbers', function() {
55585571
var member, phone;
@@ -5754,6 +5767,76 @@ describe('Opponents', function() {
57545767

57555768
});
57565769

5770+
require.register("test/paymentNotes", function(exports, require, module) {
5771+
describe('Payment Notes', function() {
5772+
var member, memberPayment, paymentNote, teamFee;
5773+
teamFee = null;
5774+
member = null;
5775+
memberPayment = null;
5776+
paymentNote = null;
5777+
before(function(done) {
5778+
teamFee = teamsnap.createTeamFee();
5779+
teamFee.teamId = team.id;
5780+
teamFee.description = 'Test Team Fee';
5781+
teamFee.amount = 1;
5782+
return teamsnap.saveTeamFee(teamFee, function(err, result) {
5783+
expect(err).to.be["null"];
5784+
return done();
5785+
});
5786+
});
5787+
before(function(done) {
5788+
member = teamsnap.createMember();
5789+
member.teamId = team.id;
5790+
member.firstName = 'Test';
5791+
return teamsnap.saveMember(member, function(err, result) {
5792+
expect(err).to.be["null"];
5793+
return done();
5794+
});
5795+
});
5796+
before(function(done) {
5797+
return teamsnap.loadMemberPayments({
5798+
memberId: member.id,
5799+
teamFeeId: teamFee.id
5800+
}).then(function(memberPayments) {
5801+
memberPayment = memberPayments[0];
5802+
return done();
5803+
});
5804+
});
5805+
after(function(done) {
5806+
return teamsnap.deleteMember(member, function(err, result) {
5807+
expect(err).to.be["null"];
5808+
return done();
5809+
});
5810+
});
5811+
after(function(done) {
5812+
return teamsnap.deleteTeamFee(teamFee, function(err, result) {
5813+
expect(err).to.be["null"];
5814+
return done();
5815+
});
5816+
});
5817+
it('should be able to load all payment notes for a team', function(done) {
5818+
return teamsnap.loadPaymentNotes(team.id, function(err, result) {
5819+
expect(err).to.be["null"];
5820+
result.should.be.an('array');
5821+
return done();
5822+
});
5823+
});
5824+
return it('should be able to create a payment note', function(done) {
5825+
paymentNote = teamsnap.createPaymentNote();
5826+
paymentNote.teamId = team.id;
5827+
paymentNote.memberPaymentId = memberPayment.id;
5828+
paymentNote.note = 'Test payment note.';
5829+
paymentNote.description = 'Payment Note Description';
5830+
return teamsnap.savePaymentNote(paymentNote, function(err, result) {
5831+
expect(err).to.be["null"];
5832+
result.should.have.property('type', 'paymentNote');
5833+
return done();
5834+
});
5835+
});
5836+
});
5837+
5838+
});
5839+
57575840
require.register("test/plans", function(exports, require, module) {
57585841
describe('Plans', function() {
57595842
it('should be able to load all plans', function() {
@@ -5828,6 +5911,38 @@ describe('Sports', function() {
58285911

58295912
});
58305913

5914+
require.register("test/teamFees", function(exports, require, module) {
5915+
describe('Team Fees', function() {
5916+
var teamFee;
5917+
teamFee = null;
5918+
it('should be able to load all team fees', function(done) {
5919+
return teamsnap.loadTeamFees(team.id, function(err, result) {
5920+
expect(err).to.be["null"];
5921+
result.should.be.an('array');
5922+
return done();
5923+
});
5924+
});
5925+
it('should be able to create a team fee', function(done) {
5926+
teamFee = teamsnap.createTeamFee();
5927+
teamFee.teamId = team.id;
5928+
teamFee.description = 'Test Team Fee';
5929+
teamFee.amount = 1;
5930+
return teamsnap.saveTeamFee(teamFee, function(err, result) {
5931+
expect(err).to.be["null"];
5932+
result.should.have.property('type', 'teamFee');
5933+
return done();
5934+
});
5935+
});
5936+
return it('should be able to delete a team fee', function(done) {
5937+
return teamsnap.deleteTeamFee(teamFee, function(err, result) {
5938+
expect(err).to.be["null"];
5939+
return done();
5940+
});
5941+
});
5942+
});
5943+
5944+
});
5945+
58315946
require.register("test/teamPreferences", function(exports, require, module) {
58325947
describe('Team Preferences', function() {
58335948
it('should be able to load preferences for teams', function(done) {

lib/test/js/test.min.js

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

src/collections/memberPayments.coffee

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,17 @@ exports.loadMemberPayments = (params, callback) ->
55
throw new TSArgsError 'teamsnap.loadMemberPayments', 'must provide a
66
teamId or query parameters'
77

8-
@loadItem 'memberPayment', params, callback
8+
@loadItems 'memberPayment', params, callback
9+
10+
11+
exports.saveMemberPayment = (memberPayment, callback) ->
12+
unless memberPayment
13+
throw new TSArgsError 'teamsnap.saveMemberPayment', '`memberPayment`
14+
must be provided'
15+
unless @isItem memberPayment, 'memberPayment'
16+
throw new TSArgsError 'teamsnap.saveMemberPayment',
17+
"`memberPayment.type` must be 'memberPayment'"
18+
unless memberPayment.memberId
19+
return @reject 'You must choose a member.', 'memberId', callback
20+
21+
@saveItem memberPayment, callback
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
exports.loadPaymentNotes = (params, callback) ->
2+
if @isId params
3+
params = teamId: params
4+
else unless params and typeof params is 'object'
5+
throw new TSArgsError 'teamsnap.loadPaymentNotes', 'must provide a
6+
teamId or query parameters'
7+
8+
@loadItems 'paymentNote', params, callback
9+
10+
11+
exports.createPaymentNote = (data) ->
12+
@createItem data,
13+
type: 'paymentNote'
14+
15+
16+
exports.savePaymentNote = (paymentNote, callback) ->
17+
unless paymentNote
18+
throw new TSArgsError 'teamsnap.savePaymentNote', '`paymentNote`
19+
must be provided'
20+
unless @isItem paymentNote, 'paymentNote'
21+
throw new TSArgsError 'teamsnap.savePaymentNote',
22+
"`paymentNote.type` must be 'paymentNote'"
23+
unless paymentNote.teamId
24+
return @reject 'You must choose a team.', 'teamId', callback
25+
unless paymentNote.memberPaymentId
26+
return @reject 'You must specify a memberPaymentId.',
27+
'memberPaymentId', callback
28+
unless paymentNote.note
29+
return @reject 'You must provide a note.', 'note', callback
30+
unless paymentNote.description
31+
return @reject 'You must provide a description.', 'description', callback
32+
@saveItem paymentNote, callback

src/collections/teamFees.coffee

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,35 @@ exports.loadTeamFees = (params, callback) ->
55
throw new TSArgsError 'teamsnap.loadTeamFees', 'must provide a
66
teamId or query parameters'
77

8-
@loadItems 'teamFee', params, callback
8+
@loadItems 'teamFee', params, callback
9+
10+
11+
exports.createTeamFee = (data) ->
12+
@createItem data,
13+
type: 'teamFee'
14+
15+
16+
exports.saveTeamFee = (teamFee, callback) ->
17+
unless teamFee
18+
throw new TSArgsError 'teamsnap.saveTeamFee', '`teamFee`
19+
must be provided'
20+
unless @isItem teamFee, 'teamFee'
21+
throw new TSArgsError 'teamsnap.saveTeamFee',
22+
"`teamFee.type` must be 'teamFee'"
23+
unless teamFee.teamId
24+
return @reject 'You must choose a team.', 'teamId', callback
25+
unless teamFee.description
26+
return @reject 'You must provide a team fee description.',
27+
'description', callback
28+
unless teamFee.amount
29+
return @reject 'You must provide a fee amount.',
30+
'description', callback
31+
@saveItem teamFee, callback
32+
33+
34+
exports.deleteTeamFee = (teamFee, callback) ->
35+
unless teamFee
36+
throw new TSArgsError 'teamsnap.deleteTeamFee',
37+
'`teamFee` must be provided'
38+
39+
@deleteItem teamFee, callback

0 commit comments

Comments
 (0)