cometcult / cometcultbraintreebundle Goto Github PK
View Code? Open in Web Editor NEWSymfony 2 Bundle for Braintree's PHP client library
Symfony 2 Bundle for Braintree's PHP client library
Using Symfony2 framework, when creating a customer with a credit card there are no issues, like the following...
$factory = $this->get('comet_cult_braintree.factory');
$customerService = $factory->get('customer');
$createPayment = $customerService->create(array(.....)
However, when attempting to do the same with a MerchantAccount, it will throw the following error:
"ClassNotFoundException: Attempted to load class "Braintree_MerchantAccount" from namespace..."
Code for merchants is the same:
$factory = $this->get('comet_cult_braintree.factory');
$merchantService = $factory->get('MerchantAccount');
$subMerchant = $merchantService->create(array(....)
Any idea on what could be wrong?
I have resolved that by adding factory method in class in vendor/braintree/braintree_php/lib/Braintree/ClientToken.php
public static function factory($attributes)
{
$instance = new self();
return $instance;
}
In controller
$tokenService = $factory->get('clienttoken');
$token = $tokenService::generate();
above code works and generate the token but without modifying the parent class its not possible please help on that.
I want that class to get updated on git so I can download the clienttoken working correctly in updated copy.
Please reply on that.
Thanks
Please tag a version (a stable version would be best if the package has been used in production for a while without issues), so that it's easier to point to the specific version in the composer.json file.
Hi,
Great work !
Just a question. How would you generate the ClientToken. I didn't see with the actual factory how to do.
I added in the factory :
use Braintree_ClientToken;
class BraintreeFactory
{
// ...
public function getClientToken(){
return Braintree_ClientToken::generate();
}
}
this is working (If it is the right way to do):
$braintree = $this->get('braintree.factory');
$transaction = $braintree->get('transaction');
$transaction::sale(array('paymentMethodNonce' => $nonce));
but this is returning "Invalid service ClientToken" :
$braintree = $this->get('braintree.factory');
$braintree_token = $braintree->get('ClientToken');
$braintree_token::generate();
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
According to the documentation provided with bundle, I tried to create transaction search service in the following way:
class: Braintree_TransactionSearch
factory_service: comet_cult_braintree.factory
factory_method: get
arguments: ["transactionSearch"]
I got the error message "Invalid service transactionSearch". I was able to fix this by adding "factory" method to Braintree_TransactionSearch class:
public static function factory($attributes)
{
$instance = new self();
return $instance;
}
Obviously, in this case I have to update this class each time I do "composer update". What I'm doing wrong? Otherwise, can you advice how to override Braintree_TransactionSearch class in order to add "factory" method?
How can I use this Bundle to get a ClientToken (that class doesn't have the method "factory")?
Environment only loads when braintree service is first invoked (or any other braintree-related service you create yourself via custom factory method).
This means that invoking \Braintree_ClientToken::generate()
before invoking comet_cult_braintree.factory
will throw an exception with message "environment needs to be set."
I have tried implementing a service as described in the doc (with updated syntax for symfony 2.8):
braintree_transaction:
class: \Braintree\Transaction
factory: ["@comet_cult_braintree.factory", get]
arguments: ["customer"]
$transactionService = $this->get('braintree_transaction');
$result = $transactionService::sale( ... );
But unfortunately it gives me this error:
Warning: Missing argument 2 for Braintree\Customer::sale()
Which seems to mean that the service does not take account of the class parameter.
I use version 3.16
of the braintree_php
bundle, in which the classes are not prepended with "Braintree_" anymore. There are class aliases though, which means that I can use both:
class: \Braintree\Transaction
or class: \Braintree\Braintree_Transaction
Both ways give the same error. Am I doing something wrong?
P.S.:
The following works:
$factory = $this->get('comet_cult_braintree.factory');
$transactionService = $factory->get('transaction');
$result = $transactionService::sale( ... );
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.