Skip to content

Commit 57d1c09

Browse files
author
Markus Amalthea Magnuson
committed
Add support for Venmo.
Fixes #32.
1 parent 2b46dfd commit 57d1c09

5 files changed

Lines changed: 554 additions & 0 deletions

File tree

hyperwallet/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
Transfer, # noqa
2424
AuthenticationToken, # noqa
2525
PayPalAccount, # noqa
26+
VenmoAccount, # noqa
2627
Payment, # noqa
2728
Balance, # noqa
2829
Receipt, # noqa

hyperwallet/api.py

Lines changed: 259 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
Transfer,
1515
AuthenticationToken,
1616
PayPalAccount,
17+
VenmoAccount,
1718
Payment,
1819
Balance,
1920
Receipt,
@@ -1745,6 +1746,264 @@ def deactivatePayPalAccount(self,
17451746

17461747
'''
17471748
1749+
Venmo Accounts
1750+
1751+
'''
1752+
1753+
def createVenmoAccount(self,
1754+
userToken=None,
1755+
data=None):
1756+
'''
1757+
Create a Venmo Account.
1758+
:param userToken:
1759+
A token identifying the User. **REQUIRED**
1760+
:param data:
1761+
A dictionary containing Venmo Account information. **REQUIRED**
1762+
:returns:
1763+
A Venmo Account.
1764+
'''
1765+
1766+
if not userToken:
1767+
raise HyperwalletException('userToken is required')
1768+
1769+
if not data:
1770+
raise HyperwalletException('data is required')
1771+
1772+
if not ('transferMethodCountry' in data) or not (data['transferMethodCountry']):
1773+
raise HyperwalletException('transferMethodCountry is required')
1774+
1775+
if not ('transferMethodCurrency' in data) or not (data['transferMethodCurrency']):
1776+
raise HyperwalletException('transferMethodCurrency is required')
1777+
1778+
if not ('accountId' in data) or not (data['accountId']):
1779+
raise HyperwalletException('accountId is required')
1780+
1781+
response = self.apiClient.doPost(
1782+
self.__buildUrl('users', userToken, 'venmo-accounts'),
1783+
data
1784+
)
1785+
1786+
return VenmoAccount(response)
1787+
1788+
def updateVenmoAccount(self,
1789+
userToken=None,
1790+
venmoAccountToken=None,
1791+
data=None):
1792+
'''
1793+
Update a Venmo Account.
1794+
1795+
:param userToken:
1796+
A token identifying the User. **REQUIRED**
1797+
:param VenmoAccountToken:
1798+
A token identifying the Venmo Account. **REQUIRED**
1799+
:param data:
1800+
A dictionary containing Venmo Account information. **REQUIRED**
1801+
:returns:
1802+
A Venmo Account.
1803+
'''
1804+
1805+
body = self.__updateTransferMethod(userToken, venmoAccountToken, 'venmo-accounts', data)
1806+
return VenmoAccount(body)
1807+
1808+
def getVenmoAccount(self,
1809+
userToken=None,
1810+
venmoAccountToken=None):
1811+
'''
1812+
Retrieve a Venmo Account.
1813+
:param userToken:
1814+
A token identifying the User. **REQUIRED**
1815+
:param VenmoAccountToken:
1816+
A token identifying the Venmo Account. **REQUIRED**
1817+
:returns:
1818+
A Venmo Account.
1819+
'''
1820+
1821+
if not userToken:
1822+
raise HyperwalletException('userToken is required')
1823+
1824+
if not venmoAccountToken:
1825+
raise HyperwalletException('venmoAccountToken is required')
1826+
1827+
response = self.apiClient.doGet(
1828+
self.__buildUrl(
1829+
'users',
1830+
userToken,
1831+
'venmo-accounts',
1832+
venmoAccountToken
1833+
)
1834+
)
1835+
1836+
return VenmoAccount(response)
1837+
1838+
def listVenmoAccounts(self,
1839+
userToken=None,
1840+
params=None):
1841+
'''
1842+
List Venmo Accounts.
1843+
:param userToken:
1844+
A token identifying the User. **REQUIRED**
1845+
:param params:
1846+
A dictionary containing query parameters.
1847+
:returns:
1848+
An array of Venmo Accounts.
1849+
'''
1850+
1851+
if not userToken:
1852+
raise HyperwalletException('userToken is required')
1853+
1854+
response = self.apiClient.doGet(
1855+
self.__buildUrl('users', userToken, 'venmo-accounts'),
1856+
params
1857+
)
1858+
1859+
return [VenmoAccount(x) for x in response.get('data', [])]
1860+
1861+
def createVenmoAccountStatusTransition(self,
1862+
userToken=None,
1863+
venmoAccountToken=None,
1864+
data=None):
1865+
'''
1866+
Create a Venmo Account Status Transition.
1867+
1868+
:param userToken:
1869+
A token identifying the User. **REQUIRED**
1870+
:param VenmoAccountToken:
1871+
A token identifying the Venmo Account. **REQUIRED**
1872+
:param data:
1873+
A dictionary containing Venmo Account Status Transition information. **REQUIRED**
1874+
:returns:
1875+
A Venmo Account Status Transition.
1876+
'''
1877+
1878+
if not userToken:
1879+
raise HyperwalletException('userToken is required')
1880+
1881+
if not venmoAccountToken:
1882+
raise HyperwalletException('venmoAccountToken is required')
1883+
1884+
if not data:
1885+
raise HyperwalletException('data is required')
1886+
1887+
response = self.apiClient.doPost(
1888+
self.__buildUrl(
1889+
'users',
1890+
userToken,
1891+
'venmo-accounts',
1892+
venmoAccountToken,
1893+
'status-transitions'
1894+
),
1895+
data
1896+
)
1897+
1898+
return StatusTransition(response)
1899+
1900+
def getVenmoAccountStatusTransition(self,
1901+
userToken=None,
1902+
venmoAccountToken=None,
1903+
statusTransitionToken=None):
1904+
'''
1905+
Retrieve a Venmo Account Status Transition.
1906+
1907+
:param userToken:
1908+
A token identifying the User. **REQUIRED**
1909+
:param VenmoAccountToken:
1910+
A token identifying the Venmo Account. **REQUIRED**
1911+
:param statusTransitionToken:
1912+
A token identifying the Venmo Account Status Transition. **REQUIRED**
1913+
:returns:
1914+
A Venmo Account Status Transition.
1915+
'''
1916+
1917+
if not userToken:
1918+
raise HyperwalletException('userToken is required')
1919+
1920+
if not venmoAccountToken:
1921+
raise HyperwalletException('venmoAccountToken is required')
1922+
1923+
if not statusTransitionToken:
1924+
raise HyperwalletException('statusTransitionToken is required')
1925+
1926+
response = self.apiClient.doGet(
1927+
self.__buildUrl(
1928+
'users',
1929+
userToken,
1930+
'venmo-accounts',
1931+
venmoAccountToken,
1932+
'status-transitions',
1933+
statusTransitionToken
1934+
)
1935+
)
1936+
1937+
return StatusTransition(response)
1938+
1939+
def listVenmoAccountStatusTransitions(self,
1940+
userToken=None,
1941+
venmoAccountToken=None,
1942+
params=None):
1943+
'''
1944+
List Venmo Account Status Transitions.
1945+
1946+
:param userToken:
1947+
A token identifying the User. **REQUIRED**
1948+
:param venmoAccountToken:
1949+
A token identifying the Venmo Account. **REQUIRED**
1950+
:param params:
1951+
A dictionary containing query parameters.
1952+
:returns:
1953+
An array of Venmo Account Status Transitions.
1954+
'''
1955+
1956+
if not userToken:
1957+
raise HyperwalletException('userToken is required')
1958+
1959+
if not venmoAccountToken:
1960+
raise HyperwalletException('venmoAccountToken is required')
1961+
1962+
response = self.apiClient.doGet(
1963+
self.__buildUrl(
1964+
'users',
1965+
userToken,
1966+
'venmo-accounts',
1967+
venmoAccountToken,
1968+
'status-transitions'
1969+
),
1970+
params
1971+
)
1972+
1973+
return [StatusTransition(x) for x in response.get('data', [])]
1974+
1975+
def deactivateVenmoAccount(self,
1976+
userToken=None,
1977+
venmoAccountToken=None,
1978+
notes=None):
1979+
'''
1980+
Deactivate a Venmo Account.
1981+
1982+
:param userToken:
1983+
A token identifying the User. **REQUIRED**
1984+
:param venmoAccountToken:
1985+
A token identifying the Venmo Account. **REQUIRED**
1986+
:param notes:
1987+
A string describing the deactivation.
1988+
:returns:
1989+
A Venmo Account Status Transition.
1990+
'''
1991+
1992+
data = {
1993+
'transition': 'DE_ACTIVATED'
1994+
}
1995+
1996+
if type(notes) is str:
1997+
data.update({'notes': notes})
1998+
1999+
return self.createVenmoAccountStatusTransition(
2000+
userToken,
2001+
venmoAccountToken,
2002+
data
2003+
)
2004+
2005+
'''
2006+
17482007
AuthenticationToken
17492008
17502009
'''

hyperwallet/models.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,35 @@ def __repr__(self):
466466
)
467467

468468

469+
class VenmoAccount(TransferMethod):
470+
'''
471+
The VenmoAccount Model.
472+
473+
:param data:
474+
A dictionary containing the attributes for the Venmo Account.
475+
'''
476+
477+
def __init__(self, data):
478+
'''
479+
Create a new Venmo Account with the provided attributes.
480+
'''
481+
482+
super(VenmoAccount, self).__init__(data)
483+
484+
self.defaults = {
485+
'accountId': None
486+
}
487+
488+
for (param, default) in self.defaults.items():
489+
setattr(self, param, data.get(param, default))
490+
491+
def __repr__(self):
492+
return "VenmoAccount({date}, {token})".format(
493+
date=self.createdOn,
494+
token=self.token
495+
)
496+
497+
469498
class Payment(HyperwalletModel):
470499
'''
471500
The Payment Model.

0 commit comments

Comments
 (0)