I am trying to set up Braintree integration in my Symfony 4 PHP app.
I have used composer to require and install the latest version of Braintree SDK, and have added testing credentials to env file.
Set Up Client
https://developers.braintreepayments.com/start/hello-client/javascript/v3
I then added the client code to my twig template for Drop-in UI.
<div id="dropin-container"></div>
<button id="submit-button">Request payment method</button>
<script>
var button = document.querySelector('#submit-button');
braintree.dropin.create({
authorization: 'CLIENT_TOKEN_FROM_SERVER',
container: '#dropin-container'
}, function (createErr, instance) {
button.addEventListener('click', function () {
instance.requestPaymentMethod(function (err, payload) {
// Submit payload.nonce to your server
});
});
});
</script>
And included this script in the js block
<script src="https://js.braintreegateway.com/web/dropin/1.14.1/js/dropin.min.js"></script>
Set Up Server
https://developers.braintreepayments.com/start/hello-server/php
Next step is to generate a client token
$clientToken = $gateway->clientToken()->generate([
"customerId" => $aCustomerId
]);
and then send token to client etc.
Question
My question is where do I put the server side code in my Symfony 4 app?
Do you create a Braintree.php service in src/Services and put all the Braintree PHP code in there or in the controller, or some in both?