Skip to content

Instantly share code, notes, and snippets.

@rounders
Created September 15, 2010 04:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rounders/580245 to your computer and use it in GitHub Desktop.
Save rounders/580245 to your computer and use it in GitHub Desktop.
# add to site_extension.rb
Checkout.class_eval do
state_machine do
before_transition :to => 'confirm' do |checkout, transition|
!checkout.payments.first.nil? && !checkout.payments.first.source_id.nil?
end
end
end
# override update method in CheckoutsController
CheckoutsController.class_eval do
def update
load_object
# call the edit hooks for the current step in case we experience validation failure and need to edit again
edit_hooks
@checkout.enable_validation_group(@checkout.state.to_sym)
@prev_state = @checkout.state
before :update
begin
if @checkout.update_attributes object_params
update_hooks
@checkout.order.update_totals!
after :update
next_step
if @checkout.completed_at
return complete_checkout
end
else
after :update_fails
set_flash :update_fails
end
rescue Spree::GatewayError => ge
logger.debug("#{ge}:\n#{ge.backtrace.join("\n")}")
flash.now[:error] = t("unable_to_authorize_credit_card") + ": #{ge.message}"
rescue
logger.debug("tried to move beyond payment checkout without entering payment info")
end
render 'edit'
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment