示例#1
0
    def test_pay_autopayable_invoices(self, fake_charge, fake_customer):
        self._create_autopay_method(fake_customer)
        fake_charge.return_value = StripeObject(id='transaction_id')

        original_outbox_length = len(mail.outbox)

        autopayable_invoice = Invoice.objects.filter(
            subscription=self.subscription)
        date_due = autopayable_invoice.first().date_due

        AutoPayInvoicePaymentHandler().pay_autopayable_invoices(date_due)
        self.assertAlmostEqual(autopayable_invoice.first().get_total(), 0)
        self.assertEqual(len(PaymentRecord.objects.all()), 1)
        self.assertEqual(len(mail.outbox), original_outbox_length + 1)
示例#2
0
 def post(self, request, *args, **kwargs):
     if self.async_response is not None:
         return self.async_response
     if self.trigger_form.is_valid():
         domain = self.trigger_form.cleaned_data['domain']
         AutoPayInvoicePaymentHandler().pay_autopayable_invoices(
             domain=domain)
         statements_url = reverse(DomainBillingStatementsView.urlname,
                                  args=[domain])
         messages.success(
             request,
             mark_safe(
                 f'Successfully triggered autopayments for "{domain}",'
                 f' please check <a href="{statements_url}">billing statements</a>'
                 f' to confirm.'))
         return HttpResponseRedirect(reverse(self.urlname))
     return self.get(request, *args, **kwargs)
示例#3
0
def pay_autopay_invoices():
    """ Check for autopayable invoices every day and pay them """
    AutoPayInvoicePaymentHandler().pay_autopayable_invoices(
        datetime.datetime.today())
示例#4
0
 def _run_autopay(self):
     autopayable_invoice = Invoice.objects.filter(
         subscription=self.subscription)
     date_due = autopayable_invoice.first().date_due
     AutoPayInvoicePaymentHandler().pay_autopayable_invoices(date_due)