mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-13 23:37:47 +00:00
Merge pull request #8568 from Matt-Yorkley/paypal-controller
Move paypal controller
This commit is contained in:
@@ -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 || "",
|
||||
@@ -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
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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'
|
||||
)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user