Skip to content

Commit 0c744e6

Browse files
Changes:
- implemented temporary API calls, - corrected upload of KYC documents
1 parent f9d9773 commit 0c744e6

10 files changed

+125
-39
lines changed

mangopay2-python-sdk.pyproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
<Compile Include="mangopaysdk\entities\bankaccount.py">
2929
<SubType>Code</SubType>
3030
</Compile>
31+
<Compile Include="mangopaysdk\entities\temporaryimmediatepayin.py" />
32+
<Compile Include="mangopaysdk\entities\temporarypaymentcard.py" />
3133
<Compile Include="mangopaysdk\entities\card.py" />
3234
<Compile Include="mangopaysdk\entities\cardpreauthorization.py" />
3335
<Compile Include="mangopaysdk\entities\cardregistration.py" />
@@ -239,6 +241,7 @@
239241
<Content Include="MANIFEST.in">
240242
<SubType>Content</SubType>
241243
</Content>
244+
<Content Include="tests\TestKycPageFile.png" />
242245
</ItemGroup>
243246
<Import Project="$(MSBuildToolsPath)\Microsoft.Common.targets" />
244247
</Project>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from mangopaysdk.entities.transaction import Transaction
2+
3+
4+
class TemporaryImmediatePayIn(Transaction):
5+
"""WARNING!
6+
This is temporary entity and will be removed in future.
7+
Contact support before using these features or if have any queries.
8+
9+
TemporaryImmediatePayIn entity
10+
"""
11+
12+
def __init__(self, id = None):
13+
self.PaymentCardId = None
14+
self.CreditedWalletId = None
15+
return super(TemporaryImmediatePayIn, self).__init__(id)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from mangopaysdk.entities.entitybase import EntityBase
2+
3+
4+
class TemporaryPaymentCard(EntityBase):
5+
"""WARNING!
6+
This is temporary entity and will be removed in future.
7+
Contact support before using these features or if have any queries.
8+
9+
TemporaryPaymentCard entity
10+
"""
11+
12+
def __init__(self, id = None):
13+
self.UserId = None
14+
self.Culture = None
15+
self.ReturnURL = None
16+
self.TemplateURL = None
17+
self.RedirectURL = None
18+
self.Alias = None
19+
return super(TemporaryPaymentCard, self).__init__(id)
20+

mangopaysdk/tools/apibase.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
from mangopaysdk.types.bankaccountdetailsus import BankAccountDetailsUS
3838
from mangopaysdk.types.bankaccountdetailsca import BankAccountDetailsCA
3939
from mangopaysdk.types.bankaccountdetailsother import BankAccountDetailsOTHER
40+
from mangopaysdk.entities.temporarypaymentcard import TemporaryPaymentCard
41+
from mangopaysdk.entities.temporaryimmediatepayin import TemporaryImmediatePayIn
4042

4143

4244
class ApiBase(object):
@@ -124,7 +126,14 @@ class ApiBase(object):
124126
'wallets_get' : ('/wallets/%s', 'GET'),
125127
'wallets_save' : ('/wallets/%s', 'PUT'),
126128

127-
'kyc_documents_all' : ('/KYC/documents', 'GET')
129+
'kyc_documents_all' : ('/KYC/documents', 'GET'),
130+
131+
132+
# These are temporary functions and WILL be removed in the future.
133+
# Contact support before using these features or if have any queries.
134+
'temp_paymentcards_create' : ('/temp/paymentcards', 'POST'),
135+
'temp_paymentcards_get' : ('/temp/paymentcards/%s', 'GET'),
136+
'temp_immediatepayins_create' : ('/temp/immediate-payins', 'POST')
128137
}
129138

130139

mangopaysdk/tools/apicardregistrations.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from mangopaysdk.tools.apibase import ApiBase
22
from mangopaysdk.entities.cardregistration import CardRegistration
3+
from mangopaysdk.entities.temporarypaymentcard import TemporaryPaymentCard
34

45

56
class ApiCardRegistrations (ApiBase):
@@ -24,4 +25,27 @@ def Update(self, cardRegistration):
2425
param CardRegistration object to save
2526
return CardRegistration Object returned from API
2627
"""
27-
return self._saveObject('cardregistration_save', cardRegistration, 'CardRegistration')
28+
return self._saveObject('cardregistration_save', cardRegistration, 'CardRegistration')
29+
30+
31+
def CreateTemporaryPaymentCard(self, paymentCard):
32+
"""WARNING!
33+
This is temporary function and will be removed in future.
34+
Contact support before using these features or if have any queries.
35+
36+
Creates new temporary payment card.
37+
param TemporaryPaymentCard Temporary payment card to be created
38+
return TemporaryPaymentCard Object returned from API
39+
"""
40+
return self._createObject('temp_paymentcards_create', paymentCard, 'TemporaryPaymentCard')
41+
42+
def GetTemporaryPaymentCard(self, paymentCardId):
43+
"""WARNING!
44+
This is temporary function and will be removed in future.
45+
Contact support before using these features or if have any queries.
46+
47+
Gets temporary payment card.
48+
param string Temporary payment card identifier
49+
return TemporaryPaymentCard Object returned from API
50+
"""
51+
return self._getObject('temp_paymentcards_get', paymentCardId, 'TemporaryPaymentCard')

mangopaysdk/tools/apipayins.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from mangopaysdk.tools.apibase import ApiBase
22
from mangopaysdk.entities.payin import PayIn
3+
from mangopaysdk.entities.temporaryimmediatepayin import TemporaryImmediatePayIn
34

45

56
class ApiPayIns (ApiBase):
@@ -36,6 +37,17 @@ def GetRefund(self, payInId):
3637
"""
3738
return self._getObject('payins_getrefunds', payInId, 'Refund')
3839

40+
def CreateTemporaryImmediatePayIn(self, immediatePayIn):
41+
"""WARNING!
42+
This is temporary function and will be removed in future.
43+
Contact support before using these features or if have any queries.
44+
45+
Creates new temporary immediate pay-in.
46+
param TemporaryImmediatePayIn Immediate pay-in object to create
47+
return TemporaryImmediatePayIn Object returned from API
48+
"""
49+
return self._createObject('temp_immediatepayins_create', immediatePayIn, 'TemporaryImmediatePayIn')
50+
3951
def _getPaymentKey(self, payIn):
4052

4153
if payIn.PaymentDetails == None:

mangopaysdk/tools/apiusers.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,12 +180,9 @@ def CreateKycPageFromFile(self, userId, kycDocumentId, file):
180180
raise Exception('Path of file cannot be empty')
181181

182182
if (not os.path.isfile(filePath)):
183-
raise Exception('File not exist')
183+
raise Exception('File not exist: ' + filePath)
184184

185-
kycPage = KycPage()
186-
with open(filePath) as f:
187-
encoded = base64.encodestring(f.read())
188-
kycPage.File = encoded
185+
kycPage = KycPage().LoadDocumentFromFile(filePath)
189186

190187
if (kycPage.File == None):
191188
raise Exception('Content of the file cannot be empty')

tests/TestKycPageFile.png

8.82 KB
Loading

tests/testapiusers.py

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -310,37 +310,9 @@ def test_Users_UpdateKycDocument(self):
310310
def test_Users_CreateKycDocumentPage(self):
311311
john = self.getJohn()
312312
kycDoc = self.getUserKycDocument()
313-
kycPage = KycPage().LoadDocumentFromFile(os.path.join(os.path.dirname(__file__),"spacer.gif"))
313+
kycPage = KycPage().LoadDocumentFromFile(os.path.join(os.path.dirname(__file__), "TestKycPageFile.png"))
314314
kycDocRes = self.sdk.users.CreateUserKycPage(kycPage, john.Id, kycDoc.Id)
315315
self.assertEqual(kycDocRes, None)
316-
317-
def test_Users_CreateKycPage_EmptyFileString(self):
318-
kycDocument = self.getUserKycDocument()
319-
user = self.getJohn()
320-
kycPage = KycPage()
321-
kycPage.File = ''
322-
kycPageResponse = self.sdk.users.CreateUserKycPage(kycPage, user.Id, kycDocument.Id)
323-
self.assertEqual(kycPageResponse, None)
324-
325-
def test_Users_CreateKycPage_WrongFileString(self):
326-
kycDocument = self.getUserKycDocument()
327-
user = self.getJohn()
328-
kycPage = KycPage()
329-
kycPage.File = 'qqqq'
330-
kycPageResponse = self.sdk.users.CreateUserKycPage(kycPage, user.Id, kycDocument.Id)
331-
self.assertEqual(kycPageResponse, None)
332-
333-
def test_Users_CreateKycPage_CorrectFileString(self):
334-
user = self.getJohn()
335-
kycDocumentInit = KycDocument()
336-
kycDocumentInit.Status = KycDocumentStatus.CREATED
337-
kycDocumentInit.Type = KycDocumentType.IDENTITY_PROOF
338-
kycDocument = self.sdk.users.CreateUserKycDocument(kycDocumentInit, user.Id)
339-
kycPage = KycPage()
340-
kycPage.File = 'dGVzdCB0ZXN0IHRlc3QgdGVzdA=='
341-
342-
kycPageResponse = self.sdk.users.CreateUserKycPage(kycPage, user.Id, kycDocument.Id)
343-
self.assertEqual(kycPageResponse, None)
344316

345317
def test_Users_CreateKycPage_EmptyFilePath(self):
346318
user = self.getJohn()
@@ -364,7 +336,7 @@ def test_Users_CreateKycPage_WrongFilePath(self) :
364336
try:
365337
self.sdk.users.CreateKycPageFromFile(user.Id, kycDocument.Id, 'notExistFileName.tmp')
366338
except Exception as exc:
367-
self.assertEqual(exc.message, 'File not exist')
339+
self.assertTrue(exc.message.find('File not exist') != -1)
368340

369341
def test_Users_CreateKycPage_CorrectFilePath(self) :
370342
user = self.getJohn()
@@ -373,7 +345,7 @@ def test_Users_CreateKycPage_CorrectFilePath(self) :
373345
kycDocumentInit.Type = KycDocumentType.IDENTITY_PROOF
374346
kycDocument = self.sdk.users.CreateUserKycDocument(kycDocumentInit, user.Id)
375347

376-
self.sdk.users.CreateKycPageFromFile(user.Id, kycDocument.Id, __file__)
348+
self.sdk.users.CreateKycPageFromFile(user.Id, kycDocument.Id, os.path.join(os.path.dirname(__file__), "TestKycPageFile.png"))
377349

378350
if __name__ == '__main__':
379351
Test_ApiUsers().test_Users_GetKycDocument()

tests/testcardregistrations.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from mangopaysdk.mangopayapi import MangoPayApi
22
from mangopaysdk.entities.cardregistration import CardRegistration
3+
from mangopaysdk.entities.temporarypaymentcard import TemporaryPaymentCard
34
from mangopaysdk.tools.enums import *
45
from tests.testbase import TestBase
56

@@ -44,4 +45,37 @@ def test_CardRegistrations_Update(self):
4445
# def test_Cards_CheckCardExisting(self):
4546
cardRegistration = self.sdk.cardRegistrations.Get(cardRegistration.Id)
4647
card = self.sdk.cards.Get(cardRegistration.CardId)
47-
self.assertTrue(int(card.Id) > 0)
48+
self.assertTrue(int(card.Id) > 0)
49+
50+
51+
# The two tests below are added to cover temporary use cases, which will be removed in future.
52+
53+
def test_TemporaryPaymentCard_Create(self):
54+
user = self.getJohn()
55+
paymentCard = TemporaryPaymentCard()
56+
paymentCard.UserId = user.Id
57+
paymentCard.Tag = 'Test tag'
58+
paymentCard.Culture = 'FR'
59+
paymentCard.ReturnURL = 'http://test.com/test'
60+
paymentCard.TemplateURL = 'https://test.com/test'
61+
62+
paymentCardCreated = self.sdk.cardRegistrations.CreateTemporaryPaymentCard(paymentCard)
63+
64+
self.assertTrue(int(paymentCardCreated.Id) > 0)
65+
self.assertEquals(paymentCardCreated.UserId, user.Id)
66+
67+
def test_TemporaryPaymentCard_Get(self):
68+
user = self.getJohn()
69+
paymentCard = TemporaryPaymentCard()
70+
paymentCard.UserId = user.Id
71+
paymentCard.Tag = 'Test tag'
72+
paymentCard.Culture = 'FR'
73+
paymentCard.ReturnURL = 'http://test.com/test'
74+
paymentCard.TemplateURL = 'https://test.com/test'
75+
76+
paymentCardCreated = self.sdk.cardRegistrations.CreateTemporaryPaymentCard(paymentCard)
77+
78+
paymentCardGet = self.sdk.cardRegistrations.GetTemporaryPaymentCard(paymentCardCreated.Id)
79+
80+
self.assertTrue(int(paymentCardGet.Id) > 0)
81+
self.assertEquals(paymentCardGet.Id, paymentCardCreated.Id)

0 commit comments

Comments
 (0)