Skip to content

Commit

Permalink
Allow extension to work with Solidus 2.2
Browse files Browse the repository at this point in the history
prior to the new gateways design payment methods were inheriting
from Spree::Gateway and they needed to be instantiated by calling
`provider`. This commit makes it possible to support both versions.

It uses the new method added into 0.2.2 of solidus_support, this is
why the dependency has been updated.
  • Loading branch information
kennyadsl committed Oct 9, 2018
1 parent ab9f2e1 commit 1477850
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/models/solidus_affirm/checkout.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module SolidusAffirm
class Checkout < ActiveRecord::Base
class Checkout < SolidusSupport.payment_source_parent_class
self.table_name = "affirm_checkouts"

def actions
Expand Down
11 changes: 9 additions & 2 deletions app/models/solidus_affirm/gateway.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module SolidusAffirm
class Gateway < ::Spree::PaymentMethod
class Gateway < SolidusSupport.payment_method_parent_class
preference :public_api_key, :string
preference :private_api_key, :string
preference :javascript_url, :string
Expand Down Expand Up @@ -44,7 +44,7 @@ def auto_capture
# If the transaction has not yet been captured, we can void the transaction.
# Otherwise, we need to issue a refund.
def cancel(charge_id, try_credit = true)
gateway
initialize_gateway

begin
transaction = ::Affirm::Charge.find(charge_id)
Expand Down Expand Up @@ -74,5 +74,12 @@ def try_void(payment)
def voidable?(transaction)
transaction.status == "authorized"
end

def initialize_gateway
# We can just leave gateway after Solidus 2.2 EOL
return gateway if respond_to?(:gateway)

provider
end
end
end
2 changes: 1 addition & 1 deletion solidus_affirm.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Gem::Specification.new do |s|
s.add_dependency 'active_model_serializers', '~> 0.10'
s.add_dependency 'affirm-ruby', '1.0.2'
s.add_dependency 'solidus', ['>= 2.0', '< 3']
s.add_dependency "solidus_support"
s.add_dependency "solidus_support", '>= 0.2.2'

s.add_development_dependency 'capybara', '~> 2.18'
s.add_development_dependency 'coffee-rails'
Expand Down

0 comments on commit 1477850

Please sign in to comment.