Razorpay.errors.BadRequestError: Сумма не является/не является обязательной и не должна быть отправлена
I am integrating razorpay payment gateway in my django project and dont know why i am getting this error.:-Amount is/are not required and should not be sent. i checked my whole code but did not find any solution
This is Traceback, In traceback window i am getting Exception Value: Amount is/are not required and should not be sent
Traceback (most recent call last):
File "D:\Project 3\test\lib\site-packages\django\core\handlers\exception.py", line 47, in inner
response = get_response(request)
File "D:\Project 3\test\lib\site-packages\django\core\handlers\base.py", line 181, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "D:\Project 3\payment\paymentapp\views.py", line 13, in index
payment = client.order.create({'Amount':amount, 'currency':'INR','payment_capture':'1'})
File "D:\Project 3\test\lib\site-packages\razorpay\resources\order.py", line 71, in create
return self.post_url(url, data, **kwargs)
File "D:\Project 3\test\lib\site-packages\razorpay\resources\base.py", line 20, in post_url
return self.client.post(url, data, **kwargs)
File "D:\Project 3\test\lib\site-packages\razorpay\client.py", line 155, in post
return self.request('post', path, data=data, **options)
File "D:\Project 3\test\lib\site-packages\razorpay\client.py", line 136, in request
raise BadRequestError(msg)
Exception Type: BadRequestError at /
Exception Value: Amount is/are not required and should not be sent
This is Views.py
from django.shortcuts import render
import razorpay
from .models import coffee
# Create your views here.
def index(request):
if request.method=='POST':
Name = request.POST.get("Name")
amount = int(request.POST.get("Amount")) * 100
client = razorpay.Client(auth=("rzp_test_YhfEhfejrkkjdkfju","t5MRPkjfijdh23845kejkej"))
payment = client.order.create({'Amount':amount, 'currency':'INR','payment_capture':'1'})
print(payment)
Coffee = coffee(Name=Name, Amount=amount , payment_id = payment['id'] )
return render(request,'index.html',{'payment':payment})
return render(request,'index.html')
def success(request):
if request.method == 'POST':
a = request.POST
print(a)
return render(request,"success.html")
This is Index.html
{% extends 'base.html' %}
{% block content %}
<div class="col-6 mx-auto">
<form method="POST">
{% csrf_token %}
<div class="mb-3">
<label class="form-label">Enter Name</label>
<input type="text" name="Name" class="form-control">
</div>
<div class="mb-3">
<label class="form-label">Enter Amount</label>
<input type="number" name="Amount" class="form-control">
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
</div>
{% if payment %}
<div class="text-center mx-auto">
<form action="/success" method="POST">
<script
src="https://checkout.razorpay.com/v1/checkout.js"
data-key="rzp_test_YhfEhfejrkkjdkfju"
data-amount="{{payment.Amount}}"
data-currency="INR"
data-order_id="{{payment.id}}"
data-buttontext="Pay with Razorpay"
data-name="Coffee Corp"
data-description="A Wild Sheep Chase is the third novel by Japanese author Haruki Murakami"
data-image="https://example.com/your_logo.jpg"
data-prefill.name="Gaurav Kumar"
data-prefill.email="gaurav.kumar@example.com"
data-theme.color="#F37254"
></script>
<input type="hidden" custom="Hidden Element" name="hidden">
</form>
</div>
{% endif %}
{% endblock %}
Я думаю, что интеграция razorpay очень чувствительна к регистру, я не знаю технической части, почему это происходит с razorpay, но это решение работает для меня, Что я сделал
. Я изменил переменную, которая принимает данные post в lowercase.
def index(request):
if request.method=='POST':
name = request.POST.get("name")
amount = int(request.POST.get("Amount")) * 100 # I wrote amount variable in lowercase
client = razorpay.Client(auth=("rzp_test_YhfE7ZnBpKrrDq","t5MRPBtnWi57MoyjDvV7nJQO"))
payment = client.order.create({'amount':amount, 'currency':'INR','payment_capture':'1'})
print(payment)
Coffee = coffee(name=name, amount=amount , payment_id = payment['id'] )#In this also i used lowercase for variables.
return render(request,'index.html',{'payment':payment})
return render(request,'index.html')
def success(request):
if request.method == 'POST':
a = request.POST
print(a)
return render(request,"success.html")