def publish_status(transaction_dao: PaymentTransactionModel, invoice: Invoice): """Publish payment/transaction status to the Queue.""" current_app.logger.debug('<publish_status') if transaction_dao.status_code == TransactionStatus.COMPLETED.value: if invoice.invoice_status_code == InvoiceStatus.PAID.value: status_code = TransactionStatus.COMPLETED.value else: current_app.logger.info( f'Status {invoice.invoice_status_code} received for invoice {invoice.id}' ) return else: status_code = 'TRANSACTION_FAILED' payload = PaymentTransaction.create_event_payload(invoice, status_code) try: publish_response(payload=payload, subject=get_pay_subject_name( invoice.corp_type_code)) except Exception as e: # NOQA pylint: disable=broad-except current_app.logger.error(e) current_app.logger.warning( f'Notification to Queue failed, marking the transaction : {transaction_dao.id} as EVENT_FAILED', e) transaction_dao.status_code = TransactionStatus.EVENT_FAILED.value current_app.logger.debug('>publish_status')
def complete_post_invoice(self, invoice: Invoice, invoice_reference: InvoiceReference) -> None: """Complete any post invoice activities if needed.""" # Publish message to the queue with payment token, so that they can release records on their side. from .payment_transaction import PaymentTransaction, \ publish_response # pylint:disable=import-outside-toplevel,cyclic-import payload = PaymentTransaction.create_event_payload(invoice, TransactionStatus.COMPLETED.value) try: publish_response(payload=payload, subject=get_pay_subject_name(invoice.corp_type_code)) except Exception as e: # pylint: disable=broad-except current_app.logger.error(e) current_app.logger.error('Notification to Queue failed for the Payment Event %s', payload) capture_message('Notification to Queue failed for the Payment Event : {msg}.'.format(msg=payload), level='error')
async def _publish_payment_event(inv: InvoiceModel): """Publish payment message to the queue.""" payment_event_payload = PaymentTransactionService.create_event_payload( invoice=inv, status_code=PaymentStatus.COMPLETED.value) try: await publish(payload=payment_event_payload, client_name=APP_CONFIG.NATS_PAYMENT_CLIENT_NAME, subject=get_pay_subject_name( inv.corp_type_code, subject_format=APP_CONFIG.NATS_PAYMENT_SUBJECT)) except Exception as e: # NOQA pylint: disable=broad-except logger.error(e) logger.warning( 'Notification to Queue failed for the Payment Event - %s', payment_event_payload) capture_message( f'Notification to Queue failed for the Payment Event {payment_event_payload}.', level='error')
def _release_payment(invoice: Invoice): """Release record.""" from .payment_transaction import publish_response # pylint:disable=import-outside-toplevel,cyclic-import from .payment_transaction import PaymentTransaction # pylint:disable=import-outside-toplevel,cyclic-import payload = PaymentTransaction.create_event_payload( invoice, TransactionStatus.COMPLETED.value) try: publish_response(payload=payload, subject=get_pay_subject_name( invoice.corp_type_code)) except Exception as e: # NOQA pylint: disable=broad-except current_app.logger.error(e) current_app.logger.error( 'Notification to Queue failed for the Payment Event %s', payload) capture_message( 'Notification to Queue failed for the Payment Event : {msg}.'. format(msg=payload), level='error')