Add route to catch pre-existing payments which may still use Checkout#edit as return URL

This commit is contained in:
Matt-Yorkley
2021-12-06 00:38:13 +00:00
parent 789c29f678
commit 7fe770a855
2 changed files with 28 additions and 0 deletions

View File

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

View File

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