Skip to content

Commit

Permalink
Reorder precondition checks in payment processing
Browse files Browse the repository at this point in the history
This way we group simple checks and checks that would raise
exceptions in different groups for better readability.
  • Loading branch information
elia committed Jan 19, 2023
1 parent 1fe26e7 commit d3e88ab
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions core/app/models/spree/payment/processing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,14 @@ def handle_void_response(response)

# @raises Spree::Core::GatewayError
def check_payment_preconditions!
return if payment_method.nil?
return if processing?
return unless payment_method
return unless payment_method.source_required?

unless source
gateway_error(I18n.t('spree.payment_processing_failed'))
end
return if processing?

unless payment_method.supports?(source)
invalidate!
gateway_error(I18n.t('spree.payment_method_not_supported'))
Expand Down

0 comments on commit d3e88ab

Please sign in to comment.