Ejemplo n.º 1
0
    def unlock_frozen_accounts(account_id: int):
        """Unlock frozen accounts."""
        from pay_api.services.cfs_service import CFSService  # pylint: disable=import-outside-toplevel,cyclic-import
        pay_account: PaymentAccount = PaymentAccount.find_by_id(account_id)
        if pay_account.cfs_account_status == CfsAccountStatus.FREEZE.value:
            # update CSF
            cfs_account: CfsAccountModel = CfsAccountModel.find_effective_by_account_id(
                pay_account.id)
            CFSService.unsuspend_cfs_account(cfs_account=cfs_account)

            cfs_account.status = CfsAccountStatus.ACTIVE.value
            cfs_account.save()

            payload = pay_account._create_account_event_payload(  # pylint:disable=protected-access
                'bc.registry.payment.unlockAccount')

            try:
                publish_response(
                    payload=payload,
                    client_name=current_app.config['NATS_ACCOUNT_CLIENT_NAME'],
                    subject=current_app.config['NATS_ACCOUNT_SUBJECT'])
            except Exception as e:  # pylint: disable=broad-except
                current_app.logger.error(e)
                current_app.logger.error(
                    'Notification to Queue failed for the Unlock Account %s - %s',
                    pay_account.auth_account_id, pay_account.auth_account_name)
                capture_message(
                    'Notification to Queue failed for the Unlock Account : {msg}.'
                    .format(msg=payload),
                    level='error')
Ejemplo n.º 2
0
    def _publish_to_queue(cls, payment_file_list: List[str]):
        # Publish message to the Queue, saying file has been uploaded. Using the event spec.
        queue_data = {
            'fileSource': 'MINIO',
            'location': current_app.config['MINIO_BUCKET_NAME']
        }
        for file_name in payment_file_list:
            queue_data['fileName'] = file_name

            payload = {
                'specversion': '1.x-wip',
                'type': 'bc.registry.payment.casSettlementUploaded',
                'source': file_name,
                'id': file_name,
                'time': f'{datetime.now()}',
                'datacontenttype': 'application/json',
                'data': queue_data
            }

            try:
                publish_response(
                    payload=payload,
                    client_name=current_app.config.get(
                        'NATS_PAYMENT_RECONCILIATIONS_CLIENT_NAME'),
                    subject=current_app.config.get(
                        'NATS_PAYMENT_RECONCILIATIONS_SUBJECT'))
            except Exception as e:  # pylint: disable=broad-except
                current_app.logger.error(e)
                current_app.logger.warning(
                    f'Notification to Queue failed for the file {file_name}',
                    e)
                raise
Ejemplo n.º 3
0
 def _publish_to_mailer(cls, invoice):
     """Construct message and send to mailer queue."""
     receipt: ReceiptModel = ReceiptModel.find_by_invoice_id_and_receipt_number(
         invoice_id=invoice.id)
     invoice_ref: InvoiceReferenceModel = InvoiceReferenceModel.find_reference_by_invoice_id_and_status(
         invoice_id=invoice.id,
         status_code=InvoiceReferenceStatus.COMPLETED.value)
     payment_transaction: PaymentTransactionModel = PaymentTransactionModel.find_recent_completed_by_invoice_id(
         invoice_id=invoice.id)
     q_payload = dict(
         specversion='1.x-wip',
         type='bc.registry.payment.refundRequest',
         source=
         f'https://api.pay.bcregistry.gov.bc.ca/v1/invoices/{invoice.id}',
         id=invoice.id,
         datacontenttype='application/json',
         data=dict(identifier=invoice.business_identifier,
                   orderNumber=receipt.receipt_number,
                   transactionDateTime=get_local_formatted_date_time(
                       payment_transaction.transaction_end_time),
                   transactionAmount=receipt.receipt_amount,
                   transactionId=invoice_ref.invoice_number))
     current_app.logger.debug(
         'Publishing payment refund request to mailer ')
     current_app.logger.debug(q_payload)
     publish_response(
         payload=q_payload,
         client_name=current_app.config.get('NATS_MAILER_CLIENT_NAME'),
         subject=current_app.config.get('NATS_MAILER_SUBJECT'))
Ejemplo n.º 4
0
 def _publish_to_mailer(cls, invoice: InvoiceModel):
     """Construct message and send to mailer queue."""
     receipt: ReceiptModel = ReceiptModel.find_by_invoice_id_and_receipt_number(
         invoice_id=invoice.id)
     invoice_ref: InvoiceReferenceModel = InvoiceReferenceModel.find_reference_by_invoice_id_and_status(
         invoice_id=invoice.id,
         status_code=InvoiceReferenceStatus.COMPLETED.value)
     payment_transaction: PaymentTransactionModel = PaymentTransactionModel.find_recent_completed_by_invoice_id(
         invoice_id=invoice.id)
     message_type: str = f'bc.registry.payment.{invoice.payment_method_code.lower()}.refundRequest'
     filing_description = ''
     for line_item in invoice.payment_line_items:
         if filing_description:
             filing_description += ','
         filing_description += line_item.description
     q_payload = dict(
         specversion='1.x-wip',
         type=message_type,
         source=
         f'https://api.pay.bcregistry.gov.bc.ca/v1/invoices/{invoice.id}',
         id=invoice.id,
         datacontenttype='application/json',
         data=dict(identifier=invoice.business_identifier,
                   orderNumber=receipt.receipt_number,
                   transactionDateTime=get_local_formatted_date_time(
                       payment_transaction.transaction_end_time),
                   transactionAmount=receipt.receipt_amount,
                   transactionId=invoice_ref.invoice_number,
                   refundDate=get_local_formatted_date_time(
                       datetime.now(), '%Y%m%d'),
                   filingDescription=filing_description))
     if invoice.payment_method_code == PaymentMethod.DRAWDOWN.value:
         payment_account: PaymentAccountModel = PaymentAccountModel.find_by_id(
             invoice.payment_account_id)
         q_payload['data'].update(
             dict(bcolAccount=invoice.bcol_account,
                  bcolUser=payment_account.bcol_user_id))
     current_app.logger.debug(
         'Publishing payment refund request to mailer ')
     current_app.logger.debug(q_payload)
     publish_response(
         payload=q_payload,
         client_name=current_app.config.get('NATS_MAILER_CLIENT_NAME'),
         subject=current_app.config.get('NATS_MAILER_SUBJECT'))
Ejemplo n.º 5
0
    def publish_account_mailer_event(self):
        """Publish to account mailer message to send out confirmation email."""
        if self.payment_method == PaymentMethod.PAD.value:
            payload = self._create_account_event_payload(
                'bc.registry.payment.padAccountCreate', include_pay_info=True)

            try:
                publish_response(
                    payload=payload,
                    client_name=current_app.config['NATS_MAILER_CLIENT_NAME'],
                    subject=current_app.config['NATS_MAILER_SUBJECT'])
            except Exception as e:  # NOQA pylint: disable=broad-except
                current_app.logger.error(e)
                current_app.logger.error(
                    'Notification to Queue failed for the Account Mailer %s - %s',
                    self.auth_account_id, self.name)
                capture_message(
                    f'Notification to Queue failed for the Account Mailer on account creation : {payload}.',
                    level='error')
Ejemplo n.º 6
0
def publish_mailer_events(message_type: str,
                          pay_account: PaymentAccountModel,
                          additional_params: Dict = {}):
    """Publish payment message to the mailer queue."""
    # Publish message to the Queue, saying account has been activated. Using the event spec.

    fee_schedule: FeeScheduleModel = FeeScheduleModel.find_by_filing_type_and_corp_type(
        corp_type_code='BCR', filing_type_code='NSF')

    payload = {
        'specversion': '1.x-wip',
        'type': f'bc.registry.payment.{message_type}',
        'source':
        f'https://api.pay.bcregistry.gov.bc.ca/v1/accounts/{pay_account.auth_account_id}',
        'id': f'{pay_account.auth_account_id}',
        'time': f'{datetime.now()}',
        'datacontenttype': 'application/json',
        'data': {
            'accountId': pay_account.auth_account_id,
            'nsfFee': fee_schedule.fee.amount,
            **additional_params
        }
    }
    try:
        publish_response(
            payload=payload,
            client_name=current_app.config.get('NATS_MAILER_CLIENT_NAME'),
            subject=current_app.config.get('NATS_MAILER_SUBJECT'))
    except Exception as e:  # pylint: disable=broad-except
        current_app.logger.error(e)
        current_app.logger.warning(
            'Notification to Queue failed for the Account Mailer %s - %s',
            pay_account.auth_account_id, payload)
        capture_message(
            'Notification to Queue failed for the Account Mailer {auth_account_id}, {msg}.'
            .format(auth_account_id=pay_account.auth_account_id, msg=payload),
            level='error')