def process(org_id, recipients, template_name, subject, **kwargs) -> dict:
    """Build the email for Account notification."""
    logger.debug('account  notification: %s', org_id)

    org: OrgModel = OrgModel.find_by_id(org_id)
    # fill in template
    filled_template = generate_template(
        current_app.config.get('TEMPLATE_PATH'), template_name)
    current_time = datetime.now()
    # render template with vars from email msg
    jnja_template = Template(filled_template, autoescape=True)
    jinja_kwargs = {
        'account_name': org.name,
        'url': get_login_url(),
        'today': current_time.strftime('%m-%d-%Y'),
        **kwargs
    }
    html_out = jnja_template.render(jinja_kwargs)
    return {
        'recipients': recipients,
        'content': {
            'subject': subject,
            'body': html_out,
            'attachments': []
        }
    }
示例#2
0
def _get_pad_confirmation_report_pdf(email_msg, token):
    current_time = datetime.datetime.now()
    mailing_address = _get_address(email_msg.get('accountId'))
    template_vars = {
        **email_msg, 'generatedDate': current_time.strftime('%m-%d-%Y'),
        'accountAddress': mailing_address
    }
    filled_template = generate_template(
        current_app.config.get('PDF_TEMPLATE_PATH'), 'pad_confirmation')
    template_b64 = "'" + base64.b64encode(bytes(filled_template,
                                                'utf-8')).decode() + "'"

    pdf_payload = {
        'reportName': 'PAD_Confirmation_Letter',
        'template': template_b64,
        'templateVars': template_vars,
        'populatePageNumber': True,
    }

    report_response = RestService.post(
        endpoint=current_app.config.get('REPORT_API_BASE_URL'),
        token=token,
        auth_header_type=AuthHeaderType.BEARER,
        content_type=ContentType.JSON,
        data=pdf_payload,
        raise_for_status=True,
        additional_headers={'Accept': 'application/pdf'})
    pdf_attachment = None
    if report_response.status_code != 200:
        logger.error('Failed to get pdf')
    else:
        pdf_attachment = base64.b64encode(report_response.content)

    return pdf_attachment
示例#3
0
def _get_pad_confirmation_email_body(email_msg, admin_name):
    filled_template = generate_template(
        current_app.config.get('TEMPLATE_PATH'), 'pad_confirmation_email')
    # render template with vars from email msg
    jnja_template = Template(filled_template, autoescape=True)
    html_out = jnja_template.render(request=email_msg, admin_name=admin_name)
    return html_out
示例#4
0
def _get_body(email_msg: dict):
    filled_template = generate_template(current_app.config.get('TEMPLATE_PATH'),
                                        TemplateType.EJV_FAILED_TEMPLATE_NAME.value)
    # render template with vars from email msg
    jnja_template = Template(filled_template, autoescape=True)
    html_out = jnja_template.render(
        logo_url=email_msg.get('logo_url')
    )
    return html_out
示例#5
0
def process(email_msg: dict) -> dict:
    """Build the email for Payment Completed notification."""
    logger.debug('refund_request notification: %s', email_msg)

    # fill in template
    filled_template = generate_template(
        current_app.config.get('TEMPLATE_PATH'), 'refund_request_email')

    # render template with vars from email msg
    jnja_template = Template(filled_template, autoescape=True)
    html_out = jnja_template.render(refund_data=email_msg)
    return {
        'recipients':
        current_app.config.get('REFUND_REQUEST').get('recipients'),
        'content': {
            'subject': f'Refund Request for {email_msg.get("identifier")}',
            'body': html_out,
            'attachments': []
        }
    }
示例#6
0
def process(event_message: dict) -> dict:
    """Build the email for Payment Completed notification."""
    logger.debug('refund_request notification: %s', event_message)
    email_msg = event_message.get('data')
    message_type = event_message.get('type')
    template_name = None
    recepients = None
    subject = None
    if message_type == MessageType.REFUND_DIRECT_PAY_REQUEST.value:
        template_name = 'creditcard_refund_request_email'
        recepients = current_app.config.get('REFUND_REQUEST').get(
            'creditcard').get('recipients')
        subject = f'Refund Request for {email_msg.get("identifier")}'
    elif message_type == MessageType.REFUND_DRAWDOWN_REQUEST.value:
        template_name = 'bcol_refund_request_email'
        recepients = current_app.config.get('REFUND_REQUEST').get('bcol').get(
            'recipients')
        refund_date = datetime.strptime(email_msg.get('refundDate'),
                                        '%Y%m%d').strftime('%Y-%m-%d')
        subject = f'BC Registries and Online Services Refunds for {refund_date}'

    # fill in template
    filled_template = generate_template(
        current_app.config.get('TEMPLATE_PATH'), template_name)

    # render template with vars from email msg
    jnja_template = Template(filled_template, autoescape=True)
    html_out = jnja_template.render(refund_data=email_msg,
                                    logo_url=email_msg.get('logo_url'))
    return {
        'recipients': recepients,
        'content': {
            'subject': subject,
            'body': html_out,
            'attachments': []
        }
    }