From e5315403b77f2c52777a94e7ff428bd8e48c5f9b Mon Sep 17 00:00:00 2001 From: Jia Xu Date: Wed, 11 Sep 2024 09:00:54 -0700 Subject: [PATCH 1/2] fix for 404 error on verify direct_pay invoice --- jobs/payment-jobs/tasks/stale_payment_task.py | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/jobs/payment-jobs/tasks/stale_payment_task.py b/jobs/payment-jobs/tasks/stale_payment_task.py index d658232c1..ed588bd65 100644 --- a/jobs/payment-jobs/tasks/stale_payment_task.py +++ b/jobs/payment-jobs/tasks/stale_payment_task.py @@ -102,16 +102,12 @@ def _verify_created_direct_pay_invoices(cls): current_app.logger.info(f'Found {len(created_invoices)} Created Invoices to be Verified.') for invoice in created_invoices: - try: - current_app.logger.info(f'Verify Invoice Job found records.Invoice Id: {invoice.id}') - paybc_invoice = DirectPayService.query_order_status(invoice, InvoiceReferenceStatus.ACTIVE.value) - - if paybc_invoice.paymentstatus in STATUS_PAID: - current_app.logger.debug('_update_active_transactions') - transaction = TransactionService.find_active_by_invoice_id(invoice.id) - if transaction: - # check existing payment status in PayBC and save receipt - TransactionService.update_transaction(transaction.id, pay_response_url=None) + current_app.logger.info(f'Verify Invoice Job found records.Invoice Id: {invoice.id}') + paybc_invoice = DirectPayService.query_order_status(invoice, InvoiceReferenceStatus.ACTIVE.value) - except Exception as err: # NOQA # pylint: disable=broad-except - current_app.logger.error(err, exc_info=True) + if paybc_invoice.paymentstatus in STATUS_PAID: + current_app.logger.debug('_update_active_transactions') + transaction = TransactionService.find_active_by_invoice_id(invoice.id) + if transaction: + # check existing payment status in PayBC and save receipt + TransactionService.update_transaction(transaction.id, pay_response_url=None) From 88306f157fda622fec11bd756c3283b9af4a0a16 Mon Sep 17 00:00:00 2001 From: Jia Xu Date: Wed, 11 Sep 2024 09:16:41 -0700 Subject: [PATCH 2/2] skip 404 error --- jobs/payment-jobs/tasks/stale_payment_task.py | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/jobs/payment-jobs/tasks/stale_payment_task.py b/jobs/payment-jobs/tasks/stale_payment_task.py index ed588bd65..f91f1836a 100644 --- a/jobs/payment-jobs/tasks/stale_payment_task.py +++ b/jobs/payment-jobs/tasks/stale_payment_task.py @@ -23,6 +23,7 @@ from pay_api.services import PaymentService, TransactionService from pay_api.services.direct_pay_service import DirectPayService from pay_api.utils.enums import InvoiceReferenceStatus, PaymentStatus, TransactionStatus +from requests import HTTPError STATUS_PAID = ('PAID', 'CMPLT') @@ -102,12 +103,19 @@ def _verify_created_direct_pay_invoices(cls): current_app.logger.info(f'Found {len(created_invoices)} Created Invoices to be Verified.') for invoice in created_invoices: - current_app.logger.info(f'Verify Invoice Job found records.Invoice Id: {invoice.id}') - paybc_invoice = DirectPayService.query_order_status(invoice, InvoiceReferenceStatus.ACTIVE.value) + try: + current_app.logger.info(f'Verify Invoice Job found records.Invoice Id: {invoice.id}') + paybc_invoice = DirectPayService.query_order_status(invoice, InvoiceReferenceStatus.ACTIVE.value) + + if paybc_invoice.paymentstatus in STATUS_PAID: + current_app.logger.debug('_update_active_transactions') + transaction = TransactionService.find_active_by_invoice_id(invoice.id) + if transaction: + # check existing payment status in PayBC and save receipt + TransactionService.update_transaction(transaction.id, pay_response_url=None) - if paybc_invoice.paymentstatus in STATUS_PAID: - current_app.logger.debug('_update_active_transactions') - transaction = TransactionService.find_active_by_invoice_id(invoice.id) - if transaction: - # check existing payment status in PayBC and save receipt - TransactionService.update_transaction(transaction.id, pay_response_url=None) + except HTTPError as http_err: + if http_err.response is not None and http_err.response.status_code == 404: + current_app.logger.info(f'Invoice not found (404). Skipping invoice id: {invoice.id}') + continue + current_app.logger.error(f'Error verifying invoice {invoice.id}: {http_err}', exc_info=True)