diff --git a/Dockerfile b/Dockerfile index 7ea5eef..f0255e1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -22,9 +22,9 @@ ADD --chown=${container_user}:${container_user_group} main.py /app RUN python3 -m venv venv \ && . ./venv/bin/activate RUN python3 -m pip install \ - git+https://github.com/openg2p/openg2p-fastapi-common.git@develop\#egg=openg2p-fastapi-common\&subdirectory=openg2p-fastapi-common \ - git+https://github.com/openg2p/openg2p-fastapi-common.git@develop\#egg=openg2p-fastapi-auth\&subdirectory=openg2p-fastapi-auth \ - git+https://github.com/openg2p/openg2p-fastapi-common.git@develop\#egg=openg2p-common-g2pconnect-id-mapper\&subdirectory=openg2p-common-g2pconnect-id-mapper \ + git+https://github.com/OpenG2P/openg2p-fastapi-common/@d2f2cadf01f561117fefea3245eb6e18dbdba826\#egg=openg2p-fastapi-common\&subdirectory=openg2p-fastapi-common \ + git+https://github.com/OpenG2P/openg2p-fastapi-common/@d2f2cadf01f561117fefea3245eb6e18dbdba826\#egg=openg2p-fastapi-auth\&subdirectory=openg2p-fastapi-auth \ + git+https://github.com/OpenG2P/openg2p-fastapi-common/@d2f2cadf01f561117fefea3245eb6e18dbdba826\#egg=openg2p-common-g2pconnect-id-mapper\&subdirectory=openg2p-common-g2pconnect-id-mapper \ ./src/g2p-cash-transfer-bridge-core \ ./src/g2p-cash-transfer-bridge-api \ ./src/gctb-translate-id-fa diff --git a/g2p-cash-transfer-bridge-api/src/g2p_cash_transfer_bridge_api/services/payment_multiplexer.py b/g2p-cash-transfer-bridge-api/src/g2p_cash_transfer_bridge_api/services/payment_multiplexer.py index 6d7661f..4a4a649 100644 --- a/g2p-cash-transfer-bridge-api/src/g2p_cash_transfer_bridge_api/services/payment_multiplexer.py +++ b/g2p-cash-transfer-bridge-api/src/g2p_cash_transfer_bridge_api/services/payment_multiplexer.py @@ -1,4 +1,5 @@ import logging +import random import re import uuid @@ -44,42 +45,49 @@ async def get_payment_backend_from_fa(self, fa: str): return None async def disburse(self, disburse_request: DisburseRequest): + error_messages = [ + "Beneficiary Account is Closed", + "Beneficiary Account is Dormant", + "Beneficiary Account not found", + "Beneficiary Account has a No Credit Policy", + ] + backends = [] if _config.get_backend_name_from_translate: - payee_fa_list = [] - try: - payee_fa_list = await self.id_translate_service.translate( - [ - disbursement.payee_fa - for disbursement in disburse_request.disbursements - ] - ) - except Exception: - # TODO: handle the failures - pass - # TODO : we want to make backend name configurable if true then all this or of false then None + backends = [ + f"backend{i}" for i in range(len(disburse_request.disbursements)) + ] + for i, disbursement in enumerate(disburse_request.disbursements): + if random.random() < 0.2: # 20% chance of failure + status = "rjct" + error_code = "rjct_payment_failed" + error_msg = random.choice(error_messages) + else: + status = "succ" + error_code = None + error_msg = None + backend_name = None if _config.get_backend_name_from_translate: - try: - backend_name = await self.get_payment_backend_from_fa( - payee_fa_list[i] or "" - ) - except Exception: - # TODO : handle the failures - pass + backend_name = backends[i] + await PaymentListItem.insert( - disburse_request.transaction_id, disbursement, backend_name=backend_name + disburse_request.transaction_id, + disbursement, + backend_name=backend_name, + status=status, + error_code=error_code, + error_msg=error_msg, ) async def disbursement_status( self, status_request: DisburseTxnStatusRequest ) -> DisburseTxnStatusResponse: + ref_ids = status_request.txnstatus_request.attribute_value if ( status_request.txnstatus_request.attribute_type == TxnStatusAttributeTypeEnum.reference_id_list ): - # TODO: handle ids not present in db - ref_ids = status_request.txnstatus_request.attribute_value if not isinstance(ref_ids, list): raise BadRequestError( "GCTB-PMS-350", "attribute_value is supposed to be a list."