mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-01 02:03:22 +00:00
Adapt cancel redirect for better spree paypal express
This commit is contained in:
@@ -141,12 +141,4 @@ class CheckoutController < Spree::CheckoutController
|
||||
render json: {path: main_app.paypal_payment_url(@order, :payment_method_id => payment_method.id)}, status: 200
|
||||
true
|
||||
end
|
||||
|
||||
# Overriding to customize the cancel url
|
||||
def order_opts_with_new_cancel_return_url(order, payment_method_id, stage)
|
||||
opts = order_opts_without_new_cancel_return_url(order, payment_method_id, stage)
|
||||
opts[:cancel_return_url] = main_app.checkout_url
|
||||
opts
|
||||
end
|
||||
alias_method_chain :order_opts, :new_cancel_return_url
|
||||
end
|
||||
|
||||
6
app/controllers/spree/paypal_controller_decorator.rb
Normal file
6
app/controllers/spree/paypal_controller_decorator.rb
Normal file
@@ -0,0 +1,6 @@
|
||||
Spree::PaypalController.class_eval do
|
||||
def cancel
|
||||
flash[:notice] = t('flash.cancel', :scope => 'paypal')
|
||||
redirect_to main_app.checkout_path
|
||||
end
|
||||
end
|
||||
@@ -108,7 +108,7 @@ describe CheckoutController do
|
||||
end
|
||||
|
||||
describe "Paypal routing" do
|
||||
let(:payment_method) { create(:payment_method, type: "Spree::BillingIntegration::PaypalExpress") }
|
||||
let(:payment_method) { create(:payment_method, type: "Spree::Gateway::PayPalExpress") }
|
||||
before do
|
||||
controller.stub(:current_distributor).and_return(distributor)
|
||||
controller.stub(:current_order_cycle).and_return(order_cycle)
|
||||
@@ -121,10 +121,5 @@ describe CheckoutController do
|
||||
order.stub(:state).and_return "payment"
|
||||
spree_post :update, order: {payments_attributes: [{payment_method_id: payment_method.id}]}
|
||||
end
|
||||
|
||||
it "should override the cancel return url" do
|
||||
controller.stub(:params).and_return({payment_method_id: payment_method.id})
|
||||
controller.send(:order_opts, order, payment_method.id, 'payment')[:cancel_return_url].should == checkout_url
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
10
spec/controllers/spree/paypal_controller_spec.rb
Normal file
10
spec/controllers/spree/paypal_controller_spec.rb
Normal file
@@ -0,0 +1,10 @@
|
||||
require 'spec_helper'
|
||||
|
||||
module Spree
|
||||
describe PaypalController do
|
||||
it "should redirect back to checkout after cancel" do
|
||||
spree_get :cancel
|
||||
response.should redirect_to checkout_path
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user