razorpay / razorpay-python

Razorpay Python SDK
https://pypi.python.org/pypi/razorpay
MIT License
153 stars 81 forks source link

Amount exceeds maximum amount allowed Error in Razorpay in python #241

Closed SachitSankhe closed 1 year ago

SachitSankhe commented 1 year ago

Please any one help me in this, I make one application that accepts payment from users. I use the Razorpay payment gateway.

here my payment code:

@api_view(['GET', 'POST'])
def bookTicket(request):
    if request.method == "POST":
        data = ({
            'user': User.objects.get(username=request.POST.get('user')).pk,
            'location': Location.objects.get(name=request.POST.get('location')).pk,
            'date': request.POST.get('date'),
            'quantity': request.POST.get('quantity'),
            'amount': request.POST.get('amount'),
        })
        ticket = TicketSerializer(data=data)
        if ticket.is_valid():
            ticket.save()
            # Getting all the items from the frontend after validation
            user = User.objects.get(username=request.POST.get('user'))
            location = Location.objects.get(name=request.POST.get('location'))
            date = request.POST.get('date')
            quantity = request.POST.get('quantity')
            amount = request.POST.get('amount')

            # Creating Razorpay Client and Order id
            client = razorpay.Client(
                auth=(settings.RAZORPAY_PUBLIC_KEY, settings.RAZORPAY_SECRET_KEY))

            client.set_app_details(
                {"title": "Django", "version": "str(1.8.17)"})

            data = {'amount': int(amount)*100,
                    'currency': 'INR',
                    'payment_capture': '1'}
            payment = client.order.create(data=data)

            print(payment)

            # Saving everything in the Ticket Model
            tempTicket = Ticket(user=user, location=location,
                                date=date, quantity=quantity, amount=amount, payment_id=payment['id'])
            tempTicket.save()

            Payment = {
                'KEY_ID': settings.RAZORPAY_PUBLIC_KEY,
                'id': payment['id'],
                'amount': payment['amount'],
            }

            return render(request, 'payment.html', {'Payment': Payment})

        return Response(ticket.errors)

and I use Test card money from https://razorpay.com/docs/payments/payments/test-card-upi-details/

my payment page load and work well, but all the time my payment fails. The page where razorpay asks whether to make the payment success or a failure is not getting prompted and it is showing a page like

image

and a new webpage is prompted like

image

Is there any problem with the code that I have written or something of a bug in razorpay-python

ankitdas13 commented 1 year ago

@SachitSankhe Sorry for the delay . Is it possible that your amount is greater than 9 lakh? Have you tried a static amount ? In case the issue has not been resolved, please let us know so that we can assist you.

SachitSankhe commented 1 year ago

Yes now it has started working I believe it was something in the API keys that were generated. I regenerated them and used them