Add re-routing for any unprocessed payments still using old return URL

This commit is contained in:
Matt-Yorkley
2021-12-31 14:41:41 +00:00
parent 5a2c14e79a
commit 2f39f5bac4
2 changed files with 38 additions and 14 deletions

View File

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

View File

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