From 0d620aac94fc590afc9f7487bac17ce9976adb0e Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Sat, 4 Dec 2021 11:45:11 +0000 Subject: [PATCH 1/7] Move paypal_controller out of spree namespace --- .../{spree => payment_gateways}/paypal_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename app/controllers/{spree => payment_gateways}/paypal_controller.rb (99%) diff --git a/app/controllers/spree/paypal_controller.rb b/app/controllers/payment_gateways/paypal_controller.rb similarity index 99% rename from app/controllers/spree/paypal_controller.rb rename to app/controllers/payment_gateways/paypal_controller.rb index 1bc70cd382..13eda152d4 100644 --- a/app/controllers/spree/paypal_controller.rb +++ b/app/controllers/payment_gateways/paypal_controller.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -module Spree +module PaymentGateways class PaypalController < ::BaseController include OrderStockCheck From 5a1aa300d5ed24438c5fd55dbbef304f24181d7e Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Sat, 4 Dec 2021 11:48:08 +0000 Subject: [PATCH 2/7] Delete route to non-existant checkout controller action --- config/routes.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/config/routes.rb b/config/routes.rb index b124475299..1909d56b5a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -81,7 +81,6 @@ Openfoodnetwork::Application.routes.draw do get '/checkout', to: 'checkout#edit' put '/checkout', to: 'checkout#update', as: :update_checkout get '/checkout/:state', to: 'checkout#edit', as: :checkout_state - get '/checkout/paypal_payment/:order_id', to: 'checkout#paypal_payment', as: :paypal_payment get 'embedded_shopfront/shopfront_session', to: 'application#shopfront_session' post 'embedded_shopfront/enable', to: 'application#enable_embedded_styles' From 575f409ebf9b7e32da20fc61a73fc905e6a32a01 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Sat, 4 Dec 2021 11:49:56 +0000 Subject: [PATCH 3/7] Delete routes to non-existant content controller --- config/routes/spree.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/config/routes/spree.rb b/config/routes/spree.rb index 461a03d742..c405a761db 100644 --- a/config/routes/spree.rb +++ b/config/routes/spree.rb @@ -169,8 +169,6 @@ Spree::Core::Engine.routes.draw do resources :products # Used by spree_paypal_express - get '/content/cvv', :to => 'content#cvv', :as => :cvv - get '/content/*path', :to => 'content#show', :as => :content get '/paypal', :to => "paypal#express", :as => :paypal_express get '/paypal/confirm', :to => "paypal#confirm", :as => :confirm_paypal get '/paypal/cancel', :to => "paypal#cancel", :as => :cancel_paypal From 0b48fa540a67dfd0d3ac0ce169c83e9cb32e7b35 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Sat, 4 Dec 2021 11:52:35 +0000 Subject: [PATCH 4/7] Move paypal routes out of spree namespace --- config/routes.rb | 7 +++++++ config/routes/spree.rb | 6 ------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index 1909d56b5a..df8970aefc 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -68,6 +68,13 @@ Openfoodnetwork::Application.routes.draw do resources :callbacks, only: [:index] resources :webhooks, only: [:create] end + + namespace :payment_gateways do + get "/paypal", to: "paypal#express", as: :paypal_express + get "/paypal/confirm", to: "paypal#confirm", as: :confirm_paypal + get "/paypal/cancel", to: "paypal#cancel", as: :cancel_paypal + get "/paypal/notify", to: "paypal#notify", as: :notify_paypal + end constraints SplitCheckoutConstraint.new do get '/checkout', to: 'split_checkout#edit' diff --git a/config/routes/spree.rb b/config/routes/spree.rb index c405a761db..1e495f3122 100644 --- a/config/routes/spree.rb +++ b/config/routes/spree.rb @@ -167,10 +167,4 @@ Spree::Core::Engine.routes.draw do end resources :products - - # Used by spree_paypal_express - get '/paypal', :to => "paypal#express", :as => :paypal_express - get '/paypal/confirm', :to => "paypal#confirm", :as => :confirm_paypal - get '/paypal/cancel', :to => "paypal#cancel", :as => :cancel_paypal - get '/paypal/notify', :to => "paypal#notify", :as => :notify_paypal end From f101b06226239b58c1bafe7ab695ae09a2438383 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Sat, 4 Dec 2021 12:03:09 +0000 Subject: [PATCH 5/7] Update all references to paypal routes --- app/controllers/payment_gateways/paypal_controller.rb | 4 ++-- app/services/checkout/paypal_redirect.rb | 10 +++------- spec/requests/checkout/paypal_spec.rb | 2 +- spec/system/consumer/shopping/checkout_paypal_spec.rb | 2 +- 4 files changed, 7 insertions(+), 11 deletions(-) diff --git a/app/controllers/payment_gateways/paypal_controller.rb b/app/controllers/payment_gateways/paypal_controller.rb index 13eda152d4..a912e0b624 100644 --- a/app/controllers/payment_gateways/paypal_controller.rb +++ b/app/controllers/payment_gateways/paypal_controller.rb @@ -80,10 +80,10 @@ module PaymentGateways SetExpressCheckoutRequestDetails: { InvoiceID: order.number, BuyerEmail: order.email, - ReturnURL: spree.confirm_paypal_url( + ReturnURL: payment_gateways_confirm_paypal_url( payment_method_id: params[:payment_method_id], utm_nooverride: 1 ), - CancelURL: spree.cancel_paypal_url, + CancelURL: payment_gateways_cancel_paypal_url, SolutionType: payment_method.preferred_solution.presence || "Mark", LandingPage: payment_method.preferred_landing_page.presence || "Billing", cppheaderimage: payment_method.preferred_logourl.presence || "", diff --git a/app/services/checkout/paypal_redirect.rb b/app/services/checkout/paypal_redirect.rb index 9c4b192ac1..798af3f69c 100644 --- a/app/services/checkout/paypal_redirect.rb +++ b/app/services/checkout/paypal_redirect.rb @@ -3,6 +3,8 @@ # Provides the redirect path if a redirect to the payment gateway is needed module Checkout class PaypalRedirect + include Rails.application.routes.url_helpers + def initialize(params) @params = params end @@ -15,13 +17,7 @@ module Checkout payment_method = Spree::PaymentMethod.find(payment_method_id) return unless payment_method.is_a?(Spree::Gateway::PayPalExpress) - spree_routes_helper.paypal_express_path(payment_method_id: payment_method.id) - end - - private - - def spree_routes_helper - Spree::Core::Engine.routes.url_helpers + payment_gateways_paypal_express_path(payment_method_id: payment_method.id) end end end diff --git a/spec/requests/checkout/paypal_spec.rb b/spec/requests/checkout/paypal_spec.rb index c8ebbd7585..44bca06ae5 100644 --- a/spec/requests/checkout/paypal_spec.rb +++ b/spec/requests/checkout/paypal_spec.rb @@ -55,7 +55,7 @@ describe "checking out an order with a paypal express payment method", type: :re expect(order.all_adjustments.payment_fee.count).to eq 1 expect(order.all_adjustments.payment_fee.first.amount).to eq 1.5 - get spree.confirm_paypal_path, params: params + get payment_gateways_confirm_paypal_path, params: params # Processing was successful, order is complete expect(response).to redirect_to order_path(order, token: order.token) diff --git a/spec/system/consumer/shopping/checkout_paypal_spec.rb b/spec/system/consumer/shopping/checkout_paypal_spec.rb index 291772a4c1..dbf3b8eb53 100644 --- a/spec/system/consumer/shopping/checkout_paypal_spec.rb +++ b/spec/system/consumer/shopping/checkout_paypal_spec.rb @@ -72,7 +72,7 @@ describe "Check out with Paypal", js: true do # jump straight to being redirected back to OFN with a "confirmed" payment. stub_paypal_response( success: true, - redirect: spree.confirm_paypal_path( + redirect: payment_gateways_confirm_paypal_path( payment_method_id: paypal.id, token: "t123", PayerID: 'p123' ) ) From 9fa19cb772428ed8e9449fb1709ac35fe79d1df1 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Sat, 4 Dec 2021 12:23:42 +0000 Subject: [PATCH 6/7] Update namespacing in specs --- .../{spree => payment_gateways}/paypal_controller_spec.rb | 2 +- spec/support/request/paypal_helper.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename spec/controllers/{spree => payment_gateways}/paypal_controller_spec.rb (99%) diff --git a/spec/controllers/spree/paypal_controller_spec.rb b/spec/controllers/payment_gateways/paypal_controller_spec.rb similarity index 99% rename from spec/controllers/spree/paypal_controller_spec.rb rename to spec/controllers/payment_gateways/paypal_controller_spec.rb index babe102935..c610e88e8d 100644 --- a/spec/controllers/spree/paypal_controller_spec.rb +++ b/spec/controllers/payment_gateways/paypal_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -module Spree +module PaymentGateways describe PaypalController, type: :controller do context '#cancel' do it 'redirects back to checkout' do diff --git a/spec/support/request/paypal_helper.rb b/spec/support/request/paypal_helper.rb index 6796bb14b5..ced242b741 100644 --- a/spec/support/request/paypal_helper.rb +++ b/spec/support/request/paypal_helper.rb @@ -10,7 +10,7 @@ module PaypalHelper set_express_checkout: paypal_response, express_checkout_url: options[:redirect] ) - allow_any_instance_of(Spree::PaypalController).to receive(:provider). + allow_any_instance_of(PaymentGateways::PaypalController).to receive(:provider). and_return(paypal_provider) end From a4794b22d55e4ca914aa62fbe79e5e719fa61fe2 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Sat, 4 Dec 2021 12:55:15 +0000 Subject: [PATCH 7/7] Delete route to non-existent paypal controller action --- config/routes.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/config/routes.rb b/config/routes.rb index df8970aefc..9eec3a5255 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -73,7 +73,6 @@ Openfoodnetwork::Application.routes.draw do get "/paypal", to: "paypal#express", as: :paypal_express get "/paypal/confirm", to: "paypal#confirm", as: :confirm_paypal get "/paypal/cancel", to: "paypal#cancel", as: :cancel_paypal - get "/paypal/notify", to: "paypal#notify", as: :notify_paypal end constraints SplitCheckoutConstraint.new do