diff --git a/app/controllers/spree/paypal_controller.rb b/app/controllers/payment_gateways/paypal_controller.rb similarity index 98% rename from app/controllers/spree/paypal_controller.rb rename to app/controllers/payment_gateways/paypal_controller.rb index 1bc70cd382..a912e0b624 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 @@ -80,10 +80,10 @@ module Spree 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/config/routes.rb b/config/routes.rb index b124475299..9eec3a5255 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 + + 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 + end constraints SplitCheckoutConstraint.new do get '/checkout', to: 'split_checkout#edit' @@ -81,7 +87,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' diff --git a/config/routes/spree.rb b/config/routes/spree.rb index 461a03d742..1e495f3122 100644 --- a/config/routes/spree.rb +++ b/config/routes/spree.rb @@ -167,12 +167,4 @@ Spree::Core::Engine.routes.draw do end 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 - get '/paypal/notify', :to => "paypal#notify", :as => :notify_paypal end 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/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/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 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' ) )