From c0ddeceb1e4bbfcecc7b5b70dea0eb8b15b03a66 Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Tue, 3 Nov 2020 14:36:20 +0000 Subject: [PATCH] Remove Pin Payments --- .rubocop_todo.yml | 2 -- app/models/spree/gateway/pin.rb | 15 ------------- app/models/spree/payment.rb | 7 ------ app/services/checkout/form_data_adapter.rb | 5 +---- config/application.rb | 1 - .../admin/payment_methods_controller_spec.rb | 14 ------------ spec/models/spree/payment_method_spec.rb | 1 - spec/models/spree/payment_spec.rb | 22 ------------------- 8 files changed, 1 insertion(+), 66 deletions(-) delete mode 100644 app/models/spree/gateway/pin.rb diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index a73b1cd0c9..cd62dcf638 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -396,7 +396,6 @@ Style/CaseEquality: Style/ClassAndModuleChildren: Exclude: - 'app/models/calculator/flat_percent_per_item.rb' - - 'app/models/spree/gateway/pin.rb' - 'app/models/tag_rule/discount_order.rb' - 'app/models/tag_rule/filter_order_cycles.rb' - 'app/models/tag_rule/filter_payment_methods.rb' @@ -612,7 +611,6 @@ Style/FrozenStringLiteralComment: - 'app/models/product_import/unit_converter.rb' - 'app/models/proxy_order.rb' - 'app/models/schedule.rb' - - 'app/models/spree/gateway/pin.rb' - 'app/models/spree/gateway/stripe_connect.rb' - 'app/models/spree/preferences/file_configuration.rb' - 'app/models/spree/property.rb' diff --git a/app/models/spree/gateway/pin.rb b/app/models/spree/gateway/pin.rb deleted file mode 100644 index c50a3fa773..0000000000 --- a/app/models/spree/gateway/pin.rb +++ /dev/null @@ -1,15 +0,0 @@ -module Spree - class Gateway::Pin < Gateway - preference :api_key, :string - - def provider_class - ActiveMerchant::Billing::PinGateway - end - - def options_with_test_preference - options_without_test_preference.merge(test: preferred_test_mode) - end - - alias_method_chain :options, :test_preference - end -end diff --git a/app/models/spree/payment.rb b/app/models/spree/payment.rb index 2c8dfc1a6c..0d014462b9 100644 --- a/app/models/spree/payment.rb +++ b/app/models/spree/payment.rb @@ -103,8 +103,6 @@ module Spree source.user_id = order.user_id if order end - # Pin payments lacks void and credit methods, but it does have refund - # Here we swap credit out for refund and remove void as a possible action def actions return [] unless payment_source&.respond_to?(:actions) @@ -113,11 +111,6 @@ module Spree payment_source.__send__("can_#{action}?", self) end - if payment_method.is_a? Gateway::Pin - actions << 'refund' if actions.include? 'credit' - actions.reject! { |a| ['credit', 'void'].include? a } - end - actions end diff --git a/app/services/checkout/form_data_adapter.rb b/app/services/checkout/form_data_adapter.rb index 1333ed5dbd..851f52e919 100644 --- a/app/services/checkout/form_data_adapter.rb +++ b/app/services/checkout/form_data_adapter.rb @@ -34,10 +34,7 @@ module Checkout end # Ensures cc_type is always passed to the model by inferring the type when - # the frontend didn't provide it. This fixes Pin Payments specifically - # although it might be useful for future payment gateways. - # - # More details: app/assets/javascripts/darkswarm/services/checkout.js.coffee#L70-L98 + # the frontend didn't provide it. def fill_in_card_type return unless payment_source_attributes diff --git a/config/application.rb b/config/application.rb index a8a6929a66..73d9e78184 100644 --- a/config/application.rb +++ b/config/application.rb @@ -125,7 +125,6 @@ module Openfoodnetwork # Register Spree payment methods initializer "spree.gateway.payment_methods", :after => "spree.register.payment_methods" do |app| - app.config.spree.payment_methods << Spree::Gateway::Pin app.config.spree.payment_methods << Spree::Gateway::StripeConnect app.config.spree.payment_methods << Spree::Gateway::StripeSCA app.config.spree.payment_methods << Spree::Gateway::PayPalExpress diff --git a/spec/controllers/spree/admin/payment_methods_controller_spec.rb b/spec/controllers/spree/admin/payment_methods_controller_spec.rb index 128ef0c42e..75abf32a63 100644 --- a/spec/controllers/spree/admin/payment_methods_controller_spec.rb +++ b/spec/controllers/spree/admin/payment_methods_controller_spec.rb @@ -41,20 +41,6 @@ module Spree expect(response).to redirect_to spree.edit_admin_payment_method_path(assigns(:payment_method)) end - it "can save Pin Payment payment method details" do - expect { - spree_post :create, payment_method: { - name: "Test Method", type: "Spree::Gateway::Pin", distributor_ids: [enterprise.id], - preferred_server: "test", preferred_api_key: "apikey123", preferred_test_mode: "1" - } - }.to change(Spree::PaymentMethod, :count).by(1) - - payment_method = Spree::PaymentMethod.last - expect(payment_method.preferences[:server]).to eq "test" - expect(payment_method.preferences[:api_key]).to eq "apikey123" - expect(payment_method.preferences[:test_mode]).to eq true - end - it "can not create a payment method of an invalid type" do expect { spree_post :create, payment_method: { name: "Invalid Payment Method", type: "Spree::InvalidType", distributor_ids: [enterprise.id] } diff --git a/spec/models/spree/payment_method_spec.rb b/spec/models/spree/payment_method_spec.rb index 1d85df5fa8..bddd520118 100644 --- a/spec/models/spree/payment_method_spec.rb +++ b/spec/models/spree/payment_method_spec.rb @@ -59,7 +59,6 @@ module Spree it "generates a clean name for known Payment Method types" do expect(Spree::PaymentMethod::Check.clean_name).to eq(I18n.t("spree.admin.payment_methods.providers.check")) - expect(Spree::Gateway::Pin.clean_name).to eq(I18n.t("spree.admin.payment_methods.providers.pin")) expect(Spree::Gateway::PayPalExpress.clean_name).to eq(I18n.t("spree.admin.payment_methods.providers.paypalexpress")) expect(Spree::Gateway::StripeConnect.clean_name).to eq(I18n.t("spree.admin.payment_methods.providers.stripeconnect")) expect(Spree::Gateway::StripeSCA.clean_name).to eq(I18n.t("spree.admin.payment_methods.providers.stripesca")) diff --git a/spec/models/spree/payment_spec.rb b/spec/models/spree/payment_spec.rb index cbba2b4b9a..9a0ab803d0 100644 --- a/spec/models/spree/payment_spec.rb +++ b/spec/models/spree/payment_spec.rb @@ -711,28 +711,6 @@ describe Spree::Payment do end end end - - context "for Pin Payments" do - let(:d) { create(:distributor_enterprise) } - let(:pin) { Spree::Gateway::Pin.create! name: 'pin', distributor_ids: [d.id] } - let(:payment) { create(:payment, source: create(:credit_card), payment_method: pin) } - - it "does not void" do - expect(payment.actions).not_to include 'void' - end - - describe "when a payment has been taken" do - before do - allow(payment).to receive(:state) { 'completed' } - allow(payment).to receive(:order) { double(:order, payment_state: 'credit_owed') } - end - - it "can refund instead of crediting" do - expect(payment.actions).not_to include 'credit' - expect(payment.actions).to include 'refund' - end - end - end end describe "refund!" do