So I have an interface developed and working with Braintree but they have since updated their api to go from Class level to an instance style interface. They gave the following to show the old and the new style of code. The problem is the old code went in the \app\Providers\AppServiceProvider.php file and I can't figure out where the new code should go. Let me first show you the code example that Braintree provides.
Old Class-Level style in AppServiceProvider
Braintree_Configuration::environment('sandbox');
Braintree_Configuration::merchantId('use_your_merchant_id');
Braintree_Configuration::publicKey('use_your_public_key');
Braintree_Configuration::privateKey('use_your_private_key');
New Instance Style code (Where does this code go?)
$gateway = new Braintree_Gateway([
'environment' => 'sandbox',
'merchantId' => 'use_your_merchant_id',
'publicKey' => 'use_your_public_key',
'privateKey' => 'use_your_private_key'
]);
So I have a trait that contains all the Braintree API calls. For example this is a method in the trait that I used with the old Class style code
public function btGetClientToken($customerID)
{
return \Braintree_ClientToken::generate([
"customerId" => $customerID,
"merchantAccountId" => config('services.braintree.merchant_account_id')]);
}
And here is the same method for the new instance style interface
public function btGetClientToken($customerID)
{
return $gateway()->clientToken()->generate([
"customerId" => $customerID,
"merchantAccountId" => config('services.braintree.merchant_account_id')]);
}
but of course the problem is I don't know where I am supposed to put the first block of code which I assume I am supposed to make a globally accessible variable ($gateway)? If I add the first block of code to the top of the new method then everything works.
It does not seem like I should have to create a new instance inside every method of the trait. I tried to get help from them but it seems no one is familiar with Laravel and their docs have no Laravel references to help.
TIA