Sha256: 1bc985ba8a16ec5e5148b78aef3855a50f30fde2a63c4bbc27d52729cd44e0ab

Contents?: true

Size: 1.5 KB

Versions: 5

Compression:

Stored size: 1.5 KB

Contents

class Store::CheckoutsController < Store::StoreController
  layout "storefront"

  def create
    unless current_cart.unfinished?
      render :json => "This order is already finished!", :status => :unprocessable_entity and return
    end

    @payment = CreditCardPayment.new(params[:payment])
    @payment.user_agreement = params[:payment][:user_agreement]
    current_cart.special_instructions = special_instructions
    
    @checkout = Checkout.new(current_cart, @payment)
    
    if @checkout.valid? && @checkout.finish
      @order = @checkout.order
      render :thanks and return
    else      
      flash[:error] = @checkout.message
      redirect_to store_order_path(params[:payment][:customer])
    end
  rescue Exception => e
    Exceptional.context(:params => filter(params))
    Exceptional.handle(e, "Checkout failed!")    
    Rails.logger.error(e.backtrace)
    Rails.logger.error(e.message)
    
    flash[:error] = "We're sorry but we could not process the sale.  Please make sure all fields are filled out accurately"
    redirect_to store_order_path
  end

  def dook
    @order = Order.find(154)
    render :thanks
  end

  def filter(params)
    filters = Rails.application.config.filter_parameters
    f = ActionDispatch::Http::ParameterFilter.new filters
    f.filter params
  end

  private
    def special_instructions
      instructions = []
      params.fetch(:special_instructions, []).each do |event_id, response|
        instructions << response
      end
      instructions.join(" ")
    end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
artfully_ose-1.2.0.pre.15 app/controllers/store/checkouts_controller.rb
artfully_ose-1.2.0.pre.12 app/controllers/store/checkouts_controller.rb
artfully_ose-1.2.0.pre.11 app/controllers/store/checkouts_controller.rb
artfully_ose-1.2.0.pre.10 app/controllers/store/checkouts_controller.rb
artfully_ose-1.2.0.pre.9 app/controllers/store/checkouts_controller.rb