I am trying to create my client but am confused on what to do with all the javascript code which is being given to me. I want to create a Drop-in UI. I have successfully been able to generate a client token by using $clientToken = $gateway->clientToken()->generate();
I am not using a customerID to keep track of customers.
My question is, in the step Get a client token
in the docs here. Where do I put the javascript code now? I have no idea where to put:
braintree.dropin.create({
// Step three: get client token from your server, such as via
// templates or async http request
authorization: CLIENT_TOKEN_FROM_SERVER,
container: '#dropin-container'
}, (error, dropinInstance) => {
// Use `dropinInstance` here
// Methods documented at https://braintree.github.io/braintree-web-drop-in/docs/current/Dropin.html
});
And also in the javascript it says Use dropinInstance here
How do I make a dropinInstance? If anyone could tell me how to complete the client set up, that would be fantastic
Here is my code so far:
index.php
<?php require_once('Braintree.php');
$gateway = new Braintree\Gateway([
'environment' => 'sandbox',
'merchantId' => 'use_your_merchant_id',
'publicKey' => 'use_your_public_key',
'privateKey' => 'use_your_private_key'
]);
$clientToken = $gateway->clientToken()->generate();
?>
<head>
<meta charset="utf-8">
<script src="https://js.braintreegateway.com/web/dropin/1.25.0/js/dropin.min.js"></script>
</head>
<body>
<!-- Step one: add an empty container to your page -->
<div id="dropin-container"></div>
<script type="text/javascript">
// Step two: create a dropin instance using that container (or a string
// that functions as a query selector such as `#dropin-container`)
braintree.dropin.create({
container: document.getElementById('dropin-container'),
// ...plus remaining configuration
}, (error, dropinInstance) => {
// Use `dropinInstance` here
// Methods documented at https://braintree.github.io/braintree-web-drop-in/docs/current/Dropin.html
});
</script>
</body>