2

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?

Designer
  • 477
  • 2
  • 12
  • What do you get if you `var_dump(getenv('sandbox_XXXX-XXXXx_XXX_XXX-XXX'));`? – aynber Apr 15 '19 at 17:26
  • @aynber - I get `bool(false)` – Designer Apr 15 '19 at 17:31
  • Then you'll need to figure out why it's returning false, and what it should have instead. – aynber Apr 15 '19 at 17:33
  • That's an obvious one lol - I have followed this exactly (https://developer.gocardless.com/getting-started/api/making-your-first-request/) so should not be getting any errors? – Designer Apr 15 '19 at 17:34
  • It doesn't tell you how to get the access token from the clipboard to the environment in the documentation, so it's missing a step or two. – aynber Apr 15 '19 at 17:43

1 Answers1

2

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.