mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Extract some methods and move to simpler callbacks with guard clauses
This commit is contained in:
@@ -6,17 +6,29 @@ module PaymentGateways
|
||||
include OrderCompletion
|
||||
|
||||
before_action :load_checkout_order, only: :confirm
|
||||
before_action :validate_payment_intent, only: :confirm
|
||||
before_action :validate_stock, only: :confirm
|
||||
|
||||
def confirm
|
||||
return processing_failed unless valid_payment_intent?
|
||||
|
||||
cancel_incomplete_payments && handle_insufficient_stock unless sufficient_stock?
|
||||
|
||||
process_payment_completion!
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def validate_stock
|
||||
return if sufficient_stock?
|
||||
|
||||
cancel_incomplete_payments
|
||||
handle_insufficient_stock
|
||||
end
|
||||
|
||||
def validate_payment_intent
|
||||
return if valid_payment_intent?
|
||||
|
||||
processing_failed
|
||||
redirect_to order_failed_route
|
||||
end
|
||||
|
||||
def valid_payment_intent?
|
||||
@valid_payment_intent ||= begin
|
||||
return false unless params["payment_intent"]&.starts_with?("pi_")
|
||||
|
||||
Reference in New Issue
Block a user