Я ищу order_id из razorpay для сохранения в базе данных, как мне получить это в views.py для сохранения в базе данных.
Оплата успешно произведена razerpay, но я хочу получить этот order_id.
Я получаю приведенную ниже ошибку
module ' razorpay.client 'не имеет атрибута' order '
urls.py
app_name = "checkout"
urlpatterns = [
path('payment/', payment, name="payment"),
path('checkout-form', checkout, name='checkout-form'),
]
views.py
def checkout(request):
user = request.user
carts = Cart.objects.filter(user=user)
orders = Order.objects.filter(user=user, ordered=False)
order = orders[0]
amount = int(order.get_totals() * 100)
context = {
"carts": carts,
'order': order,
'amount': amount,
}
return render(request, 'checkout-form.html', context)
def payment(request):
order = Order.objects.get(user=request.user, ordered=False)
amount = int(order.get_totals() * 100)
if request.method == 'POST':
print(" request is post ")
order_amount = amount,
order_currency = "INR",
order_receipt = 'order_rcptid_11'
course = client.order.create(amount=order_amount,
currency=order_currency,
receipt=order_receipt,
payment_capture='0')
# Create the Payment
payment = Payment()
payment.razorpay_order_ID = course['id'][0]
payment.user = request.user
payment.amount = int(order.get_totals())
payment.save()
print("this is the post payment method")
else:
# order = Order.objects.get(user=request.user, ordered=False)
# context = {
# 'order': order
# }
print(" request is get")
return render(request, 'checkout-form.html')
return redirect('checkout:payment/')
оформить заказ . html
<form action="{% url 'checkout:payment' %}" method="POST">
{% csrf_token %}
<script src="https://checkout.razorpay.com/v1/checkout.js"
data-key="######################"
data-amount="{{ amount }}"
data-currency="INR"
data-buttontext="Pay with Razorpay"
data-name="Acme 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-prefill.contact="9999999999"
data-theme.color="#F37254" > </script>
<input type="hidden" custom="Hidden Element" name="hidden">
</form>