Merge pull request #8568 from Matt-Yorkley/paypal-controller

Move paypal controller
This commit is contained in:
Filipe
2021-12-15 18:12:27 +00:00
committed by GitHub
8 changed files with 16 additions and 23 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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