Search code examples
phpyiibraintree

Configure Braintree in a Yii 2 project


I have downloaded the Braintree for PHP and copied all the content to the directory vendor/braintree (created by me), but I do not know how to declare its classes for being available to the whole project.

The configuration code is very simple. Could I put it together with the declaration code too?

Braintree_Configuration::environment('sandbox');
Braintree_Configuration::merchantId('myMerchandId');
Braintree_Configuration::publicKey('myPublicKey');
Braintree_Configuration::privateKey('myPrivateKey');

Can someone give a suggestion?


Solution

  • You can, but probably shouldn't. The best way to handle that stuff is to wrap it in a Yii Component and then configure the component with API keys, etc.

    Doing so makes it far easier to keep your API keys out of your repo, which is good practice (especially for payment systems :-)