diff --git a/config/routes.rb b/config/routes.rb index 152b9c1435..0fa8f94a0a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -68,6 +68,12 @@ Openfoodnetwork::Application.routes.draw do resources :callbacks, only: [:index] resources :webhooks, only: [:create] end + + # Temporary re-routing for any pending Stripe payments still using the old return URLs + constraints ->(request) { request["payment_intent"]&.start_with?("pm_") } do + match "/checkout", via: :get, controller: "payment_gateways/stripe", action: "confirm" + match "/orders/:order_number", via: :get, controller: "payment_gateways/stripe", action: "authorize" + end namespace :payment_gateways do get "/paypal", to: "paypal#express", as: :paypal_express @@ -87,10 +93,6 @@ 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 index f104b0c6d9..50121dd671 100644 --- a/spec/routing/stripe_spec.rb +++ b/spec/routing/stripe_spec.rb @@ -7,18 +7,40 @@ describe "routing for Stripe return URLS", type: :routing 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") + context "checkout return URLs" do + 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 - it "routes /checkout?test=123 to checkout#edit" do - expect(get: "/checkout?test=123"). - to route_to(controller: "checkout", action: "edit", test: "123") - end + context "authorization return URLs" do + let(:order) { create(:order) } - 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") + it "routes /orders/:number to spree/orders#show" do + expect(get: "orders/#{order.number}"). + to route_to(controller: "spree/orders", action: "show", id: order.number) + end + + it "routes /orders/:number?test=123 to spree/orders#show" do + expect(get: "/orders/#{order.number}?test=123"). + to route_to(controller: "spree/orders", action: "show", id: order.number, test: "123") + end + + it "routes /orders/:number?payment_intent=pm_123 to payment_gateways/stripe#authorize" do + expect(get: "/orders/#{order.number}?payment_intent=pm_123"). + to route_to(controller: "payment_gateways/stripe", action: "authorize", + order_number: order.number, payment_intent: "pm_123") + end end end