def capture_funds
      return if !user_is_allowed('orders', 'edit')
      
      response = Caboose::StdClass.new({
        'refresh' => nil,
        'error'   => nil,
        'success' => nil
      })
      
      order = Order.find(params[:id])
      
      if order.financial_status == 'captured'
        resp.error = "Funds for this order have already been captured."    
      elsif order.total > order.auth_amount
        resp.error = "The order total exceeds the authorized amount."
      else
        if PaymentProcessor.capture(order)
          order.update_attribute(:financial_status, 'captured')
          response.success = 'Captured funds successfully'
        else
          response.error = 'Error capturing funds'
        end
          
        #if (order.discounts.any? && order.total < order.discounts.first.amount_current) || PaymentProcessor.capture(order)
        #  order.financial_status = 'captured'
        #  order.save
        #  
        #  if order.discounts.any?
        #    order.update_attribute(:amount_discounted, order.discounts.first.amount_current)
        #    order.update_gift_cards
        #  end
        #  
        #  response.success = "Captured funds successfully"
        #else
        #  response.error = "Error capturing funds."
        #end
      end
      
      render :json => response
    end
def capture_funds
      return if !user_is_allowed('orders', 'edit')
      
      response = Caboose::StdClass.new({
        'refresh' => nil,
        'error'   => nil,
        'success' => nil
      })
      
      order = Order.find(params[:id])
      
      if order.financial_status == 'captured'
        resp.error = "Funds for this order have already been captured."    
      elsif order.total > order.auth_amount
        resp.error = "The order total exceeds the authorized amount."
      else
        if PaymentProcessor.capture(order)
          order.update_attribute(:financial_status, 'captured')
          response.success = 'Captured funds successfully'
        else
          response.error = 'Error capturing funds'
        end
          
        #if (order.discounts.any? && order.total < order.discounts.first.amount_current) || PaymentProcessor.capture(order)
        #  order.financial_status = 'captured'
        #  order.save
        #  
        #  if order.discounts.any?
        #    order.update_attribute(:amount_discounted, order.discounts.first.amount_current)
        #    order.update_gift_cards
        #  end
        #  
        #  response.success = "Captured funds successfully"
        #else
        #  response.error = "Error capturing funds."
        #end
      end
      
      render :json => response
    end
GET /admin/orders/:id/capture