Ejemplo n.º 1
0
    def post(self, request, *args, **kwargs):
        context = super().get_context_data(**kwargs)
        invoice = get_purchase_invoice(request.user,
                                       get_site_from_request(request))

        if not invoice.order_items.count(
        ) or invoice.status == Invoice.InvoiceStatus.CART:
            messages.info(request, _("Cart changed while in checkout process"))
            return redirect('vendor:cart')

        credit_card_form = CreditCardForm(request.POST)
        if request.POST.get('same_as_shipping') == 'on':
            billing_address_form = BillingAddressForm(
                instance=invoice.shipping_address)
            billing_address_form.data = billing_address_form.initial
            billing_address_form.is_bound = True
        else:
            billing_address_form = BillingAddressForm(request.POST)

        if not (billing_address_form.is_valid()
                and credit_card_form.is_valid()):
            processor = payment_processor(invoice)
            context['billing_address_form'] = billing_address_form
            context['credit_card_form'] = credit_card_form
            return render(request, self.template_name,
                          processor.get_checkout_context(context=context))
        else:
            billing_address_form.full_clean()
            credit_card_form.full_clean()
            request.session[
                'billing_address_form'] = billing_address_form.cleaned_data
            request.session['credit_card_form'] = credit_card_form.cleaned_data
            return redirect('vendor:checkout-review')
Ejemplo n.º 2
0
    def test_view_payment_success(self):
        self.invoice.status = Invoice.InvoiceStatus.CHECKOUT
        self.invoice.save()
        Payment.objects.all().delete()
        form_data = {
            'billing_address_form': {
                'billing-name': 'Home',
                'billing-company': 'Whitemoon Dreams',
                'billing-country': 840,
                'billing-address_1': '221B Baker Street',
                'billing-address_2': '',
                'billing-locality': 'Marylebone',
                'billing-state': 'California',
                'billing-postal_code': '90292'
            },
            'credit_card_form': {
                'full_name': 'Bob Ross',
                'card_number': '5424000000000015',
                'expire_month': '12',
                'expire_year': '2030',
                'cvv_number': '900',
                'payment_type': '10'
            }
        }

        billing_address = BillingAddressForm(form_data['billing_address_form'])
        billing_address.is_bound = True
        billing_address.is_valid()
        payment_info = CreditCardForm(form_data['credit_card_form'])
        payment_info.is_bound = True
        payment_info.is_valid()

        session = self.client.session
        session['billing_address_form'] = {
            f'billing-{key}': value
            for key, value in billing_address.cleaned_data.items()
        }
        session['credit_card_form'] = payment_info.cleaned_data
        session.save()

        response = self.client.post(self.view_url)

        self.assertEquals(self.invoice.payments.all().count(),
                          Payment.objects.filter(invoice=self.invoice).count())
Ejemplo n.º 3
0
    def test_view_payment_success(self):
        Payment.objects.all().delete()
        form_data = { 
            'billing_address_form': 
                {'name':'Home','company':'Whitemoon Dreams','country':'581','address_1':'221B Baker Street','address_2':'','locality':'Marylebone','state':'California','postal_code':'90292'}, 
            'credit_card_form': 
                {'full_name':'Bob Ross','card_number':'5424000000000015','expire_month':'12','expire_year':'2030','cvv_number':'900','payment_type':'10'}
            }

        billing_address = BillingAddressForm(form_data['billing_address_form'])
        billing_address.is_bound = True
        billing_address.is_valid()
        payment_info = CreditCardForm(form_data['credit_card_form'])
        payment_info.is_bound = True
        payment_info.is_valid()

        session = self.client.session
        session['billing_address_form'] = billing_address.cleaned_data
        session['credit_card_form'] = payment_info.cleaned_data
        session.save()

        response = self.client.post(self.view_url)

        self.assertRedirects(response, reverse('vendor:purchase-summary', kwargs={'pk': 1}))
Ejemplo n.º 4
0
    def post(self, request, *args, **kwargs):
        receipt = Receipt.objects.get(uuid=self.kwargs["uuid"])
        payment_form = CreditCardForm(request.POST)

        if not payment_form.is_valid():
            messages.info(request, _("Invalid Card"))
            return redirect(request.META.get('HTTP_REFERER', self.success_url))

        processor = PaymentProcessor(receipt.order_item.invoice)
        processor.set_payment_info_form_data(request.POST, CreditCardForm)
        processor.subscription_update_payment(receipt)

        if not processor.transaction_submitted:
            messages.info(
                request,
                _(f"Payment gateway error: {processor.transaction_message.get('message', '')}"
                  ))
            return redirect(request.META.get('HTTP_REFERER', self.success_url))

        messages.info(request, _(f"Success: Payment Updated"))
        return redirect(request.META.get('HTTP_REFERER', self.success_url))