Reputation: 9
I am trying to integrate Razorpay OAuth to exchange an authorization_code for tokens. Following the Razorpay documentation, I made the following API call:
-H "Content-type: application/json" \
-d '{
"client_id": "<YOUR_CLIENT_ID>",
"client_secret": "<YOUR_CLIENT_SECRET>",
"grant_type": "authorization_code",
"redirect_uri": "http://example.com/razorpay_callback",
"code": "def50200d844dc80cc44dce2c665d07a374d76802",
"mode": "test"
}'
I substituted <YOUR_CLIENT_ID> with the Key ID and <YOUR_CLIENT_SECRET> with the Key Secret generated under Settings > API Key in Razorpay's dashboard. However, the request always returns:
{
"error": {
"description": "Access denied"
}
}
Python Code for API Call: Here's how I implemented the API call in Python:
def fetch_razorpay_token(authorization_code, redirect_uri=None):
import requests
import urllib.parse
url = "https://auth.razorpay.com/token"
static_redirect_uri = "http://localhost:3000/payment"
decoded_authorization_code = urllib.parse.unquote(authorization_code)
payload = {
"client_id": "<MY_CLIENT_ID>",
"client_secret": "<MY_CLIENT_SECRET>",
"grant_type": "authorization_code",
"redirect_uri": static_redirect_uri,
"code": decoded_authorization_code,
"mode": "test",
}
headers = {"Content-type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
if response.status_code == 200:
return response.json()
else:
print("Failed:", response.status_code, response.text)
return None
Observations:
Questions:
Upvotes: 0
Views: 28