mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Adding Paypal plumbing
This commit is contained in:
@@ -4,6 +4,7 @@ class Shop::CheckoutController < Spree::CheckoutController
|
||||
prepend_before_filter :require_order_cycle
|
||||
prepend_before_filter :require_distributor_chosen
|
||||
skip_before_filter :check_registration
|
||||
skip_before_filter :redirect_to_paypal_express_form_if_needed
|
||||
|
||||
include EnterprisesHelper
|
||||
|
||||
@@ -14,7 +15,12 @@ class Shop::CheckoutController < Spree::CheckoutController
|
||||
if @order.update_attributes(params[:order])
|
||||
fire_event('spree.checkout.update')
|
||||
|
||||
|
||||
while @order.state != "complete"
|
||||
if @order.state == "payment"
|
||||
return if redirect_to_paypal_express_form_if_needed
|
||||
end
|
||||
|
||||
if @order.next
|
||||
state_callback(:after)
|
||||
else
|
||||
@@ -96,6 +102,15 @@ class Shop::CheckoutController < Spree::CheckoutController
|
||||
render :edit and return
|
||||
end
|
||||
|
||||
redirect_to(paypal_payment_order_checkout_url(@order, :payment_method_id => payment_method.id)) and return
|
||||
redirect_to(paypal_payment_order_checkout_url(@order, :payment_method_id => payment_method.id))
|
||||
true
|
||||
|
||||
end
|
||||
|
||||
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.shop_checkout_url
|
||||
opts
|
||||
end
|
||||
alias_method_chain :order_opts, :new_cancel_return_url
|
||||
end
|
||||
|
||||
@@ -37,3 +37,6 @@ Openfoodnetwork::Application.configure do
|
||||
# Print deprecation notices to the stderr
|
||||
config.active_support.deprecation = :stderr
|
||||
end
|
||||
|
||||
# Allows us to use _url helpers in Rspec
|
||||
Rails.application.routes.default_url_options[:host] = 'test.host'
|
||||
|
||||
@@ -50,7 +50,7 @@ describe Shop::CheckoutController do
|
||||
end
|
||||
|
||||
describe "Paypal routing" do
|
||||
let(:payment_method) { create(:payment_method) }
|
||||
let(:payment_method) { create(:payment_method, type: "Spree::BillingIntegration::PaypalExpress") }
|
||||
before do
|
||||
controller.stub(:current_distributor).and_return(distributor)
|
||||
controller.stub(:current_order_cycle).and_return(order_cycle)
|
||||
@@ -59,7 +59,13 @@ describe Shop::CheckoutController do
|
||||
|
||||
it "should check the payment method for Paypalness if we've selected one" do
|
||||
Spree::PaymentMethod.should_receive(:find).with(payment_method.id.to_s).and_return payment_method
|
||||
order.stub(:update_attributes).and_return true
|
||||
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 == shop_checkout_url
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user