diff --git a/app/models/spree/order_decorator.rb b/app/models/spree/order_decorator.rb index 8c0eddfea0..9892293114 100644 --- a/app/models/spree/order_decorator.rb +++ b/app/models/spree/order_decorator.rb @@ -293,6 +293,24 @@ Spree::Order.class_eval do complete? && distributor.andand.allow_order_changes? && order_cycle.andand.open? end + # Override of existing Spree method. Can remove when we reach 2-0-stable + # See commit: https://github.com/spree/spree/commit/5fca58f658273451193d5711081d018c317814ed + # Allows GatewayError to show useful error messages in checkout + def process_payments! + pending_payments.each do |payment| + break if payment_total >= total + + payment.process! + + if payment.completed? + self.payment_total += payment.amount + end + end + rescue Spree::Core::GatewayError => e # This section changed + result = !!Spree::Config[:allow_checkout_on_gateway_error] + errors.add(:base, e.message) and return result + end + private def shipping_address_from_distributor diff --git a/spec/requests/stripe_connect_checkout_spec.rb b/spec/requests/stripe_connect_checkout_spec.rb index ce787802f0..2bd2909cf0 100644 --- a/spec/requests/stripe_connect_checkout_spec.rb +++ b/spec/requests/stripe_connect_checkout_spec.rb @@ -68,7 +68,7 @@ describe "Submitting Stripe Connect charge requests", type: :request do put update_checkout_path, params expect(response.status).to be 400 json_response = JSON.parse(response.body) - expect(json_response["flash"]["error"]).to eq I18n.t(:payment_processing_failed) + expect(json_response["flash"]["error"]).to eq "Bup-bow..." expect(order.payments.completed.count).to be 0 end end @@ -128,7 +128,7 @@ describe "Submitting Stripe Connect charge requests", type: :request do put update_checkout_path, params expect(response.status).to be 400 json_response = JSON.parse(response.body) - expect(json_response["flash"]["error"]).to eq I18n.t(:payment_processing_failed) + expect(json_response["flash"]["error"]).to eq "Bup-bow..." expect(order.payments.completed.count).to be 0 end end @@ -147,7 +147,7 @@ describe "Submitting Stripe Connect charge requests", type: :request do put update_checkout_path, params expect(response.status).to be 400 json_response = JSON.parse(response.body) - expect(json_response["flash"]["error"]).to eq I18n.t(:payment_processing_failed) + expect(json_response["flash"]["error"]).to eq "Bup-bow..." expect(order.payments.completed.count).to be 0 end end @@ -209,7 +209,7 @@ describe "Submitting Stripe Connect charge requests", type: :request do put update_checkout_path, params expect(response.status).to be 400 json_response = JSON.parse(response.body) - expect(json_response["flash"]["error"]).to eq I18n.t(:payment_processing_failed) + expect(json_response["flash"]["error"]).to eq "Bup-bow..." expect(order.payments.completed.count).to be 0 end end @@ -228,7 +228,7 @@ describe "Submitting Stripe Connect charge requests", type: :request do put update_checkout_path, params expect(response.status).to be 400 json_response = JSON.parse(response.body) - expect(json_response["flash"]["error"]).to eq I18n.t(:payment_processing_failed) + expect(json_response["flash"]["error"]).to eq "Bup-bow..." expect(order.payments.completed.count).to be 0 end end