Skip to content

Instantly share code, notes, and snippets.

@lightandshadow68
Created March 18, 2010 05:09
Show Gist options
  • Save lightandshadow68/336065 to your computer and use it in GitHub Desktop.
Save lightandshadow68/336065 to your computer and use it in GitHub Desktop.
CheckoutsController.class_eval do
# customized verison of the standard r_c update method (since we need to handle gateway errors, etc)
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 object.update_attributes object_params
update_hooks
@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}"
end
# -- Set error flash if coupon code was provided but invalid
if params[:checkout] and params[:checkout][:coupon_code]
coupon = Coupon.find_by_code(params[:checkout][:coupon_code].upcase)
flash.now[:error] = t("invalid_coupon_code") unless coupon
end
# -- end coupon check
render 'edit'
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment