Skip to content

[feature] handle reports v2 #420

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion mangopay/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,10 @@
('INSTANT_CONVERSION_FAILED', 'instant_conversion_failed', 'Instant Conversion Failed'),
('QUOTED_CONVERSION_CREATED', 'quoted_conversion_created', 'Quoted Conversion Created'),
('QUOTED_CONVERSION_SUCCEEDED', 'quoted_conversion_succeeded', 'Quoted Conversion Succeeded'),
('QUOTED_CONVERSION_FAILED', 'quoted_conversion_failed', 'Quoted Conversion Failed')
('QUOTED_CONVERSION_FAILED', 'quoted_conversion_failed', 'Quoted Conversion Failed'),

('REPORT_GENERATED', 'report_generated', 'Report Generated'),
('REPORT_FAILED', 'report_failed', 'Report Failed')
)

NOTIFICATION_STATUS_CHOICES = Choices(
Expand Down
26 changes: 25 additions & 1 deletion mangopay/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
PayinsLinked, ConversionRate, CardInfo, LocalAccountDetails, InternationalAccountDetails, \
VirtualAccountCapabilities, PaymentRef, PendingUserAction, LegalRepresentative, IndividualRecipient, \
BusinessRecipient, RecipientPropertySchema, IndividualRecipientPropertySchema, BusinessRecipientPropertySchema, \
CompanyNumberValidation
CompanyNumberValidation, ReportFilter


class FieldDescriptor(object):
Expand Down Expand Up @@ -1205,3 +1205,27 @@ def api_value(self, value):
}

return value


class ReportFilterField(Field):
def python_value(self, value):
if value is not None:
return ReportFilter(currency=value.get('Currency', None), user_id=value.get('UserId', None),
wallet_id=value.get('WalletId', None))

return value

def api_value(self, value):
value = super(ReportFilterField, self).api_value(value)

if isinstance(value, ReportFilter):
result = {}
if value.currency is not None:
result['Currency'] = value.currency
if value.user_id is not None:
result['UserId'] = value.user_id
if value.wallet_id is not None:
result['WalletId'] = value.wallet_id
return result

return value
26 changes: 25 additions & 1 deletion mangopay/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
LocalAccountDetailsField, VirtualAccountCapabilitiesField, PaymentRefField, PendingUserActionField,
LegalRepresentativeField, IndividualRecipientField, BusinessRecipientField,
RecipientPropertySchemaField, IndividualRecipientPropertySchemaField,
BusinessRecipientPropertySchemaField, CompanyNumberValidationField)
BusinessRecipientPropertySchemaField, CompanyNumberValidationField, ReportFilterField)
from .query import InsertQuery, UpdateQuery, SelectQuery, ActionQuery, DeleteQuery


Expand Down Expand Up @@ -2405,6 +2405,30 @@ class Meta:
}


class ReportV2(BaseModel):
creation_date = DateTimeField(api_name='CreationDate')
report_date = DateTimeField(api_name='ReportDate')
status = CharField(api_name='Status')
result_code = CharField(api_name='ResultCode')
result_message = CharField(api_name='ResultMessage')
download_format = CharField(api_name='DownloadFormat', required=True)
download_url = CharField(api_name='DownloadURL')
report_type = CharField(api_name='ReportType', required=True)
sort = CharField(api_name='Sort')
after_date = DateTimeField(api_name='AfterDate', required=True)
before_date = DateTimeField(api_name='BeforeDate', required=True)
filters = ReportFilterField(api_name='Filters')
columns = ListField(api_name='Columns')

class Meta:
verbose_name = 'reportv2'
verbose_name_plural = 'reportsv2'
url = {
InsertQuery.identifier: '/reporting/reports',
SelectQuery.identifier: '/reporting/reports'
}


class BankingAlias(BaseModel):
tag = CharField(api_name='Tag')
credited_user = ForeignKeyField(User, api_name='CreditedUserId')
Expand Down
27 changes: 27 additions & 0 deletions mangopay/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1325,3 +1325,30 @@ def to_api_json(self):
"IsValid": self.is_valid,
"ValidationRules": self.validation_rules
}


@add_camelcase_aliases
class ReportFilter(object):
def __init__(self, currency=None, user_id=None, wallet_id=None):
self.currency = currency
self.user_id = user_id
self.wallet_id = wallet_id

def __str__(self):
return 'ReportFilter: %s , %s, %s' % \
(self.currency, self.user_id, self.wallet_id)

def __eq__(self, other):
if isinstance(other, ReportFilter):
stat = ((self.currency == other.currency) and
(self.user_id == other.user_id) and
(self.wallet_id == other.wallet_id))
return stat
return False

def to_api_json(self):
return {
"Currency": self.currency,
"UserId": self.user_id,
"WalletId": self.wallet_id
}
51 changes: 51 additions & 0 deletions tests/test_reports_v2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
from mangopay.resources import ReportV2
from mangopay.utils import ReportFilter
from tests.test_base import BaseTestLive


class ReportsV2TestLive(BaseTestLive):
def test_ReportCreate(self):
report = ReportV2()
report.report_type = 'COLLECTED_FEES'
report.download_format = 'CSV'
report.after_date = 1740787200
report.before_date = 1743544740
result = report.save()

self.assertIsNotNone(result)
self.assertTrue(result['id'])
self.assertEqual(result['report_type'], 'COLLECTED_FEES')
self.assertEqual(result['status'], 'PENDING')

def test_ReportFilteredCreate(self):
report = ReportV2()
report.report_type = 'USER_WALLET_TRANSACTIONS'
report.download_format = 'CSV'
report.after_date = 1740787200
report.before_date = 1743544740
report.filters = ReportFilter()
report.filters.currency = 'EUR'
result = report.save()

self.assertIsNotNone(result)
self.assertTrue(result['id'])
self.assertEqual(result['report_type'], 'USER_WALLET_TRANSACTIONS')
self.assertEqual(result['status'], 'PENDING')

def test_ReportGet(self):
report = ReportV2()
report.report_type = 'COLLECTED_FEES'
report.download_format = 'CSV'
report.after_date = 1740787200
report.before_date = 1743544740
created = report.save()
result = ReportV2.get(created['id'])

self.assertEqual(report.id, result.id)

def test_Reports_All(self):
page = ReportV2.all(page=1, per_page=1)
result = page.data

self.assertIsNotNone(result)
self.assertTrue(len(result) > 0)