Exemplo n.º 1
0
    def post(self, request, *args, **kwargs):
        past_receipt = Receipt.objects.get(uuid=self.kwargs["uuid"])

        payment_info = {'msg': 'renewed manually'}

        invoice = Invoice(status=Invoice.InvoiceStatus.PROCESSING,
                          site=past_receipt.order_item.invoice.site)
        invoice.profile = past_receipt.profile
        invoice.save()
        invoice.add_offer(past_receipt.order_item.offer)

        processor = PaymentProcessor(invoice)
        processor.renew_subscription(past_receipt, payment_info)

        messages.info(request, _("Subscription Renewed"))
        return redirect(request.META.get('HTTP_REFERER', self.success_url))
Exemplo n.º 2
0
def renew_subscription_task(json_data):
    """
    function to be added or called to a task queue to handle the the a subscription renewal.
    """
    transaction_id = json_data['payload']['id']
    dummy_invoice = Invoice()

    processor = payment_processor(dummy_invoice)
    transaction_detail = processor.get_transaction_detail(transaction_id)

    if not hasattr(transaction_detail, 'subscription'):
        return JsonResponse({})

    past_receipt = Receipt.objects.filter(
        transaction=transaction_detail.subscription.id.text).order_by(
            'created').first()

    payment_info = {
        'account_number':
        transaction_detail.payment.creditCard.cardNumber.text[-4:],
        'account_type':
        transaction_detail.payment.creditCard.cardType.text,
        'full_name':
        " ".join([
            transaction_detail.billTo.firstName.text,
            transaction_detail.billTo.lastName.text
        ]),
        'raw':
        str(json_data)
    }

    invoice = Invoice(status=Invoice.InvoiceStatus.PROCESSING,
                      site=past_receipt.order_item.invoice.site)
    invoice.profile = past_receipt.profile
    invoice.save()
    invoice.add_offer(past_receipt.order_item.offer)

    processor = PaymentProcessor(invoice)
    processor.renew_subscription(past_receipt, payment_info)
Exemplo n.º 3
0
    def test_default_site_id_saved(self):
        invoice = Invoice()
        invoice.profile = CustomerProfile.objects.get(pk=1)
        invoice.save()

        self.assertEquals(Site.objects.get_current(), invoice.site)