Skip to content

Commit 64c6476

Browse files
committed
Added PayPalAccounts endpoint
1 parent fcda547 commit 64c6476

6 files changed

Lines changed: 257 additions & 3 deletions

File tree

CHANGELOG.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
Changelog
22
=========
33

4-
1.1.3 (current)
4+
1.1.4 (current)
5+
------------------
6+
7+
- Added PayPal account endpoint
8+
9+
1.1.3 (2018-07-05)
510
------------------
611

712
- Added transfer endpoint

hyperwallet/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
__email__ = 'devsupport@hyperwallet.com'
77
__copyright__ = 'Copyright (c) 2017 Hyperwallet'
88
__license__ = 'MIT'
9-
__version__ = '1.1.3'
9+
__version__ = '1.1.4'
1010
__url__ = 'https://github.com/hyperwallet/python-sdk'
1111
__download_url__ = 'https://pypi.python.org/pypi/hyperwallet-sdk'
1212
__description__ = 'A Python wrapper around the Hyperwallet API'
@@ -21,6 +21,7 @@
2121
PrepaidCard, # noqa
2222
PaperCheck, # noqa
2323
Transfer, # noqa
24+
PayPalAccount, # noqa
2425
Payment, # noqa
2526
Balance, # noqa
2627
Receipt, # noqa

hyperwallet/api.py

Lines changed: 99 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
PrepaidCard,
1515
PaperCheck,
1616
Transfer,
17+
PayPalAccount,
1718
Payment,
1819
Balance,
1920
Receipt,
@@ -1457,7 +1458,7 @@ def deactivatePaperCheck(self,
14571458
'''
14581459

14591460
def createTransfer(self,
1460-
data=None):
1461+
data=None):
14611462
'''
14621463
Create a Transfer.
14631464
@@ -1560,6 +1561,103 @@ def createTransferStatusTransition(self,
15601561

15611562
'''
15621563
1564+
PayPal Accounts
1565+
1566+
'''
1567+
1568+
def createPayPalAccount(self,
1569+
userToken=None,
1570+
data=None):
1571+
'''
1572+
Create a PayPal Account.
1573+
1574+
:param userToken:
1575+
A token identifying the User. **REQUIRED**
1576+
:param data:
1577+
A dictionary containing PayPal Account information. **REQUIRED**
1578+
:returns:
1579+
A PayPal Account.
1580+
'''
1581+
1582+
if not userToken:
1583+
raise HyperwalletException('userToken is required')
1584+
1585+
if not data:
1586+
raise HyperwalletException('data is required')
1587+
1588+
if not('transferMethodCountry' in data) or not(data['transferMethodCountry']):
1589+
raise HyperwalletException('transferMethodCountry is required')
1590+
1591+
if not('transferMethodCurrency' in data) or not(data['transferMethodCurrency']):
1592+
raise HyperwalletException('transferMethodCurrency is required')
1593+
1594+
if not('email' in data) or not(data['email']):
1595+
raise HyperwalletException('email is required')
1596+
1597+
response = self.apiClient.doPost(
1598+
os.path.join('users', userToken, 'paypal-accounts'),
1599+
data
1600+
)
1601+
1602+
return PayPalAccount(response)
1603+
1604+
def getPayPalAccount(self,
1605+
userToken=None,
1606+
payPalAccountToken=None):
1607+
'''
1608+
Retrieve a PayPal Account.
1609+
1610+
:param userToken:
1611+
A token identifying the User. **REQUIRED**
1612+
:param payPalAccountToken:
1613+
A token identifying the PayPal Account. **REQUIRED**
1614+
:returns:
1615+
A PayPal Account.
1616+
'''
1617+
1618+
if not userToken:
1619+
raise HyperwalletException('userToken is required')
1620+
1621+
if not payPalAccountToken:
1622+
raise HyperwalletException('payPalAccountToken is required')
1623+
1624+
response = self.apiClient.doGet(
1625+
os.path.join(
1626+
'users',
1627+
userToken,
1628+
'paypal-accounts',
1629+
payPalAccountToken
1630+
)
1631+
)
1632+
1633+
return PayPalAccount(response)
1634+
1635+
def listPayPalAccounts(self,
1636+
userToken=None,
1637+
params=None):
1638+
'''
1639+
List PayPal Accounts.
1640+
1641+
:param userToken:
1642+
A token identifying the User. **REQUIRED**
1643+
:param params:
1644+
A dictionary containing query parameters.
1645+
:returns:
1646+
An array of PayPal Accounts.
1647+
'''
1648+
1649+
if not userToken:
1650+
raise HyperwalletException('userToken is required')
1651+
1652+
response = self.apiClient.doGet(
1653+
os.path.join('users', userToken, 'paypal-accounts'),
1654+
params
1655+
)
1656+
1657+
return [PayPalAccount(x) for x in response.get('data', [])]
1658+
1659+
'''
1660+
15631661
Payments
15641662
https://portal.hyperwallet.com/docs/api/v3/resources/payments
15651663

hyperwallet/models.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,33 @@ def __repr__(self):
406406
token=self.token
407407
)
408408

409+
class PayPalAccount(TransferMethod):
410+
'''
411+
The PayPalAccount Model.
412+
413+
:param data:
414+
A dictionary containing the attributes for the PayPal Account.
415+
'''
416+
417+
def __init__(self, data):
418+
'''
419+
Create a new PayPal Account with the provided attributes.
420+
'''
421+
422+
super(PayPalAccount, self).__init__(data)
423+
424+
self.defaults = {
425+
'email': None
426+
}
427+
428+
for (param, default) in self.defaults.items():
429+
setattr(self, param, data.get(param, default))
430+
431+
def __repr__(self):
432+
return "PayPalAccount({date}, {token})".format(
433+
date=self.createdOn,
434+
token=self.token
435+
)
409436

410437
class Payment(HyperwalletModel):
411438
'''

hyperwallet/tests/test_api.py

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,6 +1262,110 @@ def test_create_transfer_status_transition_success(self, mock_post):
12621262

12631263
'''
12641264
1265+
PayPal Accounts
1266+
1267+
'''
1268+
1269+
def test_create_paypal_account_fail_need_user_token(self):
1270+
1271+
with self.assertRaises(HyperwalletException) as exc:
1272+
self.api.createPayPalAccount()
1273+
1274+
self.assertEqual(exc.exception.message, 'userToken is required')
1275+
1276+
def test_create_paypal_account_fail_need_data(self):
1277+
1278+
with self.assertRaises(HyperwalletException) as exc:
1279+
self.api.createPayPalAccount('token')
1280+
1281+
self.assertEqual(exc.exception.message, 'data is required')
1282+
1283+
def test_create_paypal_account_fail_need_transfer_method_country(self):
1284+
1285+
paypal_account_data = {
1286+
'token': 'test-token'
1287+
}
1288+
with self.assertRaises(HyperwalletException) as exc:
1289+
self.api.createPayPalAccount('token', paypal_account_data)
1290+
1291+
self.assertEqual(exc.exception.message, 'transferMethodCountry is required')
1292+
1293+
def test_create_paypal_account_fail_need_transfer_method_currency(self):
1294+
1295+
paypal_account_data = {
1296+
'transferMethodCountry': 'test-transfer-method-country'
1297+
}
1298+
with self.assertRaises(HyperwalletException) as exc:
1299+
self.api.createPayPalAccount('token', paypal_account_data)
1300+
1301+
self.assertEqual(exc.exception.message, 'transferMethodCurrency is required')
1302+
1303+
def test_create_paypal_account_fail_need_email(self):
1304+
1305+
paypal_account_data = {
1306+
'transferMethodCountry': 'test-transfer-method-country',
1307+
'transferMethodCurrency': 'test-transfer-method-currency'
1308+
}
1309+
with self.assertRaises(HyperwalletException) as exc:
1310+
self.api.createPayPalAccount('token', paypal_account_data)
1311+
1312+
self.assertEqual(exc.exception.message, 'email is required')
1313+
1314+
@mock.patch('hyperwallet.utils.ApiClient._makeRequest')
1315+
def test_create_paypal_account_success(self, mock_post):
1316+
1317+
paypal_account_data = {
1318+
'transferMethodCountry': 'test-transfer-method-country',
1319+
'transferMethodCurrency': 'test-transfer-method-currency',
1320+
'email': 'test-email'
1321+
}
1322+
mock_post.return_value = paypal_account_data
1323+
response = self.api.createPayPalAccount('token', paypal_account_data)
1324+
1325+
self.assertTrue(response.email, paypal_account_data.get('token'))
1326+
1327+
def test_get_paypal_account_fail_need_user_token(self):
1328+
1329+
with self.assertRaises(HyperwalletException) as exc:
1330+
self.api.getPayPalAccount()
1331+
1332+
self.assertEqual(exc.exception.message, 'userToken is required')
1333+
1334+
def test_get_paypal_account_fail_need_paypal_account_token(self):
1335+
1336+
with self.assertRaises(HyperwalletException) as exc:
1337+
self.api.getPayPalAccount('token')
1338+
1339+
self.assertEqual(exc.exception.message, 'payPalAccountToken is required')
1340+
1341+
@mock.patch('hyperwallet.utils.ApiClient._makeRequest')
1342+
def test_get_paypal_account_success(self, mock_get):
1343+
1344+
paypal_account_data = {
1345+
'email': 'test-email'
1346+
}
1347+
mock_get.return_value = paypal_account_data
1348+
response = self.api.getPayPalAccount('token', 'token')
1349+
1350+
self.assertTrue(response.email, paypal_account_data.get('email'))
1351+
1352+
def test_list_paypal_accounts_fail_need_user_token(self):
1353+
1354+
with self.assertRaises(HyperwalletException) as exc:
1355+
self.api.listPayPalAccounts()
1356+
1357+
self.assertEqual(exc.exception.message, 'userToken is required')
1358+
1359+
@mock.patch('hyperwallet.utils.ApiClient._makeRequest')
1360+
def test_list_paypal_accounts_success(self, mock_get):
1361+
1362+
mock_get.return_value = {'data': [self.data]}
1363+
response = self.api.listPayPalAccounts('token')
1364+
1365+
self.assertTrue(response[0].token, self.data.get('token'))
1366+
1367+
'''
1368+
12651369
Payments
12661370
12671371
'''

hyperwallet/tests/test_models.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
PrepaidCard,
1313
PaperCheck,
1414
Transfer,
15+
PayPalAccount,
1516
Payment,
1617
Balance,
1718
Receipt,
@@ -242,6 +243,24 @@ def test_transfer_model(self):
242243

243244
'''
244245
246+
PayPal Account
247+
248+
'''
249+
250+
def test_paypal_account_model(self):
251+
252+
test_paypal_account = PayPalAccount(self.transfer_method_data)
253+
254+
self.assertEqual(
255+
test_paypal_account.__repr__(),
256+
'PayPalAccount({date}, {token})'.format(
257+
date=self.transfer_method_data.get('createdOn'),
258+
token=self.transfer_method_data.get('token')
259+
)
260+
)
261+
262+
'''
263+
245264
Payment
246265
247266
'''

0 commit comments

Comments
 (0)