Exemplo n.º 1
0
    def get_rate_response(self):
        gateway = self.data.get('gateway')
        try:
            backend_api_id = SQLMobileBackend.get_backend_api_id(gateway, is_couch_id=True)
        except Exception as e:
            log_smsbillables_error(
                "Failed to get backend for calculating an sms rate due to: %s"
                % e
            )
            raise SMSRateCalculatorError("Could not obtain connection information.")

        country_code = self.data.get('country_code')
        if country_code == NONMATCHING_COUNTRY:
            country_code = None
        direction = self.data.get('direction')

        gateway_fee = SmsGatewayFee.get_by_criteria(
            backend_api_id, direction, backend_instance=gateway,
            country_code=country_code,
        )
        usage_fee = SmsUsageFee.get_by_criteria(direction, self.request.domain)
        usd_gateway_fee = gateway_fee.amount / gateway_fee.currency.rate_to_default
        usd_total = usage_fee.amount + usd_gateway_fee

        return {
            'rate': _("%s per 160 character SMS") % fmt_dollar_amount(usd_total),
        }
Exemplo n.º 2
0
 def _send_payment_receipt(self, invoice, payment_record):
     from corehq.apps.accounting.tasks import send_purchase_receipt
     receipt_email_template = 'accounting/email/invoice_receipt.html'
     receipt_email_template_plaintext = 'accounting/email/invoice_receipt.txt'
     try:
         domain = invoice.subscription.subscriber.domain
         context = {
             'invoicing_contact_email':
             settings.INVOICING_CONTACT_EMAIL,
             'balance':
             fmt_dollar_amount(invoice.balance),
             'is_paid':
             invoice.is_paid,
             'date_due':
             invoice.date_due.strftime(USER_DATE_FORMAT)
             if invoice.date_due else 'None',
             'invoice_num':
             invoice.invoice_number,
         }
         send_purchase_receipt.delay(
             payment_record,
             domain,
             receipt_email_template,
             receipt_email_template_plaintext,
             context,
         )
     except:
         self._handle_email_failure(payment_record)
Exemplo n.º 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(),
    )
Exemplo n.º 4
0
 def process_request(self, request):
     response = super(CreditStripePaymentHandler, self).process_request(request)
     if hasattr(self, 'credit_line'):
         response.update({
             'balance': fmt_dollar_amount(self.credit_line.balance),
         })
     return response
Exemplo n.º 5
0
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 process_request(self, request):
     response = super(CreditStripePaymentHandler, self).process_request(request)
     if hasattr(self, 'credit_line'):
         response.update({
             'balance': fmt_dollar_amount(self.credit_line.balance),
         })
     return response
Exemplo n.º 7
0
    def get_rate_response(self):
        gateway = self.data.get('gateway')
        try:
            backend = SMSBackend.get(gateway)
            backend_api_id = get_backend_by_class_name(
                backend.doc_type).get_api_id()
        except Exception as e:
            logger.error("Failed to get backend for calculating an sms rate "
                         "due to: %s" % e)
            raise SMSRateCalculatorError(
                "Could not obtain connection information.")

        country_code = self.data.get('country_code')
        if country_code == NONMATCHING_COUNTRY:
            country_code = None
        direction = self.data.get('direction')

        gateway_fee = SmsGatewayFee.get_by_criteria(
            backend_api_id,
            direction,
            backend_instance=gateway,
            country_code=country_code,
        )
        usage_fee = SmsUsageFee.get_by_criteria(direction, self.request.domain)
        usd_gateway_fee = gateway_fee.amount * gateway_fee.currency.rate_to_default
        usd_total = usage_fee.amount + usd_gateway_fee

        return {
            'rate':
            _("%s per 160 character SMS") % fmt_dollar_amount(usd_total),
        }
 def get_email_context(self):
     return {
         'balance': fmt_dollar_amount(self.invoice.balance),
         'is_paid': self.invoice.date_paid is not None,
         'date_due': self.invoice.date_due.strftime("%d %B %Y"),
         'invoice_num': self.invoice.invoice_number,
     }
Exemplo n.º 9
0
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),
    )
Exemplo n.º 10
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()
    }
Exemplo n.º 11
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(),
    )
Exemplo n.º 12
0
 def _humanized_features(self):
     return [{
         'type':
         get_feature_name(feature['type'], SoftwareProductType.COMMCARE),
         'amount':
         fmt_dollar_amount(feature['amount'])
     } for feature in self.features]
Exemplo n.º 13
0
 def get_email_context(self):
     context = super(InvoiceStripePaymentHandler, self).get_email_context()
     context.update({
         'balance': fmt_dollar_amount(self.invoice.balance),
         'is_paid': self.invoice.date_paid is not None,
         'date_due': self.invoice.date_due.strftime("%d %B %Y"),
         'invoice_num': self.invoice.invoice_number,
     })
     return context
Exemplo n.º 14
0
 def get_email_context(self):
     context = super(InvoiceStripePaymentHandler, self).get_email_context()
     context.update({
         'balance': fmt_dollar_amount(self.invoice.balance),
         'is_paid': self.invoice.is_paid,
         'date_due': self.invoice.date_due.strftime(USER_DATE_FORMAT) if self.invoice.date_due else 'None',
         'invoice_num': self.invoice.invoice_number,
     })
     return context
Exemplo n.º 15
0
 def _directed_fee(direction, backend_api_id, backend_instance_id):
     gateway_fee = SmsGatewayFee.get_by_criteria(
         backend_api_id, direction, backend_instance=backend_instance_id, country_code=country_code
     )
     if not gateway_fee or gateway_fee.amount is None:
         return None
     usd_gateway_fee = gateway_fee.amount / gateway_fee.currency.rate_to_default
     usage_fee = SmsUsageFee.get_by_criteria(direction)
     return fmt_dollar_amount(usage_fee.amount + usd_gateway_fee)
Exemplo n.º 16
0
 def get_email_context(self):
     context = super(InvoiceStripePaymentHandler, self).get_email_context()
     context.update({
         'balance': fmt_dollar_amount(self.invoice.balance),
         'is_paid': self.invoice.is_paid,
         'date_due': self.invoice.date_due.strftime(USER_DATE_FORMAT) if self.invoice.date_due else 'None',
         'invoice_num': self.invoice.invoice_number,
     })
     return context
Exemplo n.º 17
0
 def process_request(self, request):
     response = super(CreditStripePaymentHandler, self).process_request(request)
     if self.credit_lines:
         response.update({
             'balances': [{'type': cline.product_type if cline.product_type else cline.feature_type,
                           'balance': fmt_dollar_amount(cline.balance)}
                          for cline in self.credit_lines]
         })
     return response
Exemplo n.º 18
0
 def process_request(self, request):
     response = super(CreditStripePaymentHandler, self).process_request(request)
     if self.credit_lines:
         response.update({
             'balances': [{'type': cline.product_type if cline.product_type else cline.feature_type,
                           'balance': fmt_dollar_amount(cline.balance)}
                          for cline in self.credit_lines]
         })
     return response
Exemplo n.º 19
0
 def _directed_fee(direction, backend_api_id, backend_instance_id):
     gateway_fee = SmsGatewayFee.get_by_criteria(
         backend_api_id,
         direction,
         backend_instance=backend_instance_id,
         country_code=country_code)
     if not gateway_fee or gateway_fee.amount is None:
         return None
     usd_gateway_fee = gateway_fee.amount / gateway_fee.currency.rate_to_default
     usage_fee = SmsUsageFee.get_by_criteria(direction)
     return fmt_dollar_amount(usage_fee.amount + usd_gateway_fee)
Exemplo n.º 20
0
 def _send_payment_receipt(self, invoice, payment_record):
     from corehq.apps.accounting.tasks import send_purchase_receipt
     receipt_email_template = 'accounting/invoice_receipt_email.html'
     receipt_email_template_plaintext = 'accounting/invoice_receipt_email_plaintext.txt'
     try:
         domain = invoice.subscription.subscriber.domain
         context = {
             'invoicing_contact_email': settings.INVOICING_CONTACT_EMAIL,
             'balance': fmt_dollar_amount(invoice.balance),
             'is_paid': invoice.is_paid,
             'date_due': invoice.date_due.strftime(USER_DATE_FORMAT) if invoice.date_due else 'None',
             'invoice_num': invoice.invoice_number,
         }
         send_purchase_receipt.delay(
             payment_record, domain, receipt_email_template, receipt_email_template_plaintext, context,
         )
     except:
         self._handle_email_failure(payment_record)
Exemplo n.º 21
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(),
    )
Exemplo n.º 22
0
 def _humanized_features(self):
     return [{
         'type': get_feature_name(feature['type'], self.core_product),
         'amount': fmt_dollar_amount(feature['amount'])
     } for feature in self.features]
Exemplo n.º 23
0
 def _humanized_products(self):
     return [{
         'type': product['type'],
         'amount': fmt_dollar_amount(product['amount'])
     } for product in self.products]
Exemplo n.º 24
0
 def _humanized_products(self):
     return [{'type': product['type'],
              'amount': fmt_dollar_amount(product['amount'])}
             for product in self.products]
Exemplo n.º 25
0
 def _humanized_features(self):
     return [{'type': get_feature_name(feature['type'], self.core_product),
              'amount': fmt_dollar_amount(feature['amount'])}
             for feature in self.features]
Exemplo n.º 26
0
 def _humanized_features(self):
     return [{'type': get_feature_name(feature['type'], SoftwareProductType.COMMCARE),
              'amount': fmt_dollar_amount(feature['amount'])}
             for feature in self.features]