Reputation: 26
I have tried to integrate paypal subscription payment system with my django application. But there are some issue in API calling from backend.
Option 1:
url = "https://api.sandbox.paypal.com/v1/billing/subscriptions/I-VL5K5767RB6S"
headers = {'Authorization': 'Bearer Ae2UGxdThO9xMgFCSJihnhqDrv7zqTSngh6ILNc3imd6RrOM-GovHN_R0jFVL80Qm5oKhDi6rg715G9_', 'Content-Type': 'application/json'}
response = requests.get(url, headers=headers)
Response to #1:
headers {'Cache-Control': 'max-age=0, no-cache, no-store, must-revalidate', 'Content-Length': '83', 'Content-Type': 'application/json', 'Date': 'Fri, 29 May 2020 08:57:14 GMT', 'Paypal-Debug-Id': '50867574d2a79'}
status_code 401
response text {"error":"invalid_token","error_description":"Token signature verification failed"}
Option 2:
url = "https://api.sandbox.paypal.com/v1/billing/subscriptions/I-VL5K5767RB6S"
headers = {'Authorization': 'Ae2UGxdThO9xMgFCSJihnhqDrv7zqTSngh6ILNc3imd6RrOM-GovHN_R0jFVL80Qm5oKhDi6rg715G9_', 'Content-Type': 'application/json'}
response = requests.get(url, headers=headers)
Response to #2:
{'Cache-Control': 'max-age=0, no-cache, no-store, must-revalidate', 'Content-Length': '244', 'Content-Type': 'application/json', 'Date': 'Fri, 29 May 2020 08:58:50 GMT', 'Paypal-Debug-Id': '3e1641470db08'}
status_code 401
response text {"name":"AUTHENTICATION_FAILURE","message":"Authentication failed due to invalid authentication credentials or a missing Authorization header.","links":[{"href":"https://developer.paypal.com/docs/api/overview/#error","rel":"information_link"}]}
How can I get a successful response?
Upvotes: 1
Views: 754
Reputation: 30379
Option #1 is the correct format for on Oauth2 Bearer token call. However, this:
Ae2UGxdThO9xMgFCSJihnhqDrv7zqTSngh6ILNc3imd6RrOM-GovHN_R0jFVL80Qm5oKhDi6rg715G9_
Is not an Oauth2 access_token. It is instead a PayPal REST App client ID, presumably for sandbox mode, which is one of the things you need to first use to obtain the appropriate access_token.
See PayPal's REST API documentation for information how to pass those Oauth 2.0 credentials and obtain the required access_token:
Note that access_tokens are typically valid for 9 hours, and after one expires you will need to generate a new one with that same call.
Upvotes: 1