def index(request):
    if request.method == "POST":
        form = PayuPaymentForm(request.POST)
        if form.is_valid():
            cd = form.cleaned_data
            buyer = Buyer(cd["buyer_first_name"], cd["buyer_last_name"],
                          cd["buyer_email"], cd["buyer_ip_address"])
            product = Product(cd["product_name"], cd["product_unit_price"],
                              cd["product_quantity"])
            description = cd["purchase_description"]
            continue_url = cd["continue_url"]
            payment_id, follow = DjangoPayU.create_payu_payment(
                buyer, product, description, continue_url)
            request.session["payment_id"] = payment_id

            return redirect(follow)
    else:
        form = PayuPaymentForm(
            initial={
                "buyer_ip_address":
                request.META["REMOTE_ADDR"],
                "continue_url":
                "{}{}".format(
                    settings.BASE_URL,
                    reverse("payment_flow_done"),
                )
            })
    data = {
        "form": form,
    }
    return render(request, "index.html", data)
def index(request):
    if request.method == "POST":
        form = PayuPaymentForm(request.POST)
        if form.is_valid():
            cd = form.cleaned_data
            buyer = Buyer(cd["buyer_first_name"], cd["buyer_last_name"], cd["buyer_email"], cd["buyer_ip_address"])
            product = Product(cd["product_name"], cd["product_unit_price"], cd["product_quantity"])
            description = cd["purchase_description"]
            continue_url = cd["continue_url"]
            payment_id, follow = DjangoPayU.create_payu_payment(buyer, product, description, continue_url)
            request.session["payment_id"] = payment_id

            return redirect(follow)
    else:
        form = PayuPaymentForm(initial={
            "buyer_ip_address": request.META["REMOTE_ADDR"],
            "continue_url": "{}{}".format(
                settings.BASE_URL,
                reverse("payment_flow_done"),
            )
        })
    data = {
        "form": form,
    }
    return render(request, "index.html", data)
Пример #3
0
def _handle_payu_payment(user, ip_address, price_total, purchase, redirect_link):
    buyer = Buyer(user.first_name, user.last_name, user.email, ip_address)
    payu_product = PayUProduct(purchase.product.name, price_total, 1)
    promo_code = purchase.promo_code and purchase.promo_code.code or ''
    payment_id, follow = DjangoPayU.create_payu_payment(
        buyer,
        payu_product,
        'Purchase: {}, product: {}, promo code: {}'.format(purchase.id, purchase.product.id, promo_code),
        redirect_link
    )
    purchase.payu_payment = PayuPayment.objects.get(payment_id=payment_id)
    purchase.payu_payment_link = follow
 def setUp(self):
     self.product = Product("Test product", 100, 2)
     self.buyer = Buyer("first_name", "last_name", "*****@*****.**",
                        "127.0.0.1")
     self.payment_id, self.follow_url = DjangoPayU.create_payu_payment(
         self.buyer, self.product, "test payment", "localhost")
 def test_payment_created(self):
     payment_id, follow_url = DjangoPayU.create_payu_payment(
         self.buyer, self.product, "payment description", "localhost")
     self.assertIsNotNone(payment_id)
     self.assertIsNotNone(follow_url)
 def setUp(self):
     self.product = Product("Test product", 100, 2)
     self.buyer = Buyer("first_name", "last_name", "*****@*****.**", "127.0.0.1")
     self.payment_id, self.follow_url = DjangoPayU.create_payu_payment(self.buyer, self.product, "test payment",
                                                                       "localhost")
 def test_payment_created(self):
     payment_id, follow_url = DjangoPayU.create_payu_payment(self.buyer, self.product, "payment description",
                                                             "localhost")
     self.assertIsNotNone(payment_id)
     self.assertIsNotNone(follow_url)