mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Fix paypal controller
This commit is contained in:
@@ -14,6 +14,8 @@ module PaymentGateways
|
||||
after_action :reset_order_when_complete, only: :confirm
|
||||
|
||||
def express
|
||||
return redirect_to order_failed_route if @any_out_of_stock == true
|
||||
|
||||
pp_request = provider.build_set_express_checkout(
|
||||
express_checkout_request_details(@order)
|
||||
)
|
||||
@@ -41,6 +43,8 @@ module PaymentGateways
|
||||
end
|
||||
|
||||
def confirm
|
||||
return redirect_to order_failed_route if @any_out_of_stock == true
|
||||
|
||||
# At this point the user has come back from the Paypal form, and we get one
|
||||
# last chance to interact with the payment process before the money moves...
|
||||
|
||||
|
||||
@@ -30,13 +30,12 @@ module PaymentGateways
|
||||
end
|
||||
|
||||
context "if the stock ran out whilst the payment was being placed" do
|
||||
before do
|
||||
allow(controller.current_order).to receive(:insufficient_stock_lines).and_return(true)
|
||||
end
|
||||
it "redirects to the details page with out of stock error" do
|
||||
mock_order_check_stock_service(controller.current_order)
|
||||
|
||||
it "redirects to the cart with out of stock error" do
|
||||
expect(post(:confirm, params: { payment_method_id: payment_method.id })).
|
||||
to redirect_to cart_path
|
||||
post(:confirm, params: { payment_method_id: payment_method.id })
|
||||
|
||||
expect(response).to redirect_to checkout_step_path(step: :details)
|
||||
|
||||
order = controller.current_order.reload
|
||||
|
||||
@@ -104,6 +103,16 @@ module PaymentGateways
|
||||
expect(flash[:error]).to eq "Could not connect to PayPal."
|
||||
end
|
||||
end
|
||||
|
||||
context "when the stock ran out whilst the payment was being placed" do
|
||||
it "redirects to the details page with out of stock error" do
|
||||
mock_order_check_stock_service(controller.current_order)
|
||||
|
||||
post(:express)
|
||||
|
||||
expect(response).to redirect_to checkout_step_path(step: :details)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#expire_current_order' do
|
||||
@@ -117,5 +126,12 @@ module PaymentGateways
|
||||
expect(controller.instance_variable_get(:@current_order)).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
def mock_order_check_stock_service(order)
|
||||
check_stock_service_mock = instance_double(Orders::CheckStockService)
|
||||
expect(Orders::CheckStockService).to receive(:new).and_return(check_stock_service_mock)
|
||||
expect(check_stock_service_mock).to receive(:sufficient_stock?).and_return(false)
|
||||
expect(check_stock_service_mock).to receive(:update_line_items).and_return(order.variants)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user