-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d4719bd
commit 5a2718e
Showing
5 changed files
with
124 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
__all__ = [ | ||
'core_mapper', | ||
'mapper_ledger_accounts', | ||
'mapper_service_providers', | ||
'mapper_service_transactions', | ||
] | ||
from .ledger_accounts import mapper_ledger_accounts | ||
from .service_transactions import ( | ||
mapper_service_providers, | ||
mapper_service_transactions, | ||
) | ||
|
||
# All mapper functions has to return a dictionary with these key, value | ||
# key -> oaxaca collection | ||
# value -> oaxaca data | ||
core_mapper = dict( | ||
service_providers=mapper_service_providers, | ||
service_transactions=mapper_service_transactions, | ||
ledger_accounts=mapper_ledger_accounts, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
class NotRequiredModelError(Exception): | ||
""" | ||
Objects not required in Oaxaca. | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from cuenca_validations.typing import DictStrAny | ||
|
||
from .exc import NotRequiredModelError | ||
|
||
STP_BANK_CODE = '90646' | ||
|
||
|
||
def mapper_ledger_accounts(data: DictStrAny) -> DictStrAny: | ||
account_type = data['account_type'] | ||
# Ignore hold an internal | ||
if account_type not in ['saving', 'default']: | ||
raise NotRequiredModelError | ||
model = dict( | ||
id=data['id'], | ||
created_at=data['created_at'], | ||
user_id=data['user_id'], | ||
) | ||
|
||
if clabe := data.get('_clabe'): | ||
model = dict( | ||
**model, | ||
bank_code=STP_BANK_CODE, | ||
account_number=clabe['clabe'], | ||
) | ||
if account_type == 'saving': | ||
collection = 'savings' | ||
model['balance'] = data['balance'] | ||
else: | ||
collection = 'accounts' | ||
model['name'] = data['user']['name'] | ||
return {collection: model} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from cuenca_validations.typing import DictStrAny | ||
|
||
from .types import CoreTransactionStatus, transaction_status_mapper | ||
|
||
|
||
def mapper_service_providers(data: DictStrAny) -> DictStrAny: | ||
fields = data['fields'] | ||
provider_key = fields[0]['service_provider_key'].replace('_barcode', '') | ||
categories = data.get('categories', []) | ||
model = dict( | ||
id=data['id'], | ||
created_at=data['created_at'], | ||
name=data['name'], | ||
provider_key=provider_key, | ||
categories=[category['name'] for category in categories], | ||
) | ||
return dict(service_providers=model) | ||
|
||
|
||
def mapper_service_transactions(data: DictStrAny) -> DictStrAny: | ||
core_status = CoreTransactionStatus[data['status']] | ||
account = data.get('service_account') | ||
ledger = data.get('ledger_account') | ||
model = dict( | ||
id=data['id'], | ||
status=transaction_status_mapper[core_status], | ||
created_at=data['created_at'], | ||
amount=data['amount'], | ||
) | ||
if ledger: | ||
model['user_id'] = data['ledger_account']['user_id'] | ||
if account: | ||
model = dict( | ||
**model, | ||
descriptor=f'Pago de servicio: {account["name"]}', | ||
account_number=account['account_number'], | ||
provider=account['service_field']['service_provider_id'], | ||
) | ||
return dict(bill_payments=model) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from enum import Enum | ||
|
||
from cuenca_validations.types import TransactionStatus | ||
|
||
|
||
class CoreTransactionStatus(str, Enum): | ||
created = 'created' | ||
failed = 'failed' | ||
submitted = 'submitted' | ||
succeeded = 'succeeded' | ||
transfer_to_default = 'transfer_to_default' | ||
return_to_origin = 'return_to_origin' | ||
suspect = 'suspect' | ||
completed = 'completed' | ||
duplicated = 'duplicated' | ||
pld_review = 'pld_review' | ||
|
||
|
||
transaction_status_mapper = { | ||
CoreTransactionStatus.created: TransactionStatus.in_review, | ||
CoreTransactionStatus.failed: TransactionStatus.failed, | ||
CoreTransactionStatus.submitted: TransactionStatus.in_review, | ||
CoreTransactionStatus.succeeded: TransactionStatus.succeeded, | ||
CoreTransactionStatus.transfer_to_default: TransactionStatus.succeeded, | ||
CoreTransactionStatus.return_to_origin: TransactionStatus.failed, | ||
CoreTransactionStatus.suspect: TransactionStatus.in_review, | ||
CoreTransactionStatus.completed: TransactionStatus.succeeded, | ||
CoreTransactionStatus.duplicated: TransactionStatus.failed, | ||
CoreTransactionStatus.pld_review: TransactionStatus.in_review, | ||
} |