//= require "vendor/braintree" SolidusBraintree = { getFrontendStyles: function(){ /* Emulation of inherited attributes through an iframe */ var $source = $('.braintree-hosted-field'); return { input: { "font-family": $source.css("font-family"), "font-size": $source.css("font-size"), "color": $source.css("color"), } }; } } Spree.routes.payment_client_token_api = Spree.pathFor("api/payment_client_token") var braintreeDropinIntegration; var cardSelector = "#payment-method-fields"; var confirmForm = "#checkout_form_confirm"; var paymentId; var getClientToken = function(onSuccess) { return Spree.ajax({ url: Spree.routes.payment_client_token_api, type: "POST", data: { payment_method_id: paymentId }, error: function(xhr, status) { // If it fails it means the payment method was not a Braintree payment method if (braintreeDropinIntegration) { braintreeDropinIntegration.teardown(); braintreeDropinIntegration = null; } }, success: function(data) { onSuccess(data); } }); }; var initializeBraintree = function(data) { $("#card_expiry").on("keyup", function() { // We need to format the braintree expiration without spaces $("#braintree_expiration_date").val($(this).val().replace(/ /g,'')); }) braintree.setup(data.client_token, "custom", { id: "checkout_form_payment", hostedFields: { styles: SolidusBraintree.getFrontendStyles(), number: { selector: "#braintree_card_number", placeholder: braintree.placeholders["number"] }, cvv: { selector: "#braintree_card_code", placeholder: braintree.placeholders["cvv"] }, expirationDate: { selector: "#braintree_card_expiry", placeholder: braintree.placeholders["expirationDate"] } }, dataCollector: { kount: {environment: braintree.environment}, paypal: true }, paypal: { container: "#braintree_paypal_container", onSuccess: function() { $(".braintree-cc-input").hide(); }, onCancelled: function() { $(".braintree-cc-input").show(); } }, onReady: function (integration) { braintreeDropinIntegration = integration; $('form').find("input#device_data").val(integration.deviceData); }, onError: function(error) { var text; if (error.type === "VALIDATION") { text = 'There was a problem with your payment information. Please check your information and try again.'; } else { text = error.message; } $('#checkout_form_payment').find(':submit, :image').attr('disabled', false).removeClass('disabled'); var errorDiv = $("
", { class: 'flash error', text: text }); if (error.details) { var list = $("