mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-20 04:59:16 +00:00
Merge pull request #13961 from mkllnk/taler-checkout-stock-error
Taler checkout stock error
This commit is contained in:
@@ -2,15 +2,36 @@
|
||||
|
||||
module PaymentGateways
|
||||
class TalerController < BaseController
|
||||
include OrderStockCheck
|
||||
include OrderCompletion
|
||||
|
||||
class StockError < StandardError
|
||||
end
|
||||
|
||||
# The Taler merchant backend has taken the payment.
|
||||
# Now we just need to confirm that and update our local database
|
||||
# before finalising the order.
|
||||
def confirm
|
||||
payment = Spree::Payment.find(params[:payment_id])
|
||||
|
||||
# Process payment early because it's probably paid already.
|
||||
# We want to capture that before any validations raise errors.
|
||||
unless payment.process!
|
||||
return redirect_to order_failed_route(step: "payment")
|
||||
end
|
||||
|
||||
@order = payment.order
|
||||
process_payment_completion!
|
||||
OrderLocker.lock_order_and_variants(@order) do
|
||||
raise StockError unless sufficient_stock?
|
||||
|
||||
process_payment_completion!
|
||||
end
|
||||
rescue Spree::Core::GatewayError => e
|
||||
flash[:notice] = e.message
|
||||
redirect_to order_failed_route(step: "payment")
|
||||
rescue StockError
|
||||
flash[:notice] = t("checkout.payment_cancelled_due_to_stock")
|
||||
redirect_to main_app.checkout_step_path(step: "details")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -674,8 +674,6 @@ module Spree
|
||||
end
|
||||
|
||||
def process_each_payment
|
||||
raise Core::GatewayError, Spree.t(:no_pending_payments) if pending_payments.empty?
|
||||
|
||||
pending_payments.each do |payment|
|
||||
if payment.amount.zero? && zero_priced_order?
|
||||
payment.update_columns(state: "completed", captured_at: Time.zone.now)
|
||||
|
||||
Reference in New Issue
Block a user