SolidusPaypalBraintree = {
  APPLE_PAY_API_VERSION: 1,

  config: {
    paths: {
      clientTokens: Spree.pathFor('solidus_paypal_braintree/client_token'),
      transactions: Spree.pathFor('solidus_paypal_braintree/transactions')
    },

    // Override to provide your own error messages.
    braintreeErrorHandle: function(braintreeError) {
      var $contentContainer = $("#content");
      var $flash = $("<div class='flash error'>" + braintreeError.name + ": " + braintreeError.message + "</div>");
      $contentContainer.prepend($flash);

      $flash.show().delay(5000).fadeOut(500);
    },

    classes: {
      hostedForm: function() {
        return SolidusPaypalBraintree.HostedForm;
      },

      client: function() {
        return SolidusPaypalBraintree.Client;
      },

      paypalButton: function() {
        return SolidusPaypalBraintree.PaypalButton;
      },

      applepayButton: function() {
        return SolidusPaypalBraintree.ApplepayButton;
      }
    }
  },

  createHostedForm: function() {
    return SolidusPaypalBraintree._factory(SolidusPaypalBraintree.config.classes.hostedForm(), arguments);
  },

  createClient: function() {
    return SolidusPaypalBraintree._factory(SolidusPaypalBraintree.config.classes.client(), arguments);
  },

  createPaypalButton: function() {
    return SolidusPaypalBraintree._factory(SolidusPaypalBraintree.config.classes.paypalButton(), arguments);
  },

  createApplePayButton: function() {
    return SolidusPaypalBraintree._factory(SolidusPaypalBraintree.config.classes.applepayButton(), arguments);
  },

  _factory: function(klass, args) {
    var normalizedArgs = Array.prototype.slice.call(args);
    return new (Function.prototype.bind.apply(klass, [null].concat(normalizedArgs)));
  }
};

@@ -228,25 +228,29 @@
 ns')%0A    %7D,%0A
+    
 %0A
-
     // Overr
@@ -352,248 +352,106 @@
     
-var $contentContainer = $(%22#content%22);%0A      var $flash = $(%22%3Cdiv class='flash error'%3E%22 + braintreeError.name + %22: %22 + braintreeError.message + %22%3C/div%3E%22);%0A      $contentContainer.prepend($flash);%0A%0A      $flash.show().delay(5000).fadeOut(500
+BraintreeError.getErrorFromSlug(braintreeError.code);%0A      SolidusPaypalBraintree.showError(error
 );%0A 
@@ -838,16 +838,16 @@
       %7D%0A
-
     %7D%0A  
@@ -844,24 +844,257 @@
 %7D%0A    %7D%0A  %7D,
+%0A  %0A  showError: function(error) %7B%0A    var $contentContainer = $(%22#content%22);%0A    var $flash = $(%22%3Cdiv class='flash error'%3E%22 + error + %22%3C/div%3E%22);%0A    $contentContainer.prepend($flash);%0A    $flash.show().delay(5000).fadeOut(500);%0A  %7D,
 %0A%0A  createHo

Refactor Braintree error handler function to get localization messages