From e3dfe463f887d44f79b113d78a24738e9259f4c1 Mon Sep 17 00:00:00 2001 From: PSNAppZ Date: Tue, 17 Sep 2024 13:03:25 +0530 Subject: [PATCH 1/3] Fix credit account details --- .../tasks/process_payment.py | 49 ++++++++++++++----- 1 file changed, 37 insertions(+), 12 deletions(-) diff --git a/openg2p-g2p-bridge-example-bank-celery/src/openg2p_g2p_bridge_example_bank_celery/tasks/process_payment.py b/openg2p-g2p-bridge-example-bank-celery/src/openg2p_g2p_bridge_example_bank_celery/tasks/process_payment.py index fac87ea..b893980 100644 --- a/openg2p-g2p-bridge-example-bank-celery/src/openg2p_g2p_bridge_example_bank_celery/tasks/process_payment.py +++ b/openg2p-g2p-bridge-example-bank-celery/src/openg2p_g2p_bridge_example_bank_celery/tasks/process_payment.py @@ -86,8 +86,17 @@ def process_payments_worker(payment_request_batch_id: str): accounting_log_debit: AccountingLog = ( construct_accounting_log_for_debit(initiate_payment_request) ) + ( + credit_account_number, + credit_account_name, + credit_account_phone, + credit_account_email, + ) = construct_credit_account_details(initiate_payment_request) + accounting_log_credit: AccountingLog = ( - construct_accounting_log_for_credit(initiate_payment_request) + construct_accounting_log_for_credit( + initiate_payment_request, credit_account_number + ) ) remitting_account = update_account_for_debit( @@ -102,10 +111,10 @@ def process_payments_worker(payment_request_batch_id: str): ) credit_account = update_account_for_credit( - initiate_payment_request.beneficiary_name, - accounting_log_credit.account_number, - initiate_payment_request.beneficiary_phone_no, - initiate_payment_request.beneficiary_email, + credit_account_name, + credit_account_number, + credit_account_phone, + credit_account_email, initiate_payment_request.beneficiary_account_currency, initiate_payment_request.payment_amount, session, @@ -163,14 +172,14 @@ def construct_accounting_log_for_debit( def construct_accounting_log_for_credit( - initiate_payment_request: InitiatePaymentRequest, + initiate_payment_request: InitiatePaymentRequest, credit_account_number: str ): return AccountingLog( reference_no=str(uuid.uuid4()), corresponding_block_reference_no="", customer_reference_no=initiate_payment_request.payment_reference_number, debit_credit=DebitCreditTypes.CREDIT, - account_number=construct_credit_account_number(initiate_payment_request), + account_number=credit_account_number, transaction_amount=initiate_payment_request.payment_amount, transaction_date=datetime.utcnow(), transaction_currency=initiate_payment_request.remitting_account_currency, @@ -185,20 +194,36 @@ def construct_accounting_log_for_credit( ) -def construct_credit_account_number(initiate_payment_request: InitiatePaymentRequest): +def construct_credit_account_details(initiate_payment_request: InitiatePaymentRequest): if initiate_payment_request.beneficiary_account_type == "MOBILE_WALLET": return ( - f"CLEARING - {initiate_payment_request.beneficiary_mobile_wallet_provider}" + f"CLEARING - {initiate_payment_request.beneficiary_mobile_wallet_provider}", + f"Clearing account for {initiate_payment_request.beneficiary_mobile_wallet_provider}", + None, + None, ) elif initiate_payment_request.beneficiary_account_type == "EMAIL_WALLET": return ( - f"CLEARING - {initiate_payment_request.beneficiary_email_wallet_provider}" + f"CLEARING - {initiate_payment_request.beneficiary_email_wallet_provider}", + f"Clearing account for {initiate_payment_request.beneficiary_email_wallet_provider}", + None, + None, ) elif initiate_payment_request.beneficiary_account_type == "BANK_ACCOUNT": if initiate_payment_request.beneficiary_bank_code == "EXAMPLE_BANK": - return initiate_payment_request.beneficiary_account + return ( + initiate_payment_request.beneficiary_account, + initiate_payment_request.beneficiary_name, + initiate_payment_request.beneficiary_phone_no, + initiate_payment_request.beneficiary_email, + ) else: - return f"CLEARING - {initiate_payment_request.beneficiary_bank_code}" + return ( + f"CLEARING - {initiate_payment_request.beneficiary_bank_code}", + f"Clearing account for {initiate_payment_request.beneficiary_bank_code}", + None, + None, + ) def generate_failures(failure_logs: List[AccountingLog], session): From 1d11c675db81b01dc1778425f7dab1282385a766 Mon Sep 17 00:00:00 2001 From: PSNAppZ Date: Tue, 17 Sep 2024 13:35:39 +0530 Subject: [PATCH 2/3] Create account statement after processing payment --- .../tasks/process_payment.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/openg2p-g2p-bridge-example-bank-celery/src/openg2p_g2p_bridge_example_bank_celery/tasks/process_payment.py b/openg2p-g2p-bridge-example-bank-celery/src/openg2p_g2p_bridge_example_bank_celery/tasks/process_payment.py index b893980..da518e9 100644 --- a/openg2p-g2p-bridge-example-bank-celery/src/openg2p_g2p_bridge_example_bank_celery/tasks/process_payment.py +++ b/openg2p-g2p-bridge-example-bank-celery/src/openg2p_g2p_bridge_example_bank_celery/tasks/process_payment.py @@ -1,5 +1,6 @@ import logging import random +import time import uuid from datetime import datetime from typing import List @@ -12,6 +13,7 @@ InitiatePaymentBatchRequest, InitiatePaymentRequest, PaymentStatus, + AccountStatement, ) from sqlalchemy import select from sqlalchemy.orm import sessionmaker @@ -139,6 +141,11 @@ def process_payments_worker(payment_request_batch_id: str): initiate_payment_batch_request.payment_initiate_attempts += 1 initiate_payment_batch_request.payment_status = PaymentStatus.SUCCESS _logger.info(f"Payments processed for batch: {payment_request_batch_id}") + account_statement = AccountStatement( + account_number=initiate_payment_requests[0].remitting_account, + active=True, + ) + session.add(account_statement) session.commit() except Exception as e: _logger.error(f"Error processing payment: {e}") From 1b94a2ced672b11be020ccce8cf3d945967bc3a0 Mon Sep 17 00:00:00 2001 From: PSNAppZ Date: Tue, 17 Sep 2024 13:38:20 +0530 Subject: [PATCH 3/3] Pre-commit fixes --- .../tasks/process_payment.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/openg2p-g2p-bridge-example-bank-celery/src/openg2p_g2p_bridge_example_bank_celery/tasks/process_payment.py b/openg2p-g2p-bridge-example-bank-celery/src/openg2p_g2p_bridge_example_bank_celery/tasks/process_payment.py index da518e9..bc8abe3 100644 --- a/openg2p-g2p-bridge-example-bank-celery/src/openg2p_g2p_bridge_example_bank_celery/tasks/process_payment.py +++ b/openg2p-g2p-bridge-example-bank-celery/src/openg2p_g2p_bridge_example_bank_celery/tasks/process_payment.py @@ -1,6 +1,5 @@ import logging import random -import time import uuid from datetime import datetime from typing import List @@ -8,12 +7,12 @@ from openg2p_g2p_bridge_example_bank_models.models import ( Account, AccountingLog, + AccountStatement, DebitCreditTypes, FundBlock, InitiatePaymentBatchRequest, InitiatePaymentRequest, PaymentStatus, - AccountStatement, ) from sqlalchemy import select from sqlalchemy.orm import sessionmaker