Reputation: 1061
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
Upvotes: 2
Views: 1684
Reputation: 1061
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.
Upvotes: 1