token error on execute payment request

bidtozeo
Contributor
Contributor

Hey,

I'm facing some problem like this:

 

im trying to integrate paypal payments in my website through server side request. server is written in python and the flow goes like this:

1. asking for token with client_id and client_secret

'https://api.sandbox.paypal.com/v1/oauth2/token'

2. create payment request

"https://api.sandbox.paypal.com/v1/payments/payment/"

with the given token and redirect the client to the approval page with the given url  -

    {
      "href": "https://api.sandbox.paypal.com/v1/payments//cgi-bin/webscr?cmd=_express-checkout&token=EC-60385559L1062554J",
      "rel": "approval_url",
      "method": "REDIRECT"
    },

from the last respone (came back from create payment request).

 

3. now the shown page on the client side is paypal payments page, the client click the button to approve the payment, send request to the server

to execute new request.

on the server side im executing this request:

url =  "https://api.paypal.com/v1/payments/payment/" +paymentId+ "/execute"
headers = {
'Content-Type': 'application/json',
"Authorization": "Bearer" + " " + accessToken,
}

dataPayment ={
"payer_id":payerId
}

 and now i'm facing a problem:

im always getting this response

status 401 

'{"error":"invalid_token","error_description":"The token passed in was not found in the system"}'

i tried using the token from the first request, i tried making another token request before make "execute" request, but im facing the same error over and over.

 

I'll appreciate your help,

thanks in advance.

Login to Me Too
1 ACCEPTED SOLUTION

Accepted Solutions
Solved

MTS_Justin
Moderator
Moderator
Hello,

Look at the URL's that your using.

In the first few requests, requesting authorization and token your submitting the requests to "api.sandbox.paypal.com" but when you go to execute the payment, your submitting them to "api.paypal.com". You can't create a payment request within one environment and then attempt to execute it in another, hence the token error.

Was my post helpful? If so, please give me a kudos!

View solution in original post

Login to Me Too
2 REPLIES 2
Solved

MTS_Justin
Moderator
Moderator
Hello,

Look at the URL's that your using.

In the first few requests, requesting authorization and token your submitting the requests to "api.sandbox.paypal.com" but when you go to execute the payment, your submitting them to "api.paypal.com". You can't create a payment request within one environment and then attempt to execute it in another, hence the token error.

Was my post helpful? If so, please give me a kudos!
Login to Me Too

bidtozeo
Contributor
Contributor

THANKS!!!!!

Login to Me Too

Haven't Found your Answer?

It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.