Skip to content

Commit 291ee73

Browse files
iulian03Iulian Masar
and
Iulian Masar
authored
[release] 3.46.0 (#425)
* handle fetching disputes for payin (#424) Co-authored-by: Iulian Masar <iulian.masar@codegile.com> * [feature] handle reports v2 (#420) * handle reports v2 * added event types * fixed tests --------- Co-authored-by: Iulian Masar <iulian.masar@codegile.com> --------- Co-authored-by: Iulian Masar <iulian.masar@codegile.com>
1 parent e4f2158 commit 291ee73

File tree

6 files changed

+153
-3
lines changed

6 files changed

+153
-3
lines changed

mangopay/constants.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,10 @@
220220
('INSTANT_CONVERSION_FAILED', 'instant_conversion_failed', 'Instant Conversion Failed'),
221221
('QUOTED_CONVERSION_CREATED', 'quoted_conversion_created', 'Quoted Conversion Created'),
222222
('QUOTED_CONVERSION_SUCCEEDED', 'quoted_conversion_succeeded', 'Quoted Conversion Succeeded'),
223-
('QUOTED_CONVERSION_FAILED', 'quoted_conversion_failed', 'Quoted Conversion Failed')
223+
('QUOTED_CONVERSION_FAILED', 'quoted_conversion_failed', 'Quoted Conversion Failed'),
224+
225+
('REPORT_GENERATED', 'report_generated', 'Report Generated'),
226+
('REPORT_FAILED', 'report_failed', 'Report Failed')
224227
)
225228

226229
NOTIFICATION_STATUS_CHOICES = Choices(

mangopay/fields.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
PayinsLinked, ConversionRate, CardInfo, LocalAccountDetails, InternationalAccountDetails, \
1414
VirtualAccountCapabilities, PaymentRef, PendingUserAction, LegalRepresentative, IndividualRecipient, \
1515
BusinessRecipient, RecipientPropertySchema, IndividualRecipientPropertySchema, BusinessRecipientPropertySchema, \
16-
CompanyNumberValidation
16+
CompanyNumberValidation, ReportFilter
1717

1818

1919
class FieldDescriptor(object):
@@ -1205,3 +1205,27 @@ def api_value(self, value):
12051205
}
12061206

12071207
return value
1208+
1209+
1210+
class ReportFilterField(Field):
1211+
def python_value(self, value):
1212+
if value is not None:
1213+
return ReportFilter(currency=value.get('Currency', None), user_id=value.get('UserId', None),
1214+
wallet_id=value.get('WalletId', None))
1215+
1216+
return value
1217+
1218+
def api_value(self, value):
1219+
value = super(ReportFilterField, self).api_value(value)
1220+
1221+
if isinstance(value, ReportFilter):
1222+
result = {}
1223+
if value.currency is not None:
1224+
result['Currency'] = value.currency
1225+
if value.user_id is not None:
1226+
result['UserId'] = value.user_id
1227+
if value.wallet_id is not None:
1228+
result['WalletId'] = value.wallet_id
1229+
return result
1230+
1231+
return value

mangopay/resources.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
LocalAccountDetailsField, VirtualAccountCapabilitiesField, PaymentRefField, PendingUserActionField,
1919
LegalRepresentativeField, IndividualRecipientField, BusinessRecipientField,
2020
RecipientPropertySchemaField, IndividualRecipientPropertySchemaField,
21-
BusinessRecipientPropertySchemaField, CompanyNumberValidationField)
21+
BusinessRecipientPropertySchemaField, CompanyNumberValidationField, ReportFilterField)
2222
from .query import InsertQuery, UpdateQuery, SelectQuery, ActionQuery, DeleteQuery
2323

2424

@@ -779,6 +779,10 @@ class Meta:
779779
verbose_name_plural = 'payins'
780780
url = '/payins'
781781

782+
def __init__(self, *args, **kwargs):
783+
super(PayIn, self).__init__(*args, **kwargs)
784+
self.disputes = RelatedManager(self, Dispute)
785+
782786
@classmethod
783787
def cast(cls, result):
784788
if cls.__name__ == "RecurringPayInCIT":
@@ -2401,6 +2405,30 @@ class Meta:
24012405
}
24022406

24032407

2408+
class ReportV2(BaseModel):
2409+
creation_date = DateTimeField(api_name='CreationDate')
2410+
report_date = DateTimeField(api_name='ReportDate')
2411+
status = CharField(api_name='Status')
2412+
result_code = CharField(api_name='ResultCode')
2413+
result_message = CharField(api_name='ResultMessage')
2414+
download_format = CharField(api_name='DownloadFormat', required=True)
2415+
download_url = CharField(api_name='DownloadURL')
2416+
report_type = CharField(api_name='ReportType', required=True)
2417+
sort = CharField(api_name='Sort')
2418+
after_date = DateTimeField(api_name='AfterDate', required=True)
2419+
before_date = DateTimeField(api_name='BeforeDate', required=True)
2420+
filters = ReportFilterField(api_name='Filters')
2421+
columns = ListField(api_name='Columns')
2422+
2423+
class Meta:
2424+
verbose_name = 'reportv2'
2425+
verbose_name_plural = 'reportsv2'
2426+
url = {
2427+
InsertQuery.identifier: '/reporting/reports',
2428+
SelectQuery.identifier: '/reporting/reports'
2429+
}
2430+
2431+
24042432
class BankingAlias(BaseModel):
24052433
tag = CharField(api_name='Tag')
24062434
credited_user = ForeignKeyField(User, api_name='CreditedUserId')

mangopay/utils.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1325,3 +1325,30 @@ def to_api_json(self):
13251325
"IsValid": self.is_valid,
13261326
"ValidationRules": self.validation_rules
13271327
}
1328+
1329+
1330+
@add_camelcase_aliases
1331+
class ReportFilter(object):
1332+
def __init__(self, currency=None, user_id=None, wallet_id=None):
1333+
self.currency = currency
1334+
self.user_id = user_id
1335+
self.wallet_id = wallet_id
1336+
1337+
def __str__(self):
1338+
return 'ReportFilter: %s , %s, %s' % \
1339+
(self.currency, self.user_id, self.wallet_id)
1340+
1341+
def __eq__(self, other):
1342+
if isinstance(other, ReportFilter):
1343+
stat = ((self.currency == other.currency) and
1344+
(self.user_id == other.user_id) and
1345+
(self.wallet_id == other.wallet_id))
1346+
return stat
1347+
return False
1348+
1349+
def to_api_json(self):
1350+
return {
1351+
"Currency": self.currency,
1352+
"UserId": self.user_id,
1353+
"WalletId": self.wallet_id
1354+
}

tests/test_disputes.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,23 @@ def test_GetDisputesForUser(self):
7575
self.assertIsNotNone(disputes)
7676
self.assertTrue(disputes)
7777

78+
def test_GetDisputesForPayIn(self):
79+
dispute = None
80+
81+
for d in self._client_disputes :
82+
if d.initial_transaction_id is not None:
83+
dispute = d
84+
break
85+
86+
self.assertIsNotNone(dispute, 'Cannot test getting disputes for wallet because there\'s no dispute with transaction ID in the disputes list.')
87+
pay_in = PayIn.get(dispute.initial_transaction_id)
88+
89+
self.assertIsNotNone(pay_in)
90+
91+
result = pay_in.disputes.all()
92+
93+
self.assertIsNotNone(result)
94+
7895
def test_GetDisputesPendingSettlement(self):
7996
disputes_pending = Dispute.get_pending_settlement()
8097

tests/test_reports_v2.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
from mangopay.resources import ReportV2
2+
from mangopay.utils import ReportFilter
3+
from tests.test_base import BaseTestLive
4+
5+
6+
class ReportsV2TestLive(BaseTestLive):
7+
def test_ReportCreate(self):
8+
report = ReportV2()
9+
report.report_type = 'COLLECTED_FEES'
10+
report.download_format = 'CSV'
11+
report.after_date = 1740787200
12+
report.before_date = 1743544740
13+
result = report.save()
14+
15+
self.assertIsNotNone(result)
16+
self.assertTrue(result['id'])
17+
self.assertEqual(result['report_type'], 'COLLECTED_FEES')
18+
self.assertEqual(result['status'], 'PENDING')
19+
20+
def test_ReportFilteredCreate(self):
21+
report = ReportV2()
22+
report.report_type = 'USER_WALLET_TRANSACTIONS'
23+
report.download_format = 'CSV'
24+
report.after_date = 1740787200
25+
report.before_date = 1743544740
26+
report.filters = ReportFilter()
27+
report.filters.currency = 'EUR'
28+
result = report.save()
29+
30+
self.assertIsNotNone(result)
31+
self.assertTrue(result['id'])
32+
self.assertEqual(result['report_type'], 'USER_WALLET_TRANSACTIONS')
33+
self.assertEqual(result['status'], 'PENDING')
34+
35+
def test_ReportGet(self):
36+
report = ReportV2()
37+
report.report_type = 'COLLECTED_FEES'
38+
report.download_format = 'CSV'
39+
report.after_date = 1740787200
40+
report.before_date = 1743544740
41+
created = report.save()
42+
result = ReportV2.get(created['id'])
43+
44+
self.assertEqual(report.id, result.id)
45+
46+
def test_Reports_All(self):
47+
page = ReportV2.all(page=1, per_page=1)
48+
result = page.data
49+
50+
self.assertIsNotNone(result)
51+
self.assertTrue(len(result) > 0)

0 commit comments

Comments
 (0)