Q:

Braintree: issues with getting client token ID

I'm trying to connect to Braintree payment system and get the client token ID with the following code:
<script src="https://js.braintreegateway.com/js/braintree-2.29.0.min.js"></script>
<script>
clientToken = <?php echo(Braintree_ClientToken::generate()); ?>;
alert(clientToken);

braintree.setup(clientToken, "dropin", {
  container: "payment-form"
});
</script>

But the code fails to fetch the client token. Please help me to solve this issue.

A:

This will help you to get Client token:
<script src="https://js.braintreegateway.com/v2/braintree.js"></script>
<?php
$clientToken = Braintree_ClientToken::generate(); // generate token
?>
<script>
clientToken = "<?php echo $clientToken;?>";
alert(clientToken);
braintree.setup(clientToken, "dropin", {
  container: "payment-form"
});
</script>

You need to use quotes for clientToken in javascript.

