Search code examples
phpgocardless

Uncaught exception 'Exception' with message 'Option `access_token` can only be a string.'


I have followed the GoCardless API 'Getting Started' instructions exactly but getting this error when trying to run a simple script

"Uncaught exception 'Exception' with message 'Option access_token can only be a string.'"

require '../../vendor/autoload.php';

$client = new \GoCardlessPro\Client([
    // We recommend storing your access token in an environment variable for security, but you could include it as a string directly in your code
    'access_token' => getenv('sandbox_XXXX-XXXXx_XXX_XXX-XXX'),
    // Change me to LIVE when you're ready to go live
    'environment' => \GoCardlessPro\Environment::SANDBOX
]);

What have i done wrong?


Solution

  • As you already knows PHP is not finding the environment variable. That's why you got false when var dumping the getenv function.

    Give it try to this library if you are not using it. It adds a abstraction layer to the environment variables and makes it easy to anyone use them in a project.

    https://github.com/vlucas/phpdotenv

    Hope I helped.