Search code examples
djangodjango-viewspayment-gatewayrazorpay

I’m getting an error while importing Razorpay in Django


I am integrating the Razorpay payment gateway in a Django project, but I am getting an error while importing razorpay as:

Import razorpay could not be resolved

Code

from django.shortcuts import render

import razorpay  # Here I am getting an error

from .models import coffee

This is my full code:

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 my terminal output:

File "D:\Project 3\payment\paymentapp\urls.py", line 18, in <module>
from .import views
File "D:\Project 3\payment\paymentapp\views.py", line 3, in <module>
import razorpay
ModuleNotFoundError: No module named 'razorpay'

Solution

  • There are a few basic things you have to know before using the Razorpay gateway in your project. First is your amount. It is considered in paisa, so you have to multiply it by 100 to convert it in to rupee. As I can see, you are multiplying by 10 to amount next.

    If you want to use Razorpay, you must use:

    pip install razorpay
    

    And I will also recommend you to read the full documentation for using it, because it seems that you are missing a lot of things. Like you have to write JavaScript code handle, etc.:

    About Standard Web Checkout Integration