Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do you go about generating a ClientToken? #12

Closed
scyrma opened this issue Nov 3, 2015 · 7 comments
Closed

How do you go about generating a ClientToken? #12

scyrma opened this issue Nov 3, 2015 · 7 comments

Comments

@scyrma
Copy link

scyrma commented Nov 3, 2015

Hi,

This is not a bug per-se, but looking how the code only returns classes with factory methods, I'm curious to know what is the designed way of using this bundle to call Braintree_ClientToken::generate()?

Thanks

@flomerz
Copy link

flomerz commented Nov 9, 2015

+1
I also want to know how to do this.

For now I use:

$this->get('comet_cult_braintree.factory');
\Braintree_ClientToken::generate()

The factory call is essential to load the configs.

@mamartins
Copy link

+1

grEvenX added a commit that referenced this issue Nov 12, 2015
Fix #12 - autoconfiguring Braintree without class instantiation
@grEvenX grEvenX mentioned this issue Nov 12, 2015
@grEvenX
Copy link
Member

grEvenX commented Nov 23, 2015

Can any of you confirm if the solution in #12 is ok for you (@mamartins, @flomerz, @scyrma) ?

@mamartins
Copy link

yes, I can call the method, and I have to do so in many functions that do not have factory, and sometimes even with some that do have factory but require parameters

@grEvenX
Copy link
Member

grEvenX commented Nov 23, 2015

@mamartins I mean with change I added in 4621db0, are you able use the code without having to get the factory before calling the static methods.

You should now be able to just call the following code as long as the CometCultBraintreeBundle is loaded:

\Braintree_ClientToken::generate()

@mamartins
Copy link

ah, sorry. yes! :)

but I was before because I am injecting the factory in some services so the settings are loaded to the hole app.

@itaelle itaelle mentioned this issue Jan 13, 2016
@marianflorin
Copy link

marianflorin commented Aug 3, 2016

@grEvenX - This solution doesn't work, at least for me. From what I tested the calls in https://github.com/cometcult/CometCultBraintreeBundle/blob/4621db02708e2ad1c65733d3dd3cb6e538d7e510/DependencyInjection/CometCultBraintreeExtension.php are executed only when the Symfony cache is generated. These calls are setting a PHP static variable, so they should be executed on every page load. What worked for me was to override the boot method in app/AppKernel.php file, like below:

public function boot()
{
parent::boot();

\Braintree_Configuration::environment($this->getContainer()->getParameter('braintree.environment'));
\Braintree_Configuration::merchantId($this->getContainer()->getParameter('braintree.merchant_id'));
\Braintree_Configuration::publicKey($this->getContainer()->getParameter('braintree.public_key'));
\Braintree_Configuration::privateKey($this->getContainer()->getParameter('braintree.private_key'));
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants