2

I was able to request an access token at https://api.sandbox.paypal.com/v1/oauth2/token and send a POST to create a new payment at https://api.sandbox.paypal.com/v1/payments/payment using the given access token. Those two APIs ran without any problem.

But when performing a GET to the payment_id that I created also using above access token, it gave me 401 https://api.sandbox.paypal.com/v1/payments/payment/PAY-XXXX. This is the step where I want to execute the payment at my return_url.

I'm using the PayPal PHP SDK downloaded from https://github.com/paypal/PayPal-PHP-SDK. Everything is still in sandbox mode. The client_id and secret are sandbox credentials.

Also, I have tried running cURL to above payment_id's URL yet it gave HTTP/1.1 401 Unauthorized as well.

curl -v https://api.sandbox.paypal.com/v1/payments/payment/PAY-XXXX 
-H 'Content-Type: application/json' 
-H 'Authorization: Bearer ACCESS_TOKEN'

According to the documentation, 401 means invalid or expired access token but I don't think it applied here because the previous POST command could run successfully.

UPDATE #1: In fact, I have tried running the whole flow (request access_token, post payment, get payment and execute) using cURL and did not have problem. So the problem must be with the PHP code

2
  • Can you try running the samples, and make sure they are working fine ? Commented Mar 9, 2015 at 4:01
  • For those that come later: Make sure to use the merchant email address that corresponds to the current clientID and clientSecret, otherwise you will get the 401 error. Commented Mar 26, 2016 at 3:38

1 Answer 1

1

There was one typo in the PHP which gave me wrong access_token. Interestingly, the POST method to create new payment was still allowed that confused me.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.