Skip to content

Commit 95132f7

Browse files
author
arek-felinczak
committed
Added: Card pre-authorization (with PayIn), PayInBankWire, get user cards & transactions, new type of documents for KYC
1 parent bbefe7e commit 95132f7

20 files changed

+361
-75
lines changed

mangopay2-python-sdk.pyproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@
2828
<Compile Include="mangopaysdk\entities\bankaccount.py">
2929
<SubType>Code</SubType>
3030
</Compile>
31+
<Compile Include="mangopaysdk\entities\aaaabankwire.py" />
3132
<Compile Include="mangopaysdk\entities\card.py" />
33+
<Compile Include="mangopaysdk\entities\cardpreauthorization.py" />
3234
<Compile Include="mangopaysdk\entities\cardregistration.py" />
3335
<Compile Include="mangopaysdk\entities\kycpage.py" />
3436
<Compile Include="mangopaysdk\entities\kycdocument.py" />
@@ -39,6 +41,7 @@
3941
<Compile Include="mangopaysdk\entities\entitybase.py">
4042
<SubType>Code</SubType>
4143
</Compile>
44+
<Compile Include="mangopaysdk\tools\apicardpreauthorizations.py" />
4245
<Compile Include="mangopaysdk\tools\apicards.py" />
4346
<Compile Include="mangopaysdk\tools\apicardregistrations.py" />
4447
<Compile Include="mangopaysdk\tools\apievents.py" />
@@ -113,9 +116,11 @@
113116
<Compile Include="mangopaysdk\types\payinpaymentdetailscard.py">
114117
<SubType>Code</SubType>
115118
</Compile>
119+
<Compile Include="mangopaysdk\types\payinpaymentdetailspreauthorized.py" />
116120
<Compile Include="mangopaysdk\types\payoutpaymentdetails.py">
117121
<SubType>Code</SubType>
118122
</Compile>
123+
<Compile Include="mangopaysdk\types\payinpaymentdetailsbankwire.py" />
119124
<Compile Include="mangopaysdk\types\payoutpaymentdetailsbankwire.py">
120125
<SubType>Code</SubType>
121126
</Compile>
@@ -169,6 +174,7 @@
169174
<SubType>Code</SubType>
170175
</Compile>
171176
<Compile Include="setup.py" />
177+
<Compile Include="tests\testcardpreauthorizations.py" />
172178
<Compile Include="tests\testevents.py" />
173179
<Compile Include="tests\testrefunds.py">
174180
<SubType>Code</SubType>
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
from mangopaysdk.entities.entitybase import EntityBase
2+
3+
4+
class CardPreAuthorization(EntityBase):
5+
"""CardPreAuthorization entity"""
6+
7+
def __init__(self, id = None):
8+
self.Tag = None
9+
# The user Id of the author of the pre-authorization
10+
self.AuthorId = None
11+
# Money object - amount debited on the bank account of the Author in cents
12+
self.DebitedFunds = None
13+
# Mode3DSType { DEFAULT, FORCE }
14+
self.SecureMode = None
15+
# This is the URL where users are automatically redirected after 3D secure validation (if activated)
16+
self.SecureModeReturnURL = None
17+
# The ID of the registered card (Got through CardRegistration object)
18+
self.CardId = None
19+
# The Id of the associated PayIn
20+
self.PayInId = None
21+
22+
# Boolean. The value is 'true' if the SecureMode was used
23+
self.SecureModeNeeded = None
24+
# This is the URL where users are automatically redirected after 3D secure validation (if activated)
25+
self.SecureModeReturnURL = None
26+
# returned from API
27+
self.SecureModeRedirectURL = None
28+
# CardPreAuthorizationStatus - The status of the payment after the PreAuthorization: WAITING, CANCELED, EXPIRED, VALIDATED
29+
30+
self.PaymentStatus = None
31+
# TransactionStatus: CREATED, SUCCEEDED, FAILED
32+
self.Status = None
33+
self.ResultCode = None
34+
self.ResultMessage = None
35+
# How the PreAuthorization has been executed.
36+
self.ExecutionType = None
37+
# The date when the payment is processed
38+
self.ExpirationDate = None
39+
40+
return super(CardPreAuthorization, self).__init__(id)
41+
42+
def GetReadOnlyProperties(self):
43+
properties = super(CardPreAuthorization, self).GetReadOnlyProperties()
44+
properties.append('ResultMessage')
45+
properties.append('ResultCode')
46+
properties.append('Status')
47+
return properties
48+
49+
def GetSubObjects(self):
50+
return {
51+
'DebitedFunds': 'Money'
52+
}
53+
54+
55+
56+
57+

mangopaysdk/entities/payin.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,19 @@ def __init__(self, id = None):
1414
# One of PayInExecutionDetails implementations, depending on ExecutionType
1515
self.ExecutionDetails = None
1616
return super(PayIn, self).__init__(id)
17-
17+
1818
def GetDependsObjects(self):
1919
return {
20-
'PaymentType': {'_property_name': 'PaymentDetails', 'CARD': 'PayInPaymentDetailsCard'},
21-
'ExecutionType': {
20+
'PaymentType': {
21+
'_property_name': 'PaymentDetails',
22+
'CARD': 'PayInPaymentDetailsCard',
23+
'BANK_WIRE': 'PayInPaymentDetailsBankWire'
24+
}, 'ExecutionType': {
2225
'_property_name': 'ExecutionDetails',
2326
'WEB': 'PayInExecutionDetailsWeb',
2427
'DIRECT': 'PayInExecutionDetailsDirect'
25-
}
26-
}
28+
}
29+
}
2730

2831
def GetReadOnlyProperties(self):
2932
properties = super(PayIn, self).GetReadOnlyProperties()

mangopaysdk/mangopayapi.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from mangopaysdk.tools import apioauth, apiclients, apiusers, apiwallets, apitransfers, apipayins, apipayouts, apievents
1+
from mangopaysdk.tools import apioauth, apiclients, apiusers, apiwallets, apitransfers, apipayins, apipayouts, apievents, apicardpreauthorizations
22
from mangopaysdk.tools import apirefunds, apicardregistrations, apicards
33
from mangopaysdk.configuration import Configuration
44
from mangopaysdk.tools.storages.authorizationtokenmanager import AuthorizationTokenManager
@@ -34,5 +34,6 @@ def __init__(self):
3434
self.payOuts = apipayouts.ApiPayOuts(self)
3535
self.refunds = apirefunds.ApiRefunds(self)
3636
self.cardRegistrations = apicardregistrations.ApiCardRegistrations(self)
37+
self.cardPreAuthorizations = apicardpreauthorizations.ApiCardPreAuthorizations(self)
3738
self.cards = apicards.ApiCards(self)
3839
self.events = apievents.ApiEvents(self)

mangopaysdk/tools/apibase.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,12 @@
1919
from mangopaysdk.entities.card import Card
2020
from mangopaysdk.entities.refund import Refund
2121
from mangopaysdk.entities.cardregistration import CardRegistration
22+
from mangopaysdk.entities.cardpreauthorization import CardPreAuthorization
2223
from mangopaysdk.types.payinexecutiondetails import PayInExecutionDetails
2324
from mangopaysdk.types.payinexecutiondetailsweb import PayInExecutionDetailsWeb
2425
from mangopaysdk.types.payinpaymentdetails import PayInPaymentDetails
26+
from mangopaysdk.types.payinpaymentdetailspreauthorized import PayInPaymentDetailsPreAuthorized
27+
from mangopaysdk.types.payinpaymentdetailsbankwire import PayInPaymentDetailsBankWire
2528
from mangopaysdk.types.payinpaymentdetailscard import PayInPaymentDetailsCard
2629
from mangopaysdk.types.payoutpaymentdetails import PayOutPaymentDetails
2730
from mangopaysdk.types.payinexecutiondetailsdirect import PayInExecutionDetailsDirect
@@ -79,6 +82,8 @@ class ApiBase(object):
7982
'payins_bankwire-preauthorized_create' : ('/payins/bankwire/preauthorized/', 'POST'),
8083
'payins_bankwire-recurrentexecution_create' : ('/payins/bankwire/recurrent-pay-in-execution/', 'POST'),
8184

85+
'payins_preauthorized-direct_create' : ('/payins/PreAuthorized/direct/', 'POST'),
86+
8287
'payins_directcredit-web_create' : ('/payins/direct-credit/web/', 'POST'),
8388
'payins_directcredit-direct_create' : ('/payins/direct-credit/direct/', 'POST'),
8489
'payins_directcredit-preauthorized_create' : ('/payins/direct-credit/preauthorized/', 'POST'),
@@ -93,6 +98,9 @@ class ApiBase(object):
9398
'payouts_get' : ('/payouts/%s', 'GET'),
9499
'payouts_createrefunds' : ('/payouts/%s/refunds', 'POST'),
95100
'payouts_getrefunds' : ('/payouts/%s/refunds', 'GET'),
101+
'preauthorizations_create' : ('/preauthorizations/card/direct', 'POST'),
102+
'preauthorizations_save' : ('/preauthorizations/%s', 'PUT'),
103+
'preauthorizations_get' : ('/preauthorizations/%s', 'GET'),
96104

97105
'reccurringpayinorders_create' : ('/reccurring-pay-in-orders', 'POST'),
98106
'reccurringpayinorders_get' : ('/reccurring-pay-in-orders/%s', 'GET'),
@@ -132,6 +140,8 @@ class ApiBase(object):
132140
'users_getproofofregistration' : ('/users/%s/ProofOfRegistration', 'GET'),
133141
'users_getshareholderdeclaration' : ('/users/%s/ShareholderDeclaration', 'GET'),
134142
'users_getbankaccount' : ('/users/%s/bankaccounts/%s', 'GET'),
143+
'users_getcards' : ('/users/%s/cards', 'GET'),
144+
'users_transactions' : ('/users/%s/transactions', 'GET'),
135145
'users_getpaymentcard' : ('/users/%s/payment-cards/%s', 'GET'),
136146
'users_savenaturals' : ('/users/natural/%s', 'PUT'),
137147
'users_savelegals' : ('/users/legal/%s', 'PUT'),
@@ -274,7 +284,17 @@ def _castResponseToEntity(self, response, entityClassName, asDependentObject = F
274284
objList.append(self._castResponseToEntity(reponseObject, entityClassName))
275285
return objList
276286

277-
if len(entityClassName) > 0:
287+
if len(entityClassName) > 0 and entityClassName == "Transaction" and response['Type'] != None:
288+
if response['Type'] == "PAYIN":
289+
entityClassName = "PayIn"
290+
if response['Type'] == "PAYOUT":
291+
entityClassName = "PayOut"
292+
if response['Type'] == "REFUND":
293+
entityClassName = "Refund"
294+
if response['Type'] == "TRANSFER":
295+
entityClassName = "Transfer"
296+
entity = globals()[entityClassName]()
297+
elif len(entityClassName) > 0 :
278298
entity = globals()[entityClassName]()
279299
else:
280300
raise Exception ('Cannot cast response to entity object. Wrong entity class name')
@@ -286,7 +306,7 @@ def _castResponseToEntity(self, response, entityClassName, asDependentObject = F
286306

287307
if hasattr(entity, name):
288308
# is sub object?
289-
if subObjects.get(name) != None:
309+
if subObjects.get(name) != None and value != None:
290310
object = self._castResponseToEntity(value, subObjects[name])
291311
setattr(entity, name, object)
292312
else:
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from mangopaysdk.tools.apibase import ApiBase
2+
from mangopaysdk.entities.cardpreauthorization import CardPreAuthorization
3+
4+
5+
class ApiCardPreAuthorizations (ApiBase):
6+
"""Class to managemen MangoPay API for card pre-authorization.
7+
see: http://docs.mangopay.com/api-references/card/pre-authorization/
8+
"""
9+
10+
def Create(self, cardPreAuthorization):
11+
"""Create new card preauthorization
12+
param CardPreAuthorization object to create
13+
return CardPreAuthorization Object returned from API
14+
"""
15+
return self._createObject('preauthorizations_create', cardPreAuthorization, 'CardPreAuthorization')
16+
17+
def Get(self, cardPreAuthorizationId):
18+
"""Get card preauthorization
19+
param string CardPreAuthorization identifier
20+
return CardPreAuthorization Object returned from API
21+
"""
22+
return self._getObject('preauthorizations_get', cardPreAuthorizationId, 'CardPreAuthorization')
23+
24+
def Update(self, cardPreAuthorization):
25+
"""Update card preauthorization
26+
param CardPreAuthorization object to save
27+
return CardPreAuthorization Object returned from API
28+
"""
29+
return self._saveObject('preauthorizations_save', cardPreAuthorization, 'CardPreAuthorization')

mangopaysdk/tools/apiusers.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,22 @@ def GetBankAccount(self, userId, bankAccountId):
9696
"""
9797
return self._getObject('users_getbankaccount', userId, 'BankAccount', bankAccountId)
9898

99+
def GetCards(self, userId, pagination = None):
100+
"""Get user payment cards.
101+
param Int/GUID userId
102+
param Pagination object
103+
return array or card entities
104+
"""
105+
return self._getList('users_getcards', pagination, 'Card', userId)
106+
107+
def GetTransactions(self, userId, pagination = None):
108+
"""Get user payment cards.
109+
param Int/GUID userId
110+
param Pagination object
111+
return array or transactions
112+
"""
113+
return self._getList('users_transactions', pagination, 'Transaction', userId)
114+
99115
def GetUserResponse(self, response):
100116
"""Get correct user object - to be used internally.
101117
param object response Response from API

mangopaysdk/tools/enums.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@ class CardRegistrationStatus:
7575
ERROR = 'ERROR'
7676
VALIDATED = 'VALIDATED'
7777

78+
class CardPreAuthorizationStatus:
79+
WAITING = 'WAITING'
80+
CANCELED = 'CANCELED'
81+
EXPIRED = 'EXPIRED'
82+
VALIDATED = 'VALIDATED'
83+
7884
class EventType:
7985
PAYIN_NORMAL_CREATED = 'PAYIN_NORMAL_CREATED'
8086
PAYIN_NORMAL_SUCCEEDED = 'PAYIN_NORMAL_SUCCEEDED'
@@ -98,7 +104,10 @@ class EventType:
98104
class KycDocumentType:
99105
IDENTITY_PROOF = 'IDENTITY_PROOF'
100106
REGISTRATION_PROOF = 'REGISTRATION_PROOF'
101-
107+
ARTICLES_OF_ASSOCIATION = 'ARTICLES_OF_ASSOCIATION'
108+
SHAREHOLDER_DECLARATION = 'SHAREHOLDER_DECLARATION'
109+
ADDRESS_PROOF = 'ADDRESS_PROOF'
110+
102111
class KycDocumentStatus:
103112
CREATED = 'CREATED'
104113
VALIDATION_ASKED = 'VALIDATION_ASKED'

mangopaysdk/types/dto.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ class Dto(object):
22
"""Abstract class for all DTOs (entities and their composites)."""
33

44
def GetSubObjects(self):
5-
"""Get array with mapping which property is object and what type of object..
5+
"""Get array with mapping which property is object and what type of object.
66
To be overridden in child class if has any sub objects.
77
return array
88
"""

mangopaysdk/types/payinexecutiondetailsdirect.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
class PayInExecutionDetailsDirect(PayInExecutionDetails):
55

66
def __init__(self):
7+
# direct card
78
self.CardId = None
89
self.SecureModeReturnURL = None
910
# Mode3DSType { DEFAULT, FORCE }
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from mangopaysdk.types.payinpaymentdetails import PayInPaymentDetails
2+
3+
class PayInPaymentDetailsBankWire(PayInPaymentDetails):
4+
"""Class represents BankWire type for mean of payment in PayIn entity."""
5+
6+
def __init__(self):
7+
self.BankAccount = None
8+
self.WireReference = None
9+
self.DeclaredDebitedFunds = None
10+
self.DeclaredFees = None
11+
12+
def GetSubObjects(self):
13+
return {'BankAccount': 'BankAccount'}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from mangopaysdk.types.payinpaymentdetails import PayInPaymentDetails
2+
3+
4+
class PayInPaymentDetailsPreAuthorized(PayInPaymentDetails):
5+
6+
def __init__(self):
7+
# The ID of the Preauthorization object
8+
self.PreauthorizationId = None

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# to build - python setup.py sdist upload
44
setup(
55
name='mangopaysdk',
6-
version='0.31',
6+
version='0.32',
77
author='Mangopay (www.mangopay.com)',
88
author_email='it-support@mangopay.com',
99
packages=['mangopaysdk', 'mangopaysdk.entities', 'mangopaysdk.tools', 'mangopaysdk.tools.storages', 'mangopaysdk.types', 'mangopaysdk.types.exceptions'],

test_suite.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from tests.testtokens import Test_Tokens
1717
from tests.testtransfers import Test_Transfers
1818
from tests.testevents import Test_ApiEvents
19+
from tests.testcardpreauthorizations import Test_CardPreAuthorization
1920

2021

2122
suite = unittest.TestSuite()
@@ -29,6 +30,7 @@
2930
suite.addTest(unittest.makeSuite(Test_Transfers))
3031
suite.addTest(unittest.makeSuite(TestRefunds))
3132
suite.addTest(unittest.makeSuite(Test_CardRegistrations))
33+
suite.addTest(unittest.makeSuite(Test_CardPreAuthorization))
3234
suite.addTest(unittest.makeSuite(Test_ApiEvents))
3335

3436
modules = ['mangopaysdk']

tests/testapiusers.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,22 @@ def test_Users_BankAccounts(self):
131131
self.assertTrue(pagination.TotalPages > 0)
132132
self.assertTrue(pagination.TotalItems > 0)
133133

134+
def test_Users_Cards(self):
135+
john = self.getJohn()
136+
payIn = self.getJohnsPayInCardDirect()
137+
userCards = self.sdk.users.GetCards(john.Id)
138+
self.assertTrue(len(userCards) == 1)
139+
self.assertIsNotNone(userCards[0].CardType)
140+
self.assertIsNotNone(userCards[0].Currency)
141+
142+
def test_Users_Transactions(self):
143+
john = self.getJohn()
144+
transfer = self.getJohnsTransfer()
145+
userTransfers = self.sdk.users.GetTransactions(john.Id)
146+
self.assertTrue(len(userTransfers) > 0)
147+
self.assertIsNotNone(userTransfers[0].Type)
148+
self.assertIsNotNone(userTransfers[0].Status)
149+
134150
def test_Users_CreateKycDocument(self):
135151
kycDoc = self.getUserKycDocument()
136152
self.assertNotEqual(kycDoc.Id, None)

0 commit comments

Comments
 (0)