Skip to content

Commit 3aaebb7

Browse files
authored
Merge pull request #9 from akreisman-epam/transfers-and-paypal-accounts
Added transfers and paypal accounts endpoints
2 parents 8a26c1d + 7d6dd53 commit 3aaebb7

6 files changed

Lines changed: 526 additions & 4 deletions

File tree

CHANGELOG.rst

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
Changelog
22
=========
33

4-
1.1.3 (current)
4+
1.1.4 (current)
55
------------------
66

7-
- Added Layer 7 encryption for Hyperwallet client
7+
- Added PayPal account endpoint
88

9-
1.1.2 (2018-08-03)
9+
1.1.3 (2018-07-05)
10+
------------------
11+
12+
- Added transfer endpoint
13+
14+
1.1.2 (2018-03-20)
1015
------------------
1116

1217
- Added bank card endpoint

hyperwallet/__init__.py

Lines changed: 3 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.2'
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'
@@ -20,6 +20,8 @@
2020
BankCard, # noqa
2121
PrepaidCard, # noqa
2222
PaperCheck, # noqa
23+
Transfer, # noqa
24+
PayPalAccount, # noqa
2325
Payment, # noqa
2426
Balance, # noqa
2527
Receipt, # noqa

hyperwallet/api.py

Lines changed: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
BankCard,
1414
PrepaidCard,
1515
PaperCheck,
16+
Transfer,
17+
PayPalAccount,
1618
Payment,
1719
Balance,
1820
Receipt,
@@ -1453,6 +1455,205 @@ def deactivatePaperCheck(self,
14531455

14541456
'''
14551457
1458+
Transfers
1459+
https://portal.hyperwallet.com/docs/api/v3/resources/transfers
1460+
1461+
'''
1462+
1463+
def createTransfer(self,
1464+
data=None):
1465+
'''
1466+
Create a Transfer.
1467+
:param data:
1468+
A dictionary containing Transfer information. **REQUIRED**
1469+
:returns:
1470+
A Transfer.
1471+
'''
1472+
1473+
if not data:
1474+
raise HyperwalletException('data is required')
1475+
1476+
if not('sourceToken' in data) or not(data['sourceToken']):
1477+
raise HyperwalletException('sourceToken is required')
1478+
1479+
if not('destinationToken' in data) or not(data['destinationToken']):
1480+
raise HyperwalletException('destinationToken is required')
1481+
1482+
if not('clientTransferId' in data) or not(data['clientTransferId']):
1483+
raise HyperwalletException('clientTransferId is required')
1484+
1485+
response = self.apiClient.doPost(
1486+
os.path.join('transfers'),
1487+
data
1488+
)
1489+
1490+
return Transfer(response)
1491+
1492+
def getTransfer(self,
1493+
transferToken=None):
1494+
'''
1495+
Retrieve a Transfer.
1496+
:param transferToken:
1497+
A token identifying the Transfer. **REQUIRED**
1498+
:returns:
1499+
A Transfer.
1500+
'''
1501+
1502+
if not transferToken:
1503+
raise HyperwalletException('transferToken is required')
1504+
1505+
response = self.apiClient.doGet(
1506+
os.path.join(
1507+
'transfers',
1508+
transferToken
1509+
)
1510+
)
1511+
1512+
return Transfer(response)
1513+
1514+
def listTransfers(self,
1515+
params=None):
1516+
'''
1517+
List Transfers.
1518+
:param params:
1519+
A dictionary containing query parameters.
1520+
:returns:
1521+
An array of Transfers.
1522+
'''
1523+
1524+
response = self.apiClient.doGet(
1525+
os.path.join('transfers'),
1526+
params
1527+
)
1528+
1529+
return [Transfer(x) for x in response.get('data', [])]
1530+
1531+
def createTransferStatusTransition(self,
1532+
transferToken=None,
1533+
data=None):
1534+
'''
1535+
Create a Transfer Status Transition.
1536+
:param transferToken:
1537+
A token identifying the Transfer. **REQUIRED**
1538+
:param data:
1539+
A dictionary containing Transfer Status Transition information. **REQUIRED**
1540+
:returns:
1541+
A Transfer Status Transition.
1542+
'''
1543+
1544+
if not transferToken:
1545+
raise HyperwalletException('transferToken is required')
1546+
1547+
if not data:
1548+
raise HyperwalletException('data is required')
1549+
1550+
response = self.apiClient.doPost(
1551+
os.path.join(
1552+
'transfers',
1553+
transferToken,
1554+
'status-transitions'
1555+
),
1556+
data
1557+
)
1558+
1559+
return StatusTransition(response)
1560+
1561+
'''
1562+
1563+
PayPal Accounts
1564+
1565+
'''
1566+
1567+
def createPayPalAccount(self,
1568+
userToken=None,
1569+
data=None):
1570+
'''
1571+
Create a PayPal Account.
1572+
:param userToken:
1573+
A token identifying the User. **REQUIRED**
1574+
:param data:
1575+
A dictionary containing PayPal Account information. **REQUIRED**
1576+
:returns:
1577+
A PayPal Account.
1578+
'''
1579+
1580+
if not userToken:
1581+
raise HyperwalletException('userToken is required')
1582+
1583+
if not data:
1584+
raise HyperwalletException('data is required')
1585+
1586+
if not('transferMethodCountry' in data) or not(data['transferMethodCountry']):
1587+
raise HyperwalletException('transferMethodCountry is required')
1588+
1589+
if not('transferMethodCurrency' in data) or not(data['transferMethodCurrency']):
1590+
raise HyperwalletException('transferMethodCurrency is required')
1591+
1592+
if not('email' in data) or not(data['email']):
1593+
raise HyperwalletException('email is required')
1594+
1595+
response = self.apiClient.doPost(
1596+
os.path.join('users', userToken, 'paypal-accounts'),
1597+
data
1598+
)
1599+
1600+
return PayPalAccount(response)
1601+
1602+
def getPayPalAccount(self,
1603+
userToken=None,
1604+
payPalAccountToken=None):
1605+
'''
1606+
Retrieve a PayPal Account.
1607+
:param userToken:
1608+
A token identifying the User. **REQUIRED**
1609+
:param payPalAccountToken:
1610+
A token identifying the PayPal Account. **REQUIRED**
1611+
:returns:
1612+
A PayPal Account.
1613+
'''
1614+
1615+
if not userToken:
1616+
raise HyperwalletException('userToken is required')
1617+
1618+
if not payPalAccountToken:
1619+
raise HyperwalletException('payPalAccountToken is required')
1620+
1621+
response = self.apiClient.doGet(
1622+
os.path.join(
1623+
'users',
1624+
userToken,
1625+
'paypal-accounts',
1626+
payPalAccountToken
1627+
)
1628+
)
1629+
1630+
return PayPalAccount(response)
1631+
1632+
def listPayPalAccounts(self,
1633+
userToken=None,
1634+
params=None):
1635+
'''
1636+
List PayPal Accounts.
1637+
:param userToken:
1638+
A token identifying the User. **REQUIRED**
1639+
:param params:
1640+
A dictionary containing query parameters.
1641+
:returns:
1642+
An array of PayPal Accounts.
1643+
'''
1644+
1645+
if not userToken:
1646+
raise HyperwalletException('userToken is required')
1647+
1648+
response = self.apiClient.doGet(
1649+
os.path.join('users', userToken, 'paypal-accounts'),
1650+
params
1651+
)
1652+
1653+
return [PayPalAccount(x) for x in response.get('data', [])]
1654+
1655+
'''
1656+
14561657
Payments
14571658
https://portal.hyperwallet.com/docs/api/v3/resources/payments
14581659

hyperwallet/models.py

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,79 @@ def __repr__(self):
363363
)
364364

365365

366+
class Transfer(HyperwalletModel):
367+
'''
368+
The Transfer Model.
369+
370+
:param data:
371+
A dictionary containing the attributes for the Transfer.
372+
'''
373+
374+
def __init__(self, data):
375+
'''
376+
Create a new Transfer with the provided attributes.
377+
'''
378+
379+
super(Transfer, self).__init__(data)
380+
381+
self.defaults = {
382+
'token': None,
383+
'status': None,
384+
'createdOn': None,
385+
'clientTransferId': None,
386+
'sourceToken': None,
387+
'sourceAmount': None,
388+
'sourceFeeAmount': None,
389+
'sourceCurrency': None,
390+
'destinationToken': None,
391+
'destinationAmount': None,
392+
'destinationFeeAmount': None,
393+
'destinationCurrency': None,
394+
'foreignExchanges': None,
395+
'notes': None,
396+
'memo': None,
397+
'expiresOn': None
398+
}
399+
400+
for (param, default) in self.defaults.items():
401+
setattr(self, param, data.get(param, default))
402+
403+
def __repr__(self):
404+
return "Transfer({date}, {token})".format(
405+
date=self.createdOn,
406+
token=self.token
407+
)
408+
409+
410+
class PayPalAccount(TransferMethod):
411+
'''
412+
The PayPalAccount Model.
413+
414+
:param data:
415+
A dictionary containing the attributes for the PayPal Account.
416+
'''
417+
418+
def __init__(self, data):
419+
'''
420+
Create a new PayPal Account with the provided attributes.
421+
'''
422+
423+
super(PayPalAccount, self).__init__(data)
424+
425+
self.defaults = {
426+
'email': None
427+
}
428+
429+
for (param, default) in self.defaults.items():
430+
setattr(self, param, data.get(param, default))
431+
432+
def __repr__(self):
433+
return "PayPalAccount({date}, {token})".format(
434+
date=self.createdOn,
435+
token=self.token
436+
)
437+
438+
366439
class Payment(HyperwalletModel):
367440
'''
368441
The Payment Model.

0 commit comments

Comments
 (0)