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 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 setUp(self): self.product = Product("Test product", 100, 2) self.buyer = Buyer("first_name", "last_name", "*****@*****.**", "127.0.0.1")
def test_create_product_with_wrong_string_unit_price(self): with self.assertRaises(DjangoPayException) as e: Product("Test product", "10.4", 2) self.assertEqual(ErrorMessages.NOT_VALID_UNIT_PRICE, e.exception.message)
def test_create_product_with_wrong_string_quantity(self): with self.assertRaises(DjangoPayException) as e: Product("Test product", 100, "3.4") self.assertEqual(ErrorMessages.NOT_VALID_QUANTITY, e.exception.message)
def test_create_product(self): product = Product("Test product", 100, 2) self.assertEqual("Test product", product.name) self.assertEqual(2, product.quantity) self.assertEqual(100, product.unit_price)