Adapt cancel redirect for better spree paypal express

This commit is contained in:
Rohan Mitchell
2014-07-23 14:54:09 +10:00
parent 5c5e7e8ed3
commit 3b28981400
4 changed files with 17 additions and 14 deletions

View File

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

View 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

View File

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

View 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