Skip to content

Commit 75b54d5

Browse files
committed
#29, subscribe 빌링키 생성 추가
1 parent 56f8341 commit 75b54d5

File tree

4 files changed

+54
-0
lines changed

4 files changed

+54
-0
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,8 @@ atlassian-ide-plugin.xml
105105
com_crashlytics_export_strings.xml
106106
crashlytics.properties
107107
crashlytics-build.properties
108+
109+
.pytest_cache/
110+
.python-version
111+
venv/
112+

iamport/client.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,18 @@ def pay_again(self, **kwargs):
9595

9696
return self._post(url, kwargs)
9797

98+
def customer_create(self, **kwargs):
99+
customer_uid = kwargs.get('customer_uid')
100+
for key in ['customer_uid', 'card_number', 'expiry', 'birth']:
101+
if key not in kwargs:
102+
raise KeyError('Essential parameter is missing!: %s' % key)
103+
url = '{}subscribe/customers/{}'.format(self.imp_url, customer_uid)
104+
return self._post(url, kwargs)
105+
106+
def customer_get(self, customer_uid):
107+
url = '{}subscribe/customers/{}'.format(self.imp_url, customer_uid)
108+
return self._get(url)
109+
98110
def pay_foreign(self, **kwargs):
99111
url = '{}subscribe/payments/foreign'.format(self.imp_url)
100112
for key in ['merchant_uid', 'amount', 'card_number', 'expiry']:

tests/test_customer_create.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# -*- coding: utf-8 -*-
2+
import pytest
3+
4+
5+
def test_customer_create(iamport):
6+
# Without 'card_number'
7+
payload_notEnough = {
8+
'customer_uid': 'customer_1234',
9+
'expiry': '2019-03',
10+
'birth': '500203',
11+
}
12+
13+
with pytest.raises(KeyError) as e:
14+
iamport.customer_create(**payload_notEnough)
15+
assert "Essential parameter is missing!: card_number" in str(e)
16+
17+
payload_full = {
18+
'customer_uid': 'customer_1234',
19+
'expiry': '2019-03',
20+
'birth': '500203',
21+
'card_number': '4092-0230-1234-1234',
22+
}
23+
24+
with pytest.raises(iamport.ResponseError) as e:
25+
iamport.customer_create(**payload_full)
26+
assert e.code == -1
27+
assert u'카드정보 인증 및 빌키 발급에 실패하였습니다.' in e.message

tests/test_customer_get.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# -*- coding: utf-8 -*-
2+
import pytest
3+
4+
5+
def test_customer_get(iamport):
6+
customer_uid = '000000'
7+
with pytest.raises(iamport.ResponseError) as e:
8+
iamport.customer_get(customer_uid)
9+
assert u'요청하신 customer_uid(000000)로 등록된 정보를 찾을 수 없습니다.' == e.message
10+

0 commit comments

Comments
 (0)