Skip to content

Commit cf3b583

Browse files
iulian03Iulian Masar
and
Iulian Masar
authored
[feature] 3.43.0 (#409)
* handle blik with code (#408) Co-authored-by: Iulian Masar <iulian.masar@codegile.com> * handle SCA context on get endpoints (#407) Co-authored-by: Iulian Masar <iulian.masar@codegile.com> --------- Co-authored-by: Iulian Masar <iulian.masar@codegile.com>
1 parent ca6387a commit cf3b583

File tree

5 files changed

+94
-24
lines changed

5 files changed

+94
-24
lines changed

mangopay/query.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class SelectQuery(BaseQuery):
4747
def __init__(self, model, *args, **kwargs):
4848
super(SelectQuery, self).__init__(model, 'GET')
4949

50-
def get(self, reference, handler=None, resource_model=None, without_client_id=False, **kwargs):
50+
def get(self, reference, handler=None, resource_model=None, without_client_id=False, with_query_params=False, **kwargs):
5151
model = resource_model or self.model
5252
handler = handler or self.handler
5353

@@ -57,7 +57,10 @@ def get(self, reference, handler=None, resource_model=None, without_client_id=Fa
5757
else:
5858
url = '%s' % meta_url
5959

60-
result, data = handler.request(self.method, url, without_client_id=without_client_id)
60+
if with_query_params:
61+
result, data = handler.request(self.method, url, without_client_id=without_client_id, **kwargs)
62+
else:
63+
result, data = handler.request(self.method, url, without_client_id=without_client_id)
6164

6265
if 'errors' in data:
6366
if result.status_code == 404:

mangopay/resources.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ def is_client_wallet(cls, obj):
410410
def get(cls, *args, **kwargs):
411411
if len(args) == 1 and cls.is_client_wallet(args[0]):
412412
return ClientWallet.get(*tuple(args[0].split('_')), **kwargs)
413-
return super(Wallet, cls).get(*args, **kwargs)
413+
return super(Wallet, cls).get(with_query_params=True, *args, **kwargs)
414414

415415

416416
@python_2_unicode_compatible
@@ -1323,6 +1323,9 @@ class BlikPayIn(PayIn):
13231323
statement_descriptor = CharField(api_name='StatementDescriptor')
13241324
return_url = CharField(api_name='ReturnURL', required=True)
13251325
redirect_url = CharField(api_name='RedirectURL')
1326+
code = CharField(api_name='Code')
1327+
ip_address = CharField(api_name='IpAddress')
1328+
browser_info = BrowserInfoField(api_name='BrowserInfo')
13261329

13271330
class Meta:
13281331
verbose_name = 'blik_payin'

tests/test_payins.py

Lines changed: 48 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
RecurringPayInRegistration, \
99
RecurringPayInCIT, PayInRefund, RecurringPayInMIT, CardPreAuthorizedDepositPayIn, MbwayPayIn, PayPalWebPayIn, \
1010
GooglePayDirectPayIn, MultibancoPayIn, SatispayPayIn, BlikPayIn, KlarnaPayIn, IdealPayIn, GiropayPayIn, \
11-
CardRegistration, BancontactPayIn, SwishPayIn, PayconiqV2PayIn, TwintPayIn, PayByBankPayIn, RecurringPayPalPayInCIT, RecurringPayPalPayInMIT
11+
CardRegistration, BancontactPayIn, SwishPayIn, PayconiqV2PayIn, TwintPayIn, PayByBankPayIn, RecurringPayPalPayInCIT, \
12+
RecurringPayPalPayInMIT
1213
from mangopay.utils import (Money, ShippingAddress, Shipping, Billing, Address, SecurityInfo, ApplepayPaymentData,
1314
GooglepayPaymentData, DebitedBankAccount, LineItem, CardInfo)
1415
from tests import settings
@@ -771,6 +772,23 @@ def test_using_api_names_as_payin_attributes(self):
771772
self.assertIs(payin.Tag, payin.tag)
772773

773774

775+
def new_blik(user, credited_wallet):
776+
pay_in = BlikPayIn()
777+
pay_in.author = user
778+
pay_in.credited_wallet = credited_wallet
779+
pay_in.fees = Money()
780+
pay_in.fees.amount = 300
781+
pay_in.fees.currency = 'PLN'
782+
pay_in.debited_funds = Money()
783+
pay_in.debited_funds.amount = 1000
784+
pay_in.debited_funds.currency = 'PLN'
785+
pay_in.statement_descriptor = 'test'
786+
pay_in.return_url = 'https://example.com?transactionId=wt_57b8f69d-cbcc-4202-9a4f-9a3f3668240b'
787+
pay_in.redirect_url = 'https://r3.girogate.de/ti/dumbdummy?tx=140079495229&rs=oHkl4WvsgwtWpMptWpqWlFa90j0EzzO9&cs=e43baf1ae4a556dfb823fd304acc408580c193e04c1a9bcb26699b4185393b05'
788+
pay_in.tag = 'Blik tag'
789+
return pay_in
790+
791+
774792
class PayInsTestLive(BaseTestLive):
775793
@unittest.skip('Set a breakpoint after creating the mandate, navigate to mandate.redirect_url and confirm')
776794
def test_PayIns_DirectDebitDirect_Create(self):
@@ -1500,19 +1518,7 @@ def test_PayIns_BlikWeb_Create(self):
15001518
credited_wallet.description = 'WALLET IN PLN'
15011519
credited_wallet = Wallet(**credited_wallet.save())
15021520

1503-
pay_in = BlikPayIn()
1504-
pay_in.author = user
1505-
pay_in.credited_wallet = credited_wallet
1506-
pay_in.fees = Money()
1507-
pay_in.fees.amount = 300
1508-
pay_in.fees.currency = 'PLN'
1509-
pay_in.debited_funds = Money()
1510-
pay_in.debited_funds.amount = 1000
1511-
pay_in.debited_funds.currency = 'PLN'
1512-
pay_in.statement_descriptor = 'test'
1513-
pay_in.return_url = 'https://example.com?transactionId=wt_57b8f69d-cbcc-4202-9a4f-9a3f3668240b'
1514-
pay_in.redirect_url = 'https://r3.girogate.de/ti/dumbdummy?tx=140079495229&rs=oHkl4WvsgwtWpMptWpqWlFa90j0EzzO9&cs=e43baf1ae4a556dfb823fd304acc408580c193e04c1a9bcb26699b4185393b05'
1515-
pay_in.tag = 'Blik tag'
1521+
pay_in = new_blik(user, credited_wallet)
15161522

15171523
result = BlikPayIn(**pay_in.save())
15181524
fetched = BlikPayIn().get(result.id)
@@ -1527,6 +1533,34 @@ def test_PayIns_BlikWeb_Create(self):
15271533
self.assertEqual("BLIK", result.payment_type)
15281534
self.assertEqual("PAYIN", result.type)
15291535

1536+
def test_PayIns_BlikWebWithCode_Create(self):
1537+
user = BaseTestLive.get_john(True)
1538+
1539+
# create wallet
1540+
credited_wallet = Wallet()
1541+
credited_wallet.owners = (user,)
1542+
credited_wallet.currency = 'PLN'
1543+
credited_wallet.description = 'WALLET IN PLN'
1544+
credited_wallet = Wallet(**credited_wallet.save())
1545+
1546+
pay_in = new_blik(user, credited_wallet)
1547+
pay_in.code = '777365'
1548+
pay_in.ip_address = '159.180.248.187'
1549+
pay_in.browser_info = BaseTest.get_browser_info()
1550+
1551+
result = BlikPayIn(**pay_in.save())
1552+
fetched = BlikPayIn().get(result.id)
1553+
1554+
self.assertIsNotNone(result)
1555+
self.assertIsNotNone(fetched)
1556+
self.assertEqual(result.id, fetched.id)
1557+
1558+
self.assertEqual("CREATED", result.status)
1559+
self.assertEqual("BLIK", result.payment_type)
1560+
self.assertIsNotNone(result.code)
1561+
self.assertIsNotNone(result.ip_address)
1562+
self.assertIsNotNone(result.browser_info)
1563+
15301564
def test_PayIns_KlarnaWeb_Create(self):
15311565
user = BaseTestLive.get_john(True)
15321566

tests/test_users.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import requests
77
import responses
88

9+
from mangopay.exceptions import APIError
910
from mangopay.resources import (User, NaturalUser, Wallet,
1011
LegalUser, Transfer, Transaction, NaturalUserSca, LegalUserSca)
1112
from mangopay.utils import Money, Address
@@ -988,3 +989,14 @@ def test_Users_CloseLegalSca(self):
988989

989990
self.assertEqual(user.id, closed.id)
990991
self.assertEqual('CLOSED', closed.user_status)
992+
993+
def test_users_GetTransactionsSca(self):
994+
user = BaseTestLive.get_john()
995+
with self.assertRaises(APIError):
996+
Transaction.all(**{"user_id": user.id, "ScaContext": 'USER_PRESENT'})
997+
try:
998+
Transaction.all(**{"user_id": user.id, "ScaContext": 'USER_PRESENT'})
999+
except APIError as ex:
1000+
self.assertTrue('PendingUserAction RedirectUrl' in ex.headers.get('www-authenticate'))
1001+
except Exception as ex:
1002+
self.assertTrue('PendingUserAction RedirectUrl' in ex.headers.get('www-authenticate'))

tests/test_wallets.py

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# -*- coding: utf-8 -*-
2-
from tests import settings
3-
from tests.resources import NaturalUser, Wallet, Transfer
4-
5-
from tests.test_base import BaseTest
6-
2+
import time
73
from datetime import date
84

95
import responses
10-
import time
6+
7+
from mangopay.exceptions import APIError
8+
from tests import settings
9+
from tests.resources import NaturalUser, Wallet, Transfer
10+
from tests.test_base import BaseTest, BaseTestLive
1111

1212

1313
class WalletsTest(BaseTest):
@@ -327,4 +327,22 @@ def test_retrieve_wallet_transactions(self):
327327
transactions = self.legal_user_wallet.transactions.all()
328328

329329
self.assertEqual(len(transactions), 1)
330-
self.assertEqual(transactions[0].type, 'TRANSFER')
330+
self.assertEqual(transactions[0].type, 'TRANSFER')
331+
332+
333+
class WalletsTestLive(BaseTestLive):
334+
def test_Wallets_get(self):
335+
wallet = BaseTestLive.get_johns_wallet()
336+
fetched = Wallet.get(wallet.id)
337+
self.assertEqual(wallet.id, fetched.id)
338+
339+
def test_Wallets_getSca(self):
340+
wallet = BaseTestLive.get_johns_wallet()
341+
with self.assertRaises(APIError):
342+
Wallet.get(wallet.id, ScaContext='USER_PRESENT')
343+
try:
344+
Wallet.get(wallet.id, ScaContext='USER_PRESENT')
345+
except APIError as ex:
346+
self.assertTrue('PendingUserAction RedirectUrl' in ex.headers.get('www-authenticate'))
347+
except Exception as ex:
348+
self.assertTrue('PendingUserAction RedirectUrl' in ex.headers.get('www-authenticate'))

0 commit comments

Comments
 (0)