diff --git a/app/controllers/solidus_paypal_braintree/admin_payments_controller_decorator.rb b/app/controllers/solidus_paypal_braintree/admin_payments_controller_decorator.rb new file mode 100644 index 00000000..eefe2392 --- /dev/null +++ b/app/controllers/solidus_paypal_braintree/admin_payments_controller_decorator.rb @@ -0,0 +1,10 @@ +module SolidusPaypalBraintree + module AdminPaymentsControllerDecorator + + def self.prepended(base) + base.helper ::SolidusPaypalBraintree::BraintreeAdminHelper + end + + ::Spree::Admin::PaymentsController.prepend(self) + end +end diff --git a/app/controllers/solidus_paypal_braintree/orders_controller_decorator.rb b/app/controllers/solidus_paypal_braintree/orders_controller_decorator.rb new file mode 100644 index 00000000..67791bf3 --- /dev/null +++ b/app/controllers/solidus_paypal_braintree/orders_controller_decorator.rb @@ -0,0 +1,10 @@ +module SolidusPaypalBraintree + module OrdersControllerDecorator + + def self.prepended(base) + base.helper ::SolidusPaypalBraintree::BraintreeCheckoutHelper + end + + ::Spree::OrdersController.prepend(self) + end +end diff --git a/app/helpers/braintree_admin_helper.rb b/app/helpers/braintree_admin_helper.rb deleted file mode 100644 index 51e57353..00000000 --- a/app/helpers/braintree_admin_helper.rb +++ /dev/null @@ -1,18 +0,0 @@ -module BraintreeAdminHelper - # Returns a link to the Braintree web UI for the given Braintree payment - def braintree_transaction_link(payment) - environment = payment.payment_method.preferred_environment == 'sandbox' ? 'sandbox' : 'www' - merchant_id = payment.payment_method.preferred_merchant_id - response_code = payment.response_code - - return unless response_code.present? - return response_code unless merchant_id.present? - - link_to( - response_code, - "https://#{environment}.braintreegateway.com/merchants/#{merchant_id}/transactions/#{response_code}", - title: 'Show payment on Braintree', - target: '_blank' - ) - end -end diff --git a/app/helpers/braintree_checkout_helper.rb b/app/helpers/braintree_checkout_helper.rb deleted file mode 100644 index d481dc58..00000000 --- a/app/helpers/braintree_checkout_helper.rb +++ /dev/null @@ -1,5 +0,0 @@ -module BraintreeCheckoutHelper - def paypal_button_preference(key, store:) - store.braintree_configuration.preferences[key] - end -end diff --git a/app/helpers/solidus_paypal_braintree/braintree_admin_helper.rb b/app/helpers/solidus_paypal_braintree/braintree_admin_helper.rb new file mode 100644 index 00000000..7063c5b0 --- /dev/null +++ b/app/helpers/solidus_paypal_braintree/braintree_admin_helper.rb @@ -0,0 +1,20 @@ +module SolidusPaypalBraintree + module BraintreeAdminHelper + # Returns a link to the Braintree web UI for the given Braintree payment + def braintree_transaction_link(payment) + environment = payment.payment_method.preferred_environment == 'sandbox' ? 'sandbox' : 'www' + merchant_id = payment.payment_method.preferred_merchant_id + response_code = payment.response_code + + return unless response_code.present? + return response_code unless merchant_id.present? + + link_to( + response_code, + "https://#{environment}.braintreegateway.com/merchants/#{merchant_id}/transactions/#{response_code}", + title: 'Show payment on Braintree', + target: '_blank' + ) + end + end +end diff --git a/app/helpers/solidus_paypal_braintree/braintree_checkout_helper.rb b/app/helpers/solidus_paypal_braintree/braintree_checkout_helper.rb index 52dd21ab..12535d9b 100644 --- a/app/helpers/solidus_paypal_braintree/braintree_checkout_helper.rb +++ b/app/helpers/solidus_paypal_braintree/braintree_checkout_helper.rb @@ -40,5 +40,8 @@ def braintree_3ds_options_for(order) } end + def paypal_button_preference(key, store:) + store.braintree_configuration.preferences[key] + end end end diff --git a/config/initializers/braintree.rb b/config/initializers/braintree.rb deleted file mode 100644 index 1f370736..00000000 --- a/config/initializers/braintree.rb +++ /dev/null @@ -1,8 +0,0 @@ -if SolidusSupport.backend_available? - Spree::Admin::PaymentsController.helper :braintree_admin -end - -if SolidusSupport.frontend_available? - Spree::CheckoutController.helper :braintree_checkout - Spree::OrdersController.helper :braintree_checkout -end diff --git a/spec/helpers/braintree_admin_helper_spec.rb b/spec/helpers/braintree_admin_helper_spec.rb index 4e769285..19798593 100644 --- a/spec/helpers/braintree_admin_helper_spec.rb +++ b/spec/helpers/braintree_admin_helper_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -RSpec.describe BraintreeAdminHelper do +RSpec.describe SolidusPaypalBraintree::BraintreeAdminHelper do describe '#braintree_transaction_link' do let(:payment_method) { create_gateway } let(:payment) do