def send_purchase_receipt(payment_record, core_product, template_html, template_plaintext, additional_context): email = payment_record.payment_method.web_user try: web_user = WebUser.get_by_username(email) name = web_user.first_name except ResourceNotFound: logger.error( "[BILLING] Strange. A payment attempt was made by a user that " "we can't seem to find! %s" % email ) name = email context = { 'name': name, 'amount': fmt_dollar_amount(payment_record.amount), 'project': payment_record.creditadjustment_set.last().credit_line.account.created_by_domain, 'date_paid': payment_record.date_created.strftime(USER_DATE_FORMAT), 'product': core_product, '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_by_product(core_product), )
def send_purchase_receipt(payment_record, core_product, template_html, template_plaintext, additional_context): email = payment_record.payment_method.billing_admin.web_user try: web_user = WebUser.get_by_username(email) name = web_user.first_name except ResourceNotFound: logger.error( "[BILLING] Strange. A payment attempt was made by a user that " "we can't seem to find! %s" % email ) name = email context = { 'name': name, 'amount': fmt_dollar_amount(payment_record.amount), 'project': payment_record.payment_method.billing_admin.domain, 'date_paid': payment_record.date_created.strftime('%d %B %Y'), 'product': core_product, '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_by_product(core_product), )
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_by_product(subscription.plan_version.product_rate.product.product_type), )