Skip to content

Commit

Permalink
Merge pull request #870 from sumesh-aot/group_cfs_lines
Browse files Browse the repository at this point in the history
Adding some error handling in place to avoid unwanted errors
  • Loading branch information
sumesh-aot authored Jan 24, 2022
2 parents 823a730 + 178a6c2 commit 3ae753b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
6 changes: 5 additions & 1 deletion pay-api/src/pay_api/services/direct_pay_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def get_receipt(self, payment_account: PaymentAccount, pay_response_url: str, in
"""Get the receipt details by calling PayBC web service."""
# If pay_response_url is present do all the pre-check, else check the status by using the invoice id
current_app.logger.debug(f'Getting receipt details {invoice_reference.invoice_id}. {pay_response_url}')
if pay_response_url is not None:
if pay_response_url:
parsed_args = parse_url_params(pay_response_url)

# validate if hashValue matches with rest of the values hashed
Expand All @@ -166,6 +166,10 @@ def get_receipt(self, payment_account: PaymentAccount, pay_response_url: str, in
# Get the transaction number from invoice reference
paybc_transaction_number = invoice_reference.invoice_number

# If transaction number cannot be found, return None
if not paybc_transaction_number:
return None

# Call PAYBC web service, get access token and use it in get txn call
access_token = self.__get_token().json().get('access_token')

Expand Down
3 changes: 3 additions & 0 deletions pay-api/src/pay_api/services/payment_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,9 @@ def update_transaction(transaction_id: uuid, # pylint: disable=too-many-locals
txn_reason_code = exc.status
transaction_dao.pay_system_reason_code = txn_reason_code
receipt_details = None
except Exception as exc: # noqa pylint: disable=unused-variable, broad-except
receipt_details = None

current_app.logger.info(f'Receipt details for {payment.invoice_number} : {receipt_details}')
if receipt_details:
PaymentTransaction._update_receipt_details(invoices, payment, receipt_details, transaction_dao)
Expand Down
4 changes: 2 additions & 2 deletions pay-api/tests/unit/services/test_payment_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,11 +387,11 @@ def test_transaction_update_on_paybc_connection_error(session, stan_server):
# Mock here that the invoice update fails here to test the rollback scenario
with patch('pay_api.services.oauth_service.requests.post', side_effect=ConnectionError('mocked error')):
transaction = PaymentTransactionService.update_transaction(transaction.id,
pay_response_url='receipt_number=123451')
pay_response_url=None)
assert transaction.pay_system_reason_code == 'SERVICE_UNAVAILABLE'
with patch('pay_api.services.oauth_service.requests.post', side_effect=ConnectTimeout('mocked error')):
transaction = PaymentTransactionService.update_transaction(transaction.id,
pay_response_url='receipt_number=123451')
pay_response_url=None)
assert transaction.pay_system_reason_code == 'SERVICE_UNAVAILABLE'

assert transaction is not None
Expand Down

0 comments on commit 3ae753b

Please sign in to comment.