Skip to content

Commit

Permalink
Get client token from braintree only in the payment page.
Browse files Browse the repository at this point in the history
  • Loading branch information
hectoregm committed May 25, 2016
1 parent c0a8434 commit 32b35d3
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions lib/assets/javascripts/spree/backend/braintree/solidus_braintree.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Spree.routes.payment_client_token_api = Spree.pathFor("api/payment_client_token")

var braintreeDropinIntegration;
var paymentForm = "#new_payment"
var cardSelector = "#new_payment [name=card]";

var getClientToken = function(onSuccess) {
Expand Down Expand Up @@ -40,17 +41,19 @@ var attachDropIn = function(data) {
};

$(document).ready(function() {
if ($(cardSelector).length) {
$(cardSelector).on("change", function() {
if ($(cardSelector + ":checked").val() === "new") {
getClientToken(attachDropIn);
} else {
if (braintreeDropinIntegration) {
braintreeDropinIntegration.teardown();
if ($(paymentForm).length) {
if ($(cardSelector).length) {
$(cardSelector).on("change", function() {
if ($(cardSelector + ":checked").val() === "new") {
getClientToken(attachDropIn);
} else {
if (braintreeDropinIntegration) {
braintreeDropinIntegration.teardown();
}
}
}
});
} else {
getClientToken(attachDropIn);
});
} else {
getClientToken(attachDropIn);
}
}
});

0 comments on commit 32b35d3

Please sign in to comment.