Getting, storing, and refreshing PayPal access token in Laravel

江枫思渺然 提交于 2021-01-05 07:16:17

问题


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:

  1. Does Omnipay manage access tokens? If so, is there documentation on how that works?
  2. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!