From 7fe770a85579222672e63a4004581cbc4d2f6c3e Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Mon, 6 Dec 2021 00:38:13 +0000 Subject: [PATCH] Add route to catch pre-existing payments which may still use Checkout#edit as return URL --- config/routes.rb | 4 ++++ spec/routing/stripe_spec.rb | 24 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 spec/routing/stripe_spec.rb 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