Skip to content

Commit

Permalink
Backport process_payments_with from Solidus 1.4
Browse files Browse the repository at this point in the history
There is an issue with the `process_payments_with` method where it will
raise a GatewayError if there are no unprocessed payments when
transitioning from confirm -> complete. It's possible with some of our
payment methods that we already have an authorized payment at that point
and there is no need for any further processing.

This issue was resolved in Solidus 1.4 in the following PR:
solidusio/solidus#1361
  • Loading branch information
Luuk Veenis committed Aug 24, 2017
1 parent b15f522 commit 13f00c5
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
30 changes: 30 additions & 0 deletions app/models/concerns/spree/adyen/order.rb
Expand Up @@ -10,6 +10,36 @@ def requires_manual_refund?
payment.source.try(:requires_manual_refund?)
end
end

private

def process_payments_with(method)
if SolidusSupport.solidus_gem_version < Gem::Version.new("1.4.0")
process_payments_with_v1_4(method)
else
super
end
end

# Backport from Solidus 1.4 to address the issue resolved in:
# https://github.com/solidusio/solidus/pull/1361
def process_payments_with_v1_4(method)
# Don't run if there is nothing to pay.
return true if payment_total >= total

unprocessed_payments.each do |payment|
break if payment_total >= total

payment.public_send(method)

if payment.completed?
self.payment_total += payment.amount
end
end
rescue Core::GatewayError => e
result = !!Spree::Config[:allow_checkout_on_gateway_error]
errors.add(:base, e.message) && (return result)
end
end
end
end
2 changes: 1 addition & 1 deletion lib/spree/adyen/engine.rb
Expand Up @@ -36,7 +36,7 @@ def self.activate
Spree::CheckoutController.prepend Spree::Adyen::CheckoutController
Spree::CreditCard.prepend Spree::CreditCard::AdyenToken
Spree::Payment.prepend Spree::Adyen::Payment
Spree::Order.include Spree::Adyen::Order
Spree::Order.prepend Spree::Adyen::Order
Spree::Admin::RefundsController.include Spree::Adyen::Admin::RefundsController
::Adyen::API::PaymentService.include Spree::Adyen::PaymentService
::Adyen::REST::Response.include Spree::Adyen::REST::Response
Expand Down

0 comments on commit 13f00c5

Please sign in to comment.