razorpay / razorpay-python

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

BadRequestError when creating a plan #84

Closed ShipraShalini closed 1 year ago

ShipraShalini commented 4 years ago

When trying to create a plan, I get the following error: BadRequestError: The requested URL was not found on the server.

The code snippet:

def create(period, interval, name, amount, description, notes, currency):
    client = razorpay.Client(auth=(RAZORPAY_KEY_ID, RAZORPAY_SECRET))
    return client.plan.create(
        {
            "period": period,
            "interval": interval,
            "item": {
                "name": name,
                "amount": amount,
                "currency": currency,
                "description": description,
            },
            "notes": notes,
        }
    )

So I tried to create a plan by directly calling the API using the Postman collections downloaded from the API Reference. I added the auth creds as header, but I still get the same error.

image

Is there a way to fix this? Am I doing anything wrong?

soheshdoshi commented 4 years ago

You need to just add item_id in your JSON.

def create(period, interval, name, amount, description, notes, currency):
    client = razorpay.Client(auth=(RAZORPAY_KEY_ID, RAZORPAY_SECRET))
    return client.plan.create(
        {
            "item_id": "YOUR_ITEM_ID",
            "period": "weekly",
            "interval": 1,
            "item": {
                "name": "Test plan - Weekly",
                "amount": 69900,
                "currency": "INR",
                "description": "Description for the test plan"
            },
            "notes": {
                "notes_key_1": "Tea, Earl Grey, Hot",
                "notes_key_2": "Tea, Earl Grey… decaf."
            }
        })

checkout this @ShipraShalini

djb4ai commented 3 years ago

@soheshdoshi Where do I find the item id? When I create a plan on the Razorpay dashboard it creates an item_id by itself same for the curl request. if I pass any random item_id it says- razorpay.errors.BadRequestError: The id provided does not exist

rahul6612 commented 3 years ago

after passing order_id i am getting the same error The id provided does not exist WHY?

sanzzzay commented 2 years ago

Hey @ShipraShalini - couple of things we can try here.

  1. Check this post - https://github.com/razorpay/razorpay-magento/issues/112 - [Some port issue]
  2. In Test mode, generate the API keys and add it to POSTMAN like this: https://razorpay.com/docs/assets/images/api/postman_basic_auth.gif , it worked for me. 😸
  3. To test through the client code - check this. Before that, ponder over here too
  4. If 3rd one didn't work let me know. Even I need to test the python library code. PS: I didn't understand why folks mentioned to add item_id, but it's auto generated all we need is to give proper params. Edit - 3rd method worked fine for me.
ankitdas13 commented 1 year ago

Tested this from my end and it is working #112 . Closing this issue for now. if you need any help then please let us know