Example #1
0
def send_purchase_receipt(payment_record, domain, template_html,
                          template_plaintext, additional_context):
    username = payment_record.payment_method.web_user

    try:
        web_user = WebUser.get_by_username(username)
        email = web_user.get_email()
        name = web_user.first_name
    except ResourceNotFound:
        log_accounting_error(
            "Strange. A payment attempt was made by a user that "
            "we can't seem to find! %s" % username,
            show_stack_trace=True,
        )
        name = email = username

    context = {
        'name': name,
        'amount': fmt_dollar_amount(payment_record.amount),
        'project': domain,
        'date_paid': payment_record.date_created.strftime(USER_DATE_FORMAT),
        'transaction_id': payment_record.public_transaction_id,
    }
    context.update(additional_context)

    email_html = render_to_string(template_html, context)
    email_plaintext = render_to_string(template_plaintext, context)

    send_HTML_email(
        ugettext("Payment Received - Thank You!"),
        email,
        email_html,
        text_content=email_plaintext,
        email_from=get_dimagi_from_email(),
    )
Example #2
0
def _send_downgrade_warning(invoice, context):
    if invoice.is_customer_invoice:
        subject = _(
            "CommCare Alert: {}'s subscriptions will be downgraded to Community Plan after tomorrow!".format(
                invoice.account.name
            ))
        subscriptions_to_downgrade = _(
            "subscriptions on {}".format(invoice.account.name)
        )
        bcc = None
    else:
        subject = _(
            "CommCare Alert: {}'s subscription will be downgraded to Community Plan after tomorrow!".format(
                invoice.get_domain()
            ))
        subscriptions_to_downgrade = _(
            "subscription for {}".format(invoice.get_domain())
        )
        bcc = [settings.GROWTH_EMAIL]

    context.update({
        'subscriptions_to_downgrade': subscriptions_to_downgrade
    })
    send_html_email_async.delay(
        subject,
        invoice.contact_emails,
        render_to_string('accounting/email/downgrade_warning.html', context),
        render_to_string('accounting/email/downgrade_warning.txt', context),
        cc=[settings.ACCOUNTS_EMAIL],
        bcc=bcc,
        email_from=get_dimagi_from_email())
Example #3
0
def send_purchase_receipt(payment_record, domain,
                          template_html, template_plaintext,
                          additional_context):
    username = payment_record.payment_method.web_user

    try:
        web_user = WebUser.get_by_username(username)
        email = web_user.get_email()
        name = web_user.first_name
    except ResourceNotFound:
        log_accounting_error(
            "Strange. A payment attempt was made by a user that "
            "we can't seem to find! %s" % username,
            show_stack_trace=True,
        )
        name = email = username

    context = {
        'name': name,
        'amount': fmt_dollar_amount(payment_record.amount),
        'project': domain,
        'date_paid': payment_record.date_created.strftime(USER_DATE_FORMAT),
        'transaction_id': payment_record.public_transaction_id,
    }
    context.update(additional_context)

    email_html = render_to_string(template_html, context)
    email_plaintext = render_to_string(template_plaintext, context)

    send_HTML_email(
        ugettext("Payment Received - Thank You!"), email, email_html,
        text_content=email_plaintext,
        email_from=get_dimagi_from_email(),
    )
Example #4
0
def send_autopay_failed(invoice, payment_method):
    subscription = invoice.subscription
    auto_payer = subscription.account.auto_pay_user
    payment_method = StripePaymentMethod.objects.get(web_user=auto_payer)
    autopay_card = payment_method.get_autopay_card(subscription.account)
    try:
        recipient = WebUser.get_by_username(auto_payer).get_email()
    except ResourceNotFound:
        recipient = auto_payer
    domain = invoice.get_domain()

    context = {
        'domain': domain,
        'subscription_plan': subscription.plan_version.plan.name,
        'billing_date': datetime.date.today(),
        'invoice_number': invoice.invoice_number,
        'autopay_card': autopay_card,
        'domain_url': absolute_reverse('dashboard_default', args=[domain]),
        'billing_info_url': absolute_reverse('domain_update_billing_info', args=[domain]),
        'support_email': settings.INVOICING_CONTACT_EMAIL,
    }

    template_html = 'accounting/autopay_failed_email.html'
    template_plaintext = 'accounting/autopay_failed_email.txt'

    send_HTML_email(
        subject="Subscription Payment for CommCare Invoice %s was declined" % invoice.invoice_number,
        recipient=recipient,
        html_content=render_to_string(template_html, context),
        text_content=render_to_string(template_plaintext, context),
        email_from=get_dimagi_from_email(),
    )
Example #5
0
def _send_downgrade_warning(invoice, context):
    if invoice.is_customer_invoice:
        subject = _(
            "CommCare Alert: {}'s subscriptions will be downgraded to Community Plan after tomorrow!"
            .format(invoice.account.name))
        subscriptions_to_downgrade = _("subscriptions on {}".format(
            invoice.account.name))
        bcc = None
    else:
        subject = _(
            "CommCare Alert: {}'s subscription will be downgraded to Community Plan after tomorrow!"
            .format(invoice.get_domain()))
        subscriptions_to_downgrade = _("subscription for {}".format(
            invoice.get_domain()))
        bcc = [settings.GROWTH_EMAIL]

    context.update({'subscriptions_to_downgrade': subscriptions_to_downgrade})
    send_html_email_async.delay(
        subject,
        invoice.contact_emails,
        render_to_string('accounting/email/downgrade_warning.html', context),
        render_to_string('accounting/email/downgrade_warning.txt', context),
        cc=[settings.ACCOUNTS_EMAIL],
        bcc=bcc,
        email_from=get_dimagi_from_email())
Example #6
0
def _send_downgrade_warning(invoice, communication_model, context):
    if invoice.is_customer_invoice:
        subject = _(
            "CommCare Alert: {}'s subscriptions will be paused after tomorrow!"
            .format(invoice.account.name))
        subscriptions_to_downgrade = _("subscriptions on {}".format(
            invoice.account.name))
        bcc = None
    else:
        subject = _(
            "CommCare Alert: {}'s subscription will be paused after tomorrow!".
            format(invoice.get_domain()))
        subscriptions_to_downgrade = _("subscription for {}".format(
            invoice.get_domain()))
        bcc = [settings.GROWTH_EMAIL]

    context.update({'subscriptions_to_downgrade': subscriptions_to_downgrade})
    send_html_email_async.delay(
        subject,
        invoice.get_contact_emails(include_domain_admins=True,
                                   filter_out_dimagi=True),
        render_to_string('accounting/email/downgrade_warning.html', context),
        render_to_string('accounting/email/downgrade_warning.txt', context),
        cc=[settings.ACCOUNTS_EMAIL],
        bcc=bcc,
        email_from=get_dimagi_from_email())
    communication_model.objects.create(
        invoice=invoice,
        communication_type=CommunicationType.DOWNGRADE_WARNING,
    )
Example #7
0
def send_autopay_failed(invoice, payment_method):
    subscription = invoice.subscription
    auto_payer = subscription.account.auto_pay_user
    payment_method = StripePaymentMethod.objects.get(web_user=auto_payer)
    autopay_card = payment_method.get_autopay_card(subscription.account)
    web_user = WebUser.get_by_username(auto_payer)
    if web_user:
        recipient = web_user.get_email()
    else:
        recipient = auto_payer
    domain = invoice.get_domain()

    context = {
        'domain': domain,
        'subscription_plan': subscription.plan_version.plan.name,
        'billing_date': datetime.date.today(),
        'invoice_number': invoice.invoice_number,
        'autopay_card': autopay_card,
        'domain_url': absolute_reverse('dashboard_default', args=[domain]),
        'billing_info_url': absolute_reverse('domain_update_billing_info', args=[domain]),
        'support_email': settings.INVOICING_CONTACT_EMAIL,
    }

    template_html = 'accounting/email/autopay_failed.html'
    template_plaintext = 'accounting/email/autopay_failed.txt'

    send_HTML_email(
        subject="Subscription Payment for CommCare Invoice %s was declined" % invoice.invoice_number,
        recipient=recipient,
        html_content=render_to_string(template_html, context),
        text_content=render_to_string(template_plaintext, context),
        email_from=get_dimagi_from_email(),
    )
Example #8
0
def get_context_to_send_purchase_receipt(payment_record_id, domain,
                                         additional_context):
    payment_record = PaymentRecord.objects.get(id=payment_record_id)
    username = payment_record.payment_method.web_user
    web_user = WebUser.get_by_username(username)
    if web_user:
        email = web_user.get_email()
        name = web_user.first_name
    else:
        raise_except_and_log_accounting_comms_error(username)
        name = email = username

    template_context = {
        'name': name,
        'amount': fmt_dollar_amount(payment_record.amount),
        'project': domain,
        'date_paid': payment_record.date_created.strftime(USER_DATE_FORMAT),
        'transaction_id': payment_record.public_transaction_id,
    }
    template_context.update(additional_context)

    return {
        'template_context': template_context,
        'email_to': email,
        'email_from': get_dimagi_from_email()
    }
Example #9
0
def _send_overdue_notice(invoice, context):
    send_html_email_async.delay(
        ugettext('CommCare Billing Statement 30 days Overdue for {}'.format(invoice.get_domain())),
        invoice.contact_emails,
        render_to_string('accounting/30_days.html', context),
        render_to_string('accounting/30_days.txt', context),
        cc=[settings.ACCOUNTS_EMAIL],
        email_from=get_dimagi_from_email())
Example #10
0
def _send_overdue_notice(invoice, context):
    send_html_email_async.delay(
        ugettext('CommCare Billing Statement 30 days Overdue for {}'.format(invoice.get_domain())),
        invoice.contact_emails,
        render_to_string('accounting/30_days.html', context),
        render_to_string('accounting/30_days.txt', context),
        cc=[settings.ACCOUNTS_EMAIL],
        email_from=get_dimagi_from_email())
Example #11
0
def _send_downgrade_notice(invoice, context):
    send_html_email_async.delay(
        ugettext('Oh no! Your CommCare subscription for {} has been downgraded'.format(invoice.get_domain())),
        invoice.contact_emails,
        render_to_string('accounting/downgrade.html', context),
        render_to_string('accounting/downgrade.txt', context),
        cc=[settings.ACCOUNTS_EMAIL],
        email_from=get_dimagi_from_email()
    )
Example #12
0
def _send_downgrade_notice(invoice, context):
    send_html_email_async.delay(
        ugettext('Oh no! Your CommCare subscription for {} has been downgraded'.format(invoice.get_domain())),
        invoice.contact_emails,
        render_to_string('accounting/downgrade.html', context),
        render_to_string('accounting/downgrade.txt', context),
        cc=[settings.ACCOUNTS_EMAIL],
        email_from=get_dimagi_from_email()
    )
Example #13
0
def _send_downgrade_notice(invoice, context):
    send_html_email_async.delay(
        _('Oh no! Your CommCare subscription for {} has been paused'.format(invoice.get_domain())),
        invoice.get_contact_emails(include_domain_admins=True, filter_out_dimagi=True),
        render_to_string('accounting/email/downgrade.html', context),
        render_to_string('accounting/email/downgrade.txt', context),
        cc=[settings.ACCOUNTS_EMAIL],
        bcc=[settings.GROWTH_EMAIL],
        email_from=get_dimagi_from_email()
    )
Example #14
0
def _send_downgrade_warning(invoice, context):
    send_html_email_async.delay(
        ugettext("CommCare Alert: {}'s subscription will be downgraded to Community Plan after tomorrow!".format(
            invoice.get_domain()
        )),
        invoice.contact_emails,
        render_to_string('accounting/downgrade_warning.html', context),
        render_to_string('accounting/downgrade_warning.txt', context),
        cc=[settings.ACCOUNTS_EMAIL],
        email_from=get_dimagi_from_email())
Example #15
0
def _send_downgrade_warning(invoice, context):
    send_html_email_async.delay(
        ugettext("CommCare Alert: {}'s subscription will be downgraded to Community Plan after tomorrow!".format(
            invoice.get_domain()
        )),
        invoice.contact_emails,
        render_to_string('accounting/downgrade_warning.html', context),
        render_to_string('accounting/downgrade_warning.txt', context),
        cc=[settings.ACCOUNTS_EMAIL],
        email_from=get_dimagi_from_email())
Example #16
0
def _send_overdue_notice(invoice, context):
    if invoice.is_customer_invoice:
        bcc = None
    else:
        bcc = [settings.GROWTH_EMAIL]
    send_html_email_async.delay(
        _('CommCare Billing Statement 30 days Overdue for {}'.format(context['domain_or_account'])),
        invoice.contact_emails,
        render_to_string('accounting/email/30_days.html', context),
        render_to_string('accounting/email/30_days.txt', context),
        cc=[settings.ACCOUNTS_EMAIL],
        bcc=bcc,
        email_from=get_dimagi_from_email())
Example #17
0
def _send_overdue_notice(invoice, context):
    if invoice.is_customer_invoice:
        bcc = None
    else:
        bcc = [settings.GROWTH_EMAIL]
    send_html_email_async.delay(
        _('CommCare Billing Statement 30 days Overdue for {}'.format(context['domain_or_account'])),
        invoice.contact_emails,
        render_to_string('accounting/email/30_days.html', context),
        render_to_string('accounting/email/30_days.txt', context),
        cc=[settings.ACCOUNTS_EMAIL],
        bcc=bcc,
        email_from=get_dimagi_from_email())
Example #18
0
def _send_overdue_notice(invoice, communication_model, context):
    if invoice.is_customer_invoice:
        bcc = None
    else:
        bcc = [settings.GROWTH_EMAIL]
    send_html_email_async.delay(
        _('CommCare Billing Statement 30 days Overdue for {}'.format(context['domain_or_account'])),
        invoice.get_contact_emails(include_domain_admins=True, filter_out_dimagi=True),
        render_to_string('accounting/email/30_days.html', context),
        render_to_string('accounting/email/30_days.txt', context),
        cc=[settings.ACCOUNTS_EMAIL],
        bcc=bcc,
        email_from=get_dimagi_from_email()
    )
    communication_model.objects.create(
        invoice=invoice,
        communication_type=CommunicationType.OVERDUE_INVOICE,
    )
Example #19
0
def get_context_to_send_autopay_failed_email(invoice_id):
    invoice = Invoice.objects.get(id=invoice_id)
    subscription = invoice.subscription
    auto_payer = subscription.account.auto_pay_user
    payment_method = StripePaymentMethod.objects.get(web_user=auto_payer)
    autopay_card = payment_method.get_autopay_card(subscription.account)
    web_user = WebUser.get_by_username(auto_payer)
    if web_user:
        recipient = web_user.get_email()
    else:
        recipient = auto_payer
    domain = invoice.get_domain()

    template_context = {
        'domain':
        domain,
        'subscription_plan':
        subscription.plan_version.plan.name,
        'billing_date':
        date.today(),
        'invoice_number':
        invoice.invoice_number,
        'autopay_card':
        autopay_card,
        'domain_url':
        absolute_reverse('dashboard_default', args=[domain]),
        'billing_info_url':
        absolute_reverse('domain_update_billing_info', args=[domain]),
        'support_email':
        settings.INVOICING_CONTACT_EMAIL,
    }

    return {
        'template_context': template_context,
        'invoice_number': invoice.invoice_number,
        'email_to': recipient,
        'email_from': get_dimagi_from_email()
    }
Example #20
0
def send_purchase_receipt(payment_record, domain,
                          template_html, template_plaintext,
                          additional_context):
    username = payment_record.payment_method.web_user
    web_user = WebUser.get_by_username(username)
    if web_user:
        email = web_user.get_email()
        name = web_user.first_name
    else:
        try:
            # needed for sentry
            raise AccountingCommunicationError()
        except AccountingCommunicationError:
            log_accounting_error(
                f"A payment attempt was made by a user that "
                f"does not exist: {username}",
                show_stack_trace=True,
            )
        name = email = username

    context = {
        'name': name,
        'amount': fmt_dollar_amount(payment_record.amount),
        'project': domain,
        'date_paid': payment_record.date_created.strftime(USER_DATE_FORMAT),
        'transaction_id': payment_record.public_transaction_id,
    }
    context.update(additional_context)

    email_html = render_to_string(template_html, context)
    email_plaintext = render_to_string(template_plaintext, context)

    send_HTML_email(
        _("Payment Received - Thank You!"), email, email_html,
        text_content=email_plaintext,
        email_from=get_dimagi_from_email(),
    )