Use proper module/namespace

This commit is contained in:
Matt-Yorkley
2021-12-27 21:36:32 +00:00
parent 48c4ecde08
commit ddf6e7eadd

View File

@@ -1,40 +1,42 @@
# frozen_string_literal: true
class StripeController < BaseController
include OrderStockCheck
include OrderCompletion
module PaymentGateways
class StripeController < BaseController
include OrderStockCheck
include OrderCompletion
before_action :load_checkout_order, only: :confirm
before_action :load_checkout_order, only: :confirm
def confirm
return processing_failed unless valid_payment_intent?
def confirm
return processing_failed unless valid_payment_intent?
cancel_incomplete_payments && handle_insufficient_stock unless sufficient_stock?
cancel_incomplete_payments && handle_insufficient_stock unless sufficient_stock?
process_payment_completion!
end
private
def valid_payment_intent?
@valid_payment_intent ||= begin
return false unless params["payment_intent"]&.starts_with?("pi_")
last_payment = OrderPaymentFinder.new(@order).last_payment
@order.state == "payment" &&
last_payment&.state == "requires_authorization" &&
last_payment&.response_code == params["payment_intent"]
process_payment_completion!
end
end
def cancel_incomplete_payments
# The checkout could not complete due to stock running out. We void any pending (incomplete)
# Stripe payments here as the order will need to be changed and resubmitted (or abandoned).
@order.payments.incomplete.each do |payment|
payment.void_transaction!
payment.adjustment&.update_columns(eligible: false, state: "finalized")
private
def valid_payment_intent?
@valid_payment_intent ||= begin
return false unless params["payment_intent"]&.starts_with?("pi_")
last_payment = OrderPaymentFinder.new(@order).last_payment
@order.state == "payment" &&
last_payment&.state == "requires_authorization" &&
last_payment&.response_code == params["payment_intent"]
end
end
def cancel_incomplete_payments
# The checkout could not complete due to stock running out. We void any pending (incomplete)
# Stripe payments here as the order will need to be changed and resubmitted (or abandoned).
@order.payments.incomplete.each do |payment|
payment.void_transaction!
payment.adjustment&.update_columns(eligible: false, state: "finalized")
end
flash[:notice] = I18n.t("checkout.payment_cancelled_due_to_stock")
end
flash[:notice] = I18n.t("checkout.payment_cancelled_due_to_stock")
end
end