Skip to content

Commit 916c07e

Browse files
Merge pull request #24 from payjp/matuura/term-balance
add term and balance API
2 parents d8176da + e4ee482 commit 916c07e

5 files changed

Lines changed: 94 additions & 5 deletions

File tree

payjp/__init__.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,22 @@
1111
retry_max_delay = 32
1212

1313
# TODO include Card?
14-
__all__ = ['Account', 'Card', 'Charge', 'Customer', 'Event', 'Plan', 'Subscription', 'Token', 'Transfer', 'Statement']
14+
__all__ = [
15+
'Account',
16+
'Card',
17+
'Charge',
18+
'Customer',
19+
'Event',
20+
'Plan',
21+
'Subscription',
22+
'Token',
23+
'Transfer',
24+
'Statement',
25+
'Term',
26+
'Balance'
27+
]
1528

1629
# Resource
1730
from payjp.resource import ( # noqa
18-
Account, Charge, Customer, Event, Plan, Subscription, Token, Transfer, Statement)
31+
Account, Charge, Customer, Event, Plan, Subscription, Token, Transfer, Statement, Term, Balance)
1932

payjp/resource.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def convert_to_payjp_object(resp, api_key, account, api_base=None):
1616
'charge': Charge, 'customer': Customer,
1717
'event': Event, 'plan': Plan,
1818
'subscription': Subscription, 'token': Token,
19-
'transfer': Transfer, 'statement': Statement, 'list': ListObject}
19+
'transfer': Transfer, 'statement': Statement, 'list': ListObject, 'term': Term, 'balance': Balance}
2020

2121
if isinstance(resp, list):
2222
return [convert_to_payjp_object(i, api_key, account, api_base) for i in resp]
@@ -429,3 +429,11 @@ def statement_urls(self, **kwargs):
429429
url = self.instance_url() + '/statement_urls'
430430
self.refresh_from(self.request('post', url, kwargs))
431431
return self
432+
433+
434+
class Term(ListableAPIResource):
435+
pass
436+
437+
438+
class Balance(ListableAPIResource):
439+
pass

payjp/test/test_resources.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,5 +1143,73 @@ def test_statement_urls(self):
11431143
)
11441144

11451145

1146+
class TermTest(PayjpResourceTest):
1147+
1148+
def test_list_terms(self):
1149+
payjp.Term.all()
1150+
self.requestor_mock.request.assert_called_with(
1151+
'get',
1152+
'/v1/terms',
1153+
{}
1154+
)
1155+
1156+
def test_retrieve_term(self):
1157+
payjp.Term.retrieve('term_foo')
1158+
self.requestor_mock.request.assert_called_with(
1159+
'get',
1160+
'/v1/terms/term_foo',
1161+
{},
1162+
None
1163+
)
1164+
1165+
1166+
class BalanceTest(PayjpResourceTest):
1167+
response = {
1168+
"created": 1438354800,
1169+
"id": "ba_xxx",
1170+
"livemode": False,
1171+
"net": 1000,
1172+
"object": "balance",
1173+
"state": "collecting",
1174+
"statements": [{
1175+
"balance_id": "ba_xxx",
1176+
"created": 1438354800,
1177+
"id": "st_xxx",
1178+
"object": "statement",
1179+
}],
1180+
"closed": False,
1181+
"due_date": None,
1182+
"bank_info": None,
1183+
"tenant_id": None
1184+
}
1185+
1186+
def test_list_balances(self):
1187+
payjp.Balance.all()
1188+
self.requestor_mock.request.assert_called_with(
1189+
'get',
1190+
'/v1/balances',
1191+
{}
1192+
)
1193+
1194+
def test_retrieve_balance(self):
1195+
balance = payjp.Balance.retrieve('balance_foo')
1196+
self.requestor_mock.request.assert_called_with(
1197+
'get',
1198+
'/v1/balances/balance_foo',
1199+
{},
1200+
None
1201+
)
1202+
self.assertTrue(isinstance(balance, payjp.Balance))
1203+
self.assertEqual(balance.id, 'ba_xxx')
1204+
self.assertTrue(isinstance(balance.statements[0], payjp.Statement))
1205+
balance.statements[0].statement_urls()
1206+
self.requestor_mock.request.assert_called_with(
1207+
'post',
1208+
'/v1/statements/st_xxx/statement_urls',
1209+
{},
1210+
None
1211+
)
1212+
1213+
11461214
if __name__ == '__main__':
11471215
unittest.main()

payjp/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
VERSION = '0.2.0'
1+
VERSION = '0.4.0'

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
setup(
1616
name="payjp",
17-
version="0.2.0",
17+
version="0.4.0",
1818
description='PAY.JP python bindings',
1919
author="PAY.JP",
2020
author_email='support@pay.jp',

0 commit comments

Comments
 (0)