Sha256: 5e1aa930b1f6c220eabec49132b068e481ff2bdf897b4c874785033a159ee711

Contents?: true

Size: 1.02 KB

Versions: 1

Compression:

Stored size: 1.02 KB

Contents

//= require "vendor/braintree-2.9.0"

Spree.routes.payment_client_token_api = Spree.pathFor("api/payment_client_token")

var getClientToken = function(onSuccess) {
  return Spree.ajax({
    url: Spree.routes.payment_client_token_api,
    type: "POST",
    data: {
      payment_method_id: $('form input[type=radio]:checked').val()
    },
    error: function(xhr, status) {
      show_flash("error", xhr.responseJSON.message);
    },
    success: function(data) {
      onSuccess(data);
    }
  });
};

var attachDropIn = function(data) {
  braintree.setup(data.client_token, "dropin", {
    container: "braintree-dropin",
    form: "new_payment",
    onReady: function() {
      console.log("braintree dropin is ready");
      return;
    },
    onError: function(type, message) {
      show_flash("error", message);
    },
    onPaymentMethodReceived: function(obj) {
      $("#payment_method_nonce").val(obj.nonce);
      $("#new_payment").submit();
      return;
    }
  });
};

$(document).ready(function() {
  getClientToken(attachDropIn);
});

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
solidus_braintree-0.1.1 lib/assets/javascripts/spree/backend/braintree/solidus_braintree.js