问题
I am currently using Omnipay's PayPal library in Laravel to interact with the PayPal API. Paypal requires an application to use its client id and secret to retrieve an access token. I've stored the client id and secret in ENV variables.
I'm trying to figure out 2 things:
- Does Omnipay manage access tokens? If so, is there documentation on how that works?
- If not, I would like to form the below curl example in PHP so I can function to run either on a cron or on a trigger
Documentation on PayPal's curl example: https://developer.paypal.com/docs/api/get-an-access-token-curl/
I've had trouble figuring out how to translate this commandline curl call into a PHP curl call:
curl -v https://api-m.sandbox.paypal.com/v1/oauth2/token \
-H "Accept: application/json" \
-H "Accept-Language: en_US" \
-u "client_id:secret" \
-d "grant_type=client_credentials"
My current attempt at the whole thing involves a method that would check if the access token is expired, and refresh it if not (otherwise, do nothing). I would run this method as an hourly cron job as well as being called prior to making the API call.
来源:https://stackoverflow.com/questions/65013437/getting-storing-and-refreshing-paypal-access-token-in-laravel