def furnish_request_message(request: Request, option: str):  # pylint: disable=redefined-outer-name
    """Send notification info to the mail queue."""
    current_app.logger.debug(
        'Start of the furnishing of request for %s nrNum=%s', option,
        request.nrNum)
    payload = create_cloud_event_msg(
        msg_id=str(uuid.uuid4()),
        msg_type='bc.registry.names.request',
        source=f'/requests/{request.nrNum}',
        time=datetime.utcfromtimestamp(
            time.time()).replace(tzinfo=timezone.utc).isoformat(),
        identifier=request.nrNum,
        json_data_body={'request': {
            'nrNum': request.nrNum,
            'option': option
        }})
    current_app.logger.debug('About to publish email for %s nrNum=%s', option,
                             request.nrNum)
    publish_email_message(payload)

    if option == 'before-expiry':
        request.notifiedBeforeExpiry = True
    elif option == 'expired':
        request.notifiedExpiry = True
        request.stateCd = State.EXPIRED
    request.save_to_db()
def create_name_request_state_msg(nr_num, state_cd, old_state_cd):
    """Builds a name request state message."""
    return create_cloud_event_msg(msg_id=str(uuid.uuid4()),
                                            msg_type='bc.registry.names.events',
                                            source=f'/requests/{nr_num}',
                                            time=datetime.
                                            utcfromtimestamp(time.time()).
                                            replace(tzinfo=timezone.utc).
                                            isoformat(),
                                            identifier=nr_num,
                                            json_data_body={
                                                'request': {
                                                    'nrNum': nr_num,
                                                    'newState': state_cd,
                                                    'previousState': old_state_cd
                                                }}
                                            )
Exemple #3
0
async def furnish_receipt_message(qsm: QueueServiceManager, payment: Payment):  # pylint: disable=redefined-outer-name
    """Send receipt info to the mail queue if it hasn't yet been done."""
    if payment.furnished == 'Y':
        logger.debug(
            'Queue Issue: Duplicate, already furnished receipt for payment.id=%s',
            payment.id)
        capture_message(
            f'Queue Issue: Duplicate, already furnished receipt for payment.id={payment.id}'
        )
        return

    nr = None

    logger.debug('Start of the furnishing of receipt for payment record:%s',
                 payment.as_dict())
    try:
        payment.furnished = True
        payment.save_to_db()
    except Exception as err:  # noqa: B902; bare exception to catch all
        raise Exception('Unable to alter payment record.') from err

    try:
        nr = RequestDAO.find_by_id(payment.nrId)
        cloud_event_msg = create_cloud_event_msg(
            msg_id=str(uuid.uuid4()),
            msg_type='bc.registry.names.request',
            source=f'/requests/{nr.nrNum}',
            time=datetime.utcfromtimestamp(
                time.time()).replace(tzinfo=timezone.utc).isoformat(),
            identifier=nr.nrNum,
            json_data_body={
                'request': {
                    'header': {
                        'nrNum': nr.nrNum
                    },
                    'paymentToken': payment.payment_token,
                    'statusCode': nr.stateCd
                }
            })
        logger.debug('About to publish email for payment.id=%s', payment.id)
        await publish_email_message(qsm, cloud_event_msg)
    except Exception as err:  # noqa: B902; bare exception to catch all
        payment.furnished = False
        payment.save_to_db()
        logger.debug('Reset payment furnish status payment.id= %s', payment.id)
        raise QueueException(f'Unable to furnish NR info. {err}') from err
def publish_email_notification(nr_num: str, option: str, refund_value=None):
    """Send notification info to the mail queue."""
    data = {
        'request': {
            'nrNum': nr_num,
            'option': option
        }
    }

    if refund_value:
        data['request']['refundValue'] = refund_value

    payload = create_cloud_event_msg(
        msg_id=str(uuid.uuid4()),
        msg_type='bc.registry.names.request',
        source=f'/requests/{nr_num}',
        time=datetime.utcfromtimestamp(time.time()).replace(tzinfo=timezone.utc).isoformat(),
        identifier=nr_num,
        json_data_body=data
    )

    email_subject = current_app.config.get('NATS_EMAILER_SUBJECT')
    current_app.logger.debug('About to publish email for %s nrNum=%s', option, nr_num)
    queue.publish_json(payload, email_subject)