diff --git a/config/routes.rb b/config/routes.rb index 6c637f306e..b129967ca5 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -86,6 +86,10 @@ Openfoodnetwork::Application.routes.draw do end end + # Temporary re-routing for any pending Stripe payments still using the old return URL + match '/checkout', via: :get, controller: "payment_gateways/stripe", action: "confirm", + constraints: ->(request) { request["payment_intent"]&.start_with?("pm_") } + get '/checkout', to: 'checkout#edit' put '/checkout', to: 'checkout#update', as: :update_checkout get '/checkout/:state', to: 'checkout#edit', as: :checkout_state diff --git a/spec/routing/stripe_spec.rb b/spec/routing/stripe_spec.rb new file mode 100644 index 0000000000..f104b0c6d9 --- /dev/null +++ b/spec/routing/stripe_spec.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +require "spec_helper" + +describe "routing for Stripe return URLS", type: :routing do + before do + allow_any_instance_of(SplitCheckoutConstraint).to receive(:current_user) { build(:user) } + end + + it "routes /checkout to checkout#edit" do + expect(get: "checkout"). + to route_to("checkout#edit") + end + + it "routes /checkout?test=123 to checkout#edit" do + expect(get: "/checkout?test=123"). + to route_to(controller: "checkout", action: "edit", test: "123") + end + + it "routes /checkout?payment_intent=pm_123 to payment_gateways/stripe#confirm" do + expect(get: "/checkout?payment_intent=pm_123"). + to route_to(controller: "payment_gateways/stripe", action: "confirm", payment_intent: "pm_123") + end +end