Show more helpful payment processing error in checkout

This commit is contained in:
Rob Harrington
2017-09-17 11:47:46 +10:00
parent 665749d0c5
commit 7c82fa3d44
2 changed files with 23 additions and 5 deletions

View File

@@ -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

View File

@@ -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