Reputation: 778
I am attempting to follow the basics of Braintree integration and I am running into stumbling block after stumbling block seeing the flow in action.
Right now I am trying to take a look at the dropin UI for Braintree and using their code, copy and pasted I am running into
"braintree is not defined"
when the braintree.dropin.create is executed.
<div id="dropin-container"></div>
<button id="submit-button">Purchase</button>
<script src="https://js.braintreegateway.com/web/dropin/1.14.1/js/dropin.min.js"></script>
<script>
var submitButton = document.querySelector('#submit-button');
braintree.dropin.create({
authorization: 'CLIENT_AUTHORIZATION',
container: '#dropin-container'
}, function (err, dropinInstance) {
if (err) {
// Handle any errors that might've occurred when creating Drop-in
console.error(err);
return;
}
submitButton.addEventListener('click', function () {
dropinInstance.requestPaymentMethod(function (err, payload) {
if (err) {
// Handle errors in requesting payment method
}
// Send payload.nonce to your server
});
});
});
</script>
Does anyone have any recommendations on how to get this dropin working?
Edit: As far as development stack is concerned I am creating this in a Django environment and testing with both the JavaScript library and the Python library. This particular implementation I am attempting to use the javascript library.
Upvotes: 2
Views: 1473
Reputation: 461
I had a similar issue and moved the code for dropin.create to happen once the page was loaded and problem went away
Upvotes: 0
Reputation: 778
I solved my own issue by starting over and using this code:
https://developers.braintreepayments.com/start/hello-client/javascript/v3
<head>
<meta charset="utf-8">
<script src="https://js.braintreegateway.com/web/dropin/1.14.1/js/dropin.min.js"></script>
</head>
<body>
<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>
</body>
I then provided the CLIENT_TOKEN_FROM_SERVER via the Python Library. Works.
Upvotes: 1