Skip to content

Commit f5ad21f

Browse files
Added Hook entity type to allow management of URL notifications;
Modified BankAccount handling and added five new types of bank accounts (IBAN, GB, US, CA and OTHER); Minor changes related to code cleanup.
1 parent 95132f7 commit f5ad21f

21 files changed

+472
-29
lines changed

mangopay2-python-sdk.pyproj

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@
2828
<Compile Include="mangopaysdk\entities\bankaccount.py">
2929
<SubType>Code</SubType>
3030
</Compile>
31-
<Compile Include="mangopaysdk\entities\aaaabankwire.py" />
3231
<Compile Include="mangopaysdk\entities\card.py" />
3332
<Compile Include="mangopaysdk\entities\cardpreauthorization.py" />
3433
<Compile Include="mangopaysdk\entities\cardregistration.py" />
34+
<Compile Include="mangopaysdk\entities\hook.py" />
3535
<Compile Include="mangopaysdk\entities\kycpage.py" />
3636
<Compile Include="mangopaysdk\entities\kycdocument.py" />
3737
<Compile Include="mangopaysdk\entities\event.py" />
@@ -45,6 +45,7 @@
4545
<Compile Include="mangopaysdk\tools\apicards.py" />
4646
<Compile Include="mangopaysdk\tools\apicardregistrations.py" />
4747
<Compile Include="mangopaysdk\tools\apievents.py" />
48+
<Compile Include="mangopaysdk\tools\apihooks.py" />
4849
<Compile Include="mangopaysdk\tools\storages\authorizationtokenmanager.py">
4950
<SubType>Code</SubType>
5051
</Compile>
@@ -58,6 +59,12 @@
5859
<Compile Include="mangopaysdk\tools\storages\__init__.py">
5960
<SubType>Code</SubType>
6061
</Compile>
62+
<Compile Include="mangopaysdk\types\bankaccountdetails.py" />
63+
<Compile Include="mangopaysdk\types\bankaccountdetailsca.py" />
64+
<Compile Include="mangopaysdk\types\bankaccountdetailsgb.py" />
65+
<Compile Include="mangopaysdk\types\bankaccountdetailsiban.py" />
66+
<Compile Include="mangopaysdk\types\bankaccountdetailsother.py" />
67+
<Compile Include="mangopaysdk\types\bankaccountdetailsus.py" />
6168
<Compile Include="mangopaysdk\types\payinexecutiondetailsdirect.py" />
6269
<Compile Include="mangopaysdk\types\payinpaymentdetailsdirectcard.py" />
6370
<Compile Include="mangopaysdk\entities\refund.py" />
@@ -176,6 +183,7 @@
176183
<Compile Include="setup.py" />
177184
<Compile Include="tests\testcardpreauthorizations.py" />
178185
<Compile Include="tests\testevents.py" />
186+
<Compile Include="tests\testhooks.py" />
179187
<Compile Include="tests\testrefunds.py">
180188
<SubType>Code</SubType>
181189
</Compile>

mangopaysdk/entities/bankaccount.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,30 @@ class BankAccount(EntityBase):
77
def __init__(self, id = None):
88
self.UserId = None
99
# Type of bank account
10-
self.Type = 'IBAN'
10+
self.Type = None
1111
self.OwnerName = None
1212
self.OwnerAddress = None
1313
# must be valid ^[a-zA-Z]{2}\d{2}\s*(\w{4}\s*){2,7}\w{1,4}
14-
self.IBAN = None
14+
#self.IBAN = None
15+
self.Details = None
1516
# example BREXPLPWKRA
16-
self.BIC = None
17+
#self.BIC = None
1718
return super(BankAccount, self).__init__(id)
1819

1920
def GetReadOnlyProperties(self):
2021
properties = super(BankAccount, self).GetReadOnlyProperties()
21-
properties.append('UserId' )
22-
return properties
22+
properties.append('UserId')
23+
properties.append('Type')
24+
return properties
25+
26+
def GetDependsObjects(self):
27+
return {
28+
'Type': {
29+
'_property_name': 'Details',
30+
'IBAN': 'BankAccountDetailsIBAN',
31+
'GB': 'BankAccountDetailsGB',
32+
'US': 'BankAccountDetailsUS',
33+
'CA': 'BankAccountDetailsCA',
34+
'OTHER': 'BankAccountDetailsOTHER'
35+
}
36+
}

mangopaysdk/entities/hook.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from mangopaysdk.entities.entitybase import EntityBase
2+
3+
class Hook(EntityBase):
4+
"""Hooks and Notifications entity."""
5+
6+
def __init__(self, id = None):
7+
self.Url = None
8+
self.Status = None
9+
self.Validity = None
10+
self.EventType = None
11+
return super(Hook, self).__init__(id)

mangopaysdk/mangopayapi.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from mangopaysdk.tools import apioauth, apiclients, apiusers, apiwallets, apitransfers, apipayins, apipayouts, apievents, apicardpreauthorizations
2-
from mangopaysdk.tools import apirefunds, apicardregistrations, apicards
2+
from mangopaysdk.tools import apirefunds, apicardregistrations, apicards, apihooks
33
from mangopaysdk.configuration import Configuration
44
from mangopaysdk.tools.storages.authorizationtokenmanager import AuthorizationTokenManager
55

@@ -36,4 +36,5 @@ def __init__(self):
3636
self.cardRegistrations = apicardregistrations.ApiCardRegistrations(self)
3737
self.cardPreAuthorizations = apicardpreauthorizations.ApiCardPreAuthorizations(self)
3838
self.cards = apicards.ApiCards(self)
39-
self.events = apievents.ApiEvents(self)
39+
self.events = apievents.ApiEvents(self)
40+
self.hooks = apihooks.ApiHooks(self)

mangopaysdk/tools/apibase.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from mangopaysdk.types.dto import Dto
44
from mangopaysdk.types.money import Money
55
import json, inspect
6+
from mangopaysdk.tools.resttool import RestTool
67
from mangopaysdk.entities.event import Event
78
from mangopaysdk.entities.kycdocument import KycDocument
89
from mangopaysdk.entities.kycpage import KycPage
@@ -20,6 +21,7 @@
2021
from mangopaysdk.entities.refund import Refund
2122
from mangopaysdk.entities.cardregistration import CardRegistration
2223
from mangopaysdk.entities.cardpreauthorization import CardPreAuthorization
24+
from mangopaysdk.entities.hook import Hook
2325
from mangopaysdk.types.payinexecutiondetails import PayInExecutionDetails
2426
from mangopaysdk.types.payinexecutiondetailsweb import PayInExecutionDetailsWeb
2527
from mangopaysdk.types.payinpaymentdetails import PayInPaymentDetails
@@ -29,7 +31,11 @@
2931
from mangopaysdk.types.payoutpaymentdetails import PayOutPaymentDetails
3032
from mangopaysdk.types.payinexecutiondetailsdirect import PayInExecutionDetailsDirect
3133
from mangopaysdk.types.payoutpaymentdetailsbankwire import PayOutPaymentDetailsBankWire
32-
from mangopaysdk.tools.resttool import RestTool
34+
from mangopaysdk.types.bankaccountdetailsiban import BankAccountDetailsIBAN
35+
from mangopaysdk.types.bankaccountdetailsgb import BankAccountDetailsGB
36+
from mangopaysdk.types.bankaccountdetailsus import BankAccountDetailsUS
37+
from mangopaysdk.types.bankaccountdetailsca import BankAccountDetailsCA
38+
from mangopaysdk.types.bankaccountdetailsother import BankAccountDetailsOTHER
3339

3440

3541
class ApiBase(object):
@@ -124,7 +130,12 @@ class ApiBase(object):
124130
'users_getkycdocument' : ('/users/%s/KYC/documents/%s', 'GET'),
125131
'users_savekycdocument' : ('/users/%s/KYC/documents/%s', 'PUT'),
126132

127-
'users_createbankaccounts' : ('/users/%s/bankaccounts', 'POST'),
133+
'users_createbankaccounts_iban': ('/users/%s/bankaccounts/iban', 'POST'),
134+
'users_createbankaccounts_gb': ('/users/%s/bankaccounts/gb', 'POST'),
135+
'users_createbankaccounts_us': ('/users/%s/bankaccounts/us', 'POST'),
136+
'users_createbankaccounts_ca': ('/users/%s/bankaccounts/ca', 'POST'),
137+
'users_createbankaccounts_other': ('/users/%s/bankaccounts/other', 'POST'),
138+
128139
'users_all' : ('/users', 'GET'),
129140
'users_allkyc' : ('/users/%s/KYC', 'GET'),
130141
'users_allkycrequests' : ('/users/%s/KYC/requests', 'GET'),
@@ -355,4 +366,6 @@ def _canReadSubRequestData (self, entity, propertyName):
355366
return True
356367
if isinstance(entity, PayOut) and propertyName == 'MeanOfPaymentDetails':
357368
return True
369+
if isinstance(entity, BankAccount) and propertyName == 'Details':
370+
return True
358371
return False

mangopaysdk/tools/apihooks.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from mangopaysdk.tools.apibase import ApiBase
2+
3+
class ApiHooks(ApiBase):
4+
"""MangoPay API for hooks and notifications."""
5+
6+
def Create(self, hook):
7+
"""Creates a new hook.
8+
param Hook hook
9+
return Newly created hook object returned from API
10+
"""
11+
return self._createObject('hooks_create', hook, 'Hook')
12+
13+
def Get(self, hookId):
14+
"""Gets hook.
15+
param type hookId Hook identifier
16+
return Hook object returned from API
17+
"""
18+
return self._getObject('hooks_get', hookId, 'Hook')
19+
20+
def Update(self, hook):
21+
"""Updates a hook.
22+
param Hook hook Hook object to update
23+
return Updated hook object returned from API
24+
"""
25+
return self._saveObject('hooks_save', hook, 'Hook')
26+
27+
def GetAll(self, pagination = None):
28+
"""Gets all hooks.
29+
return Array of objects returned from API
30+
"""
31+
return self._getList('hooks_all', pagination, 'Hook')

mangopaysdk/tools/apiusers.py

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
from mangopaysdk.entities.bankaccount import BankAccount
66
from mangopaysdk.entities.kycdocument import KycDocument
77
from mangopaysdk.entities.kycpage import KycPage
8+
import collections
9+
import os.path
810

911

1012
class ApiUsers(ApiBase):
@@ -78,7 +80,8 @@ def CreateBankAccount(self, userId, bankAccount):
7880
param BankAccount Entity of bank account with fields: OwnerName, UserId, Type, OwnerAddress,IBAN, BIC, Tag
7981
return BankAccount Create bank account object
8082
"""
81-
return self._createObject('users_createbankaccounts', bankAccount, 'BankAccount', userId)
83+
type = self.GetBankAccountType(bankAccount)
84+
return self._createObject('users_createbankaccounts_' + type, bankAccount, 'BankAccount', userId)
8285

8386
def GetBankAccounts(self, userId, pagination = None):
8487
"""Get all bank accounts for user.
@@ -149,7 +152,7 @@ def CreateUserKycPage(self, kycPage, userId, kycDocumentId):
149152
param Int/GUID User identifier
150153
param Int/GUID KycDocument identifier
151154
"""
152-
self._createObject('users_createkycpage', kycPage, None, userId, kycDocumentId)
155+
return self._createObject('users_createkycpage', kycPage, None, userId, kycDocumentId)
153156

154157
def UpdateUserKycDocument(self, kycDocument, userId, kycDocumentId):
155158
"""Updates KycDocument
@@ -158,4 +161,40 @@ def UpdateUserKycDocument(self, kycDocument, userId, kycDocumentId):
158161
param Int/GUID KycDocument identifier
159162
return KycDocument from API with fileds: Id, Tag, CreationDate, Type, Status, RefusedReasonType, RefusedReasonMessage
160163
"""
161-
return self._saveObject('users_savekycdocument', kycDocument, 'KycDocument', userId, kycDocument.Id)
164+
return self._saveObject('users_savekycdocument', kycDocument, 'KycDocument', userId, kycDocument.Id)
165+
166+
def CreateKycPageFromFile(self, userId, kycDocumentId, file):
167+
"""Create page for Kyc document from file
168+
param int userId User identifier
169+
param KycPage page Kyc
170+
"""
171+
172+
filePath = file
173+
#if (isinstance(file, collections.Sequence)):
174+
# filePath = file['tmp_name']
175+
176+
if (filePath == None or filePath == ''):
177+
raise Exception('Path of file cannot be empty')
178+
179+
if (not os.path.isfile(filePath)):
180+
raise Exception('File not exist')
181+
182+
kycPage = KycPage()
183+
with open(filePath) as f:
184+
encoded = base64.encodestring(f.read())
185+
kycPage.File = encoded
186+
187+
if (kycPage.File == None):
188+
raise Exception('Content of the file cannot be empty')
189+
190+
self.CreateUserKycPage(kycPage, userId, kycDocumentId)
191+
192+
def GetBankAccountType(self, bankAccount):
193+
194+
if (bankAccount.Details == None):
195+
raise Exception('Details is not defined or it is not object type')
196+
197+
className = bankAccount.Details.__class__.__name__.replace('BankAccountDetails', '').lower()
198+
199+
return className
200+

mangopaysdk/tools/enums.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ class RequestType:
66

77

88
class PersonType:
9-
Natural = 'NATURAL';
9+
Natural = 'NATURAL'
1010
Legal = 'LEGAL'
1111

1212

1313
class LegalPersonType:
14-
BUSINESS = 'BUSINESS';
14+
BUSINESS = 'BUSINESS'
1515
ORGANIZATION = 'ORGANIZATION'
1616

1717

mangopaysdk/tools/resttool.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from mangopaysdk.tools.authenticationHelper import AuthenticationHelper
33
from mangopaysdk.tools.urltool import UrlTool
44
from mangopaysdk.types.exceptions.responseexception import ResponseException
5+
import sys
56

67

78
class RestTool:
@@ -85,8 +86,27 @@ def _runRequest(self, urlMethod, pagination, additionalUrlParams):
8586

8687
# load pagination info
8788
if not pagination == None:
88-
pagination.TotalPages = int(response.headers['x-number-of-pages'])
89-
pagination.TotalItems = int(response.headers['x-number-of-items'])
89+
if ('x-number-of-pages' in response.headers.keys()):
90+
pagination.TotalPages = int(response.headers['x-number-of-pages'])
91+
if ('x-number-of-items' in response.headers.keys()):
92+
pagination.TotalItems = int(response.headers['x-number-of-items'])
93+
94+
#try:
95+
# if not pagination == None:
96+
# pagination.TotalPages = int(response.headers['x-number-of-pages'])
97+
#except:
98+
# pagination.TotalPages = 1
99+
# if self._debugMode:
100+
# logging.getLogger(__name__).debug(sys.exc_info()[0])
101+
#else:
102+
# try:
103+
# if not pagination == None:
104+
# pagination.TotalItems = int(response.headers['x-number-of-items'])
105+
# except:
106+
# pagination.TotalItems = 0
107+
# if self._debugMode:
108+
# logging.getLogger(__name__).debug(sys.exc_info()[0])
109+
90110

91111
# this can hit create connection performance
92112
# response.connection.close()
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from mangopaysdk.types.dto import Dto
2+
3+
class BankAccountDetails(Dto):
4+
pass
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from mangopaysdk.types.bankaccountdetails import BankAccountDetails
2+
3+
4+
class BankAccountDetailsCA(BankAccountDetails):
5+
"""CA bank account type for BankAccount entity."""
6+
7+
def __init__(self):
8+
self.BankName = None
9+
"""Bank name"""
10+
11+
self.InstitutionNumber = None
12+
"""Institution number"""
13+
14+
self.BranchCode = None
15+
"""Branch code"""
16+
17+
self.AccountNumber = None
18+
"""Account number"""
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from mangopaysdk.types.bankaccountdetails import BankAccountDetails
2+
3+
4+
class BankAccountDetailsGB(BankAccountDetails):
5+
"""GB bank account type for BankAccount entity."""
6+
7+
def __init__(self):
8+
self.AccountNumber = None
9+
"""Account number"""
10+
11+
self.SortCode = None
12+
"""Sort code"""
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from mangopaysdk.types.bankaccountdetails import BankAccountDetails
2+
3+
4+
class BankAccountDetailsIBAN(BankAccountDetails):
5+
"""IBAN bank account type for BankAccount entity."""
6+
7+
def __init__(self):
8+
self.IBAN = None
9+
"""IBAN number"""
10+
11+
self.BIC = None
12+
"""BIC"""
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from mangopaysdk.types.bankaccountdetails import BankAccountDetails
2+
3+
4+
class BankAccountDetailsOTHER(BankAccountDetails):
5+
"""OTHER bank account type for BankAccount entity."""
6+
7+
def __init__(self):
8+
self.Type = None
9+
"""Type"""
10+
11+
self.Country = None
12+
"""The Country associate to the BankAccount,
13+
ISO 3166-1 alpha-2 format is expected"""
14+
15+
self.BIC = None
16+
"""Valid BIC format"""
17+
18+
self.AccountNumber = None
19+
"""Account number"""
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from mangopaysdk.types.bankaccountdetails import BankAccountDetails
2+
3+
4+
class BankAccountDetailsUS(BankAccountDetails):
5+
"""GB bank account type for BankAccount entity."""
6+
7+
def __init__(self):
8+
self.AccountNumber = None
9+
"""Account number"""
10+
11+
self.ABA = None
12+
"""ABA"""

0 commit comments

Comments
 (0)