diff options
author | Brendan Deere <brendan@stembolt.com> | 2016-10-17 15:46:05 -0700 |
---|---|---|
committer | Brendan Deere <brendan@stembolt.com> | 2016-10-17 15:59:21 -0700 |
commit | 71f9177e71cc6499fd49e2c8040aa5640142d346 (patch) | |
tree | f8e96d40fe089728e46b5463170f0cfd80d14e3b /lib | |
parent | 3e1edba0a308cd9f9fa6604bd1553ad2d00ce5b3 (diff) |
Initialize the gateway with a block
So Ive been running into the problem of the gateway being evaluated too
early (before the db is created) having it be explicitely set in an
initializer.
Im now specifying the default gateway in a block so that it will not be
evaluated until it is actually needed
Diffstat (limited to 'lib')
-rw-r--r-- | lib/solidus_subscriptions/config.rb | 22 |
1 files changed, 1 insertions, 21 deletions
diff --git a/lib/solidus_subscriptions/config.rb b/lib/solidus_subscriptions/config.rb index f3f186c..6ff33d1 100644 --- a/lib/solidus_subscriptions/config.rb +++ b/lib/solidus_subscriptions/config.rb @@ -80,28 +80,8 @@ module SolidusSubscriptions ] end - def default_gateway=(gateway) - @gateway = gateway - end - def default_gateway - @gateway ||= Spree::Gateway.where(active: true).detect do |gateway| - gateway.payment_source_class == Spree::CreditCard - end - - return @gateway if @gateway - - raise <<-MSG.strip - SolidusSubscriptions requires a Credit Card Gateway - - Make sure at lease one Spree::PaymentMethod exists with a - #payment_source_class of Spree::CreditCard. - - Alternatively, you can manually set the Gateway you would like to use by - adding the following to an initializer: - - SolidusSubscription::Config.default_gateway = my_gateway - MSG + block_given? ? @gateway = Proc.new : @gateway.call end end end |