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 get_status(request, payment_id):
    try:
        payment_status = DjangoPayU.get_payment_status(payment_id)
    except DjangoPayException:
        return HttpResponseBadRequest()

    data = {
        "status": payment_status
    }
    return JsonResponse(data)

    #
    # def start_payment(request):
    # json_str = request.body.decode('utf-8')
    # data = json.loads(json_str)
    #
    # user_id = data.get("user_id")
    # quantity = data.get("quantity")
    #     price = data.get("price")
    #     title = data.get("title")
    #
    #     try:
    #         User.objects.get(pk=user_id)
    #     except User.DoesNotExist:
    #         raise BadParamValueException(ErrorMessages.USER_NOT_FOUND)
    #
    #     user = User.objects.get(pk=user_id)
    #
    #
    #     response = {
    #         "order_id": new_payment.uid,
    #         "payu_id": new_payment.payu_id,
    #         "follow": new_payment.payu_url,
    #     }
    #     return JsonResponse(response)
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 get_status(request, payment_id):
    try:
        payment_status = DjangoPayU.get_payment_status(payment_id)
    except DjangoPayException:
        return HttpResponseBadRequest()

    data = {"status": payment_status}
    return JsonResponse(data)
예제 #5
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 test_get_payment_status_for_failed_payment(self):
     PayuPayment.objects.filter(pk=self.payment_id).update(
         payment_status=PaymentStatus.STATUS_FAILED)
     self.assertEqual(DjangoPayU.get_payment_status(self.payment_id),
                      PaymentStatus.STATUS_FAILED)
 def test_get_payment_status_for_started_payment(self):
     self.assertEqual(DjangoPayU.get_payment_status(self.payment_id),
                      PaymentStatus.STATUS_STARTED)
 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 test_get_payment_status_for_completed_payment(self):
     PayuPayment.objects.filter(pk=self.payment_id).update(payment_status=PaymentStatus.STATUS_COMPLETED)
     self.assertEqual(DjangoPayU.get_payment_status(self.payment_id), PaymentStatus.STATUS_COMPLETED)
 def test_get_payment_status_for_started_payment(self):
     self.assertEqual(DjangoPayU.get_payment_status(self.payment_id), PaymentStatus.STATUS_STARTED)
 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)