From 7711e3643a2a7728cf369af64b7aed8a017f915b Mon Sep 17 00:00:00 2001 From: Alessandro Desantis Date: Wed, 17 Jun 2020 14:10:48 +0200 Subject: Retrieve payment method from payment source Previously, the payment method was set when configuring the gem. This is not needed, since we can get it directly from the source we are charging, which is much more flexible since it opens up the ability to charge sources belonging to different payment methods. --- README.md | 10 ---------- app/services/solidus_subscriptions/checkout.rb | 2 +- lib/solidus_subscriptions/config.rb | 5 ----- spec/lib/solidus_subscriptions/config_spec.rb | 17 ----------------- spec/services/solidus_subscriptions/checkout_spec.rb | 1 - spec/support/helpers/checkout_infrastructure.rb | 4 ---- 6 files changed, 1 insertion(+), 38 deletions(-) delete mode 100644 spec/lib/solidus_subscriptions/config_spec.rb diff --git a/README.md b/README.md index eaec397..cb4912b 100644 --- a/README.md +++ b/README.md @@ -19,16 +19,6 @@ bundle bundle exec rails g solidus_subscriptions:install ``` -## Configuration - -This gem requires a gateway which supports credit cards in order to process subscription orders. - -Add this to specify the gateway used by the gem: an initializer. - -```ruby -SolidusSubscriptions::Config.default_gateway { my_gateway } -``` - ### Guest checkout Subscriptions require a user to be present to allow them to be managed after they are purchased. diff --git a/app/services/solidus_subscriptions/checkout.rb b/app/services/solidus_subscriptions/checkout.rb index d82a0dc..cd66406 100644 --- a/app/services/solidus_subscriptions/checkout.rb +++ b/app/services/solidus_subscriptions/checkout.rb @@ -131,7 +131,7 @@ module SolidusSubscriptions order.payments.create( source: active_card, amount: order.total, - payment_method: Config.default_gateway + payment_method: active_card.payment_method, ) end diff --git a/lib/solidus_subscriptions/config.rb b/lib/solidus_subscriptions/config.rb index 6ab41c6..d6dbbf6 100644 --- a/lib/solidus_subscriptions/config.rb +++ b/lib/solidus_subscriptions/config.rb @@ -31,11 +31,6 @@ module SolidusSubscriptions def out_of_stock_dispatcher_class @out_of_stock_dispatcher_class ||= ::SolidusSubscriptions::OutOfStockDispatcher end - - def default_gateway(&block) - return @gateway.call unless block_given? - @gateway = block - end end # Maximum number of times a user can skip their subscription before it diff --git a/spec/lib/solidus_subscriptions/config_spec.rb b/spec/lib/solidus_subscriptions/config_spec.rb deleted file mode 100644 index b5b8519..0000000 --- a/spec/lib/solidus_subscriptions/config_spec.rb +++ /dev/null @@ -1,17 +0,0 @@ -require 'spec_helper' - -RSpec.describe SolidusSubscriptions::Config do - before { described_class.instance_variable_set('@gateway', nil) } - after { described_class.instance_variable_set('@gateway', nil) } - - describe '.default_gateway' do - let(:bogus) { build_stubbed(:credit_card_payment_method) } - subject(:gateway) { described_class.default_gateway } - - before do - described_class.default_gateway { bogus } - end - - it { is_expected.to eq bogus } - end -end diff --git a/spec/services/solidus_subscriptions/checkout_spec.rb b/spec/services/solidus_subscriptions/checkout_spec.rb index 5a9a386..84780db 100644 --- a/spec/services/solidus_subscriptions/checkout_spec.rb +++ b/spec/services/solidus_subscriptions/checkout_spec.rb @@ -25,7 +25,6 @@ RSpec.describe SolidusSubscriptions::Checkout do end before do - SolidusSubscriptions::Config.default_gateway { payment_method } Spree::Variant.all.each { |v| v.update(subscribable: true) } end diff --git a/spec/support/helpers/checkout_infrastructure.rb b/spec/support/helpers/checkout_infrastructure.rb index 6a18083..8196a87 100644 --- a/spec/support/helpers/checkout_infrastructure.rb +++ b/spec/support/helpers/checkout_infrastructure.rb @@ -3,16 +3,12 @@ module CheckoutInfrastructure def self.extended(base) base.before(:all) do - payment_method = create :credit_card_payment_method create :country create :shipping_method - - SolidusSubscriptions::Config.default_gateway { payment_method } end base.after(:all) do DatabaseCleaner.clean_with(:truncation) - SolidusSubscriptions::Config.default_gateway { nil } end end end -- cgit v1.2.3