def admin_status_options
      return if !user_is_allowed('categories', 'view')
      statuses = ['cart', 'pending', 'ready to ship', 'shipped', 'canceled']
      options = []
      statuses.each do |s|
        options << {
          'text' => s,
          'value' => s
        }
      end       
      render :json => options    
    end
def admin_status_options
      return if !user_is_allowed('categories', 'view')
      statuses = ['cart', 'pending', 'ready to ship', 'shipped', 'canceled']
      options = []
      statuses.each do |s|
        options << {
          'text' => s,
          'value' => s
        }
      end       
      render :json => options    
    end
GET /admin/orders/:id/void
def void
  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'
    response.error = "This order has already been captured, you will need to refund instead"
  else
    if order.total < order.amount_discounted || PaymentProcessor.void(order)
      order.financial_status = 'cancelled'
      order.status = 'voided'
      order.save

      response.success = "Order voided successfully"
    else
      response.error = "Error voiding order."
    end
  end

  render json: response
end
 GET /admin/orders/:id/refund
 def refund
   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'
     response.error = "This order hasn't been captured yet, you will need to void instead"
   else
     ap order.total
     ap order.amount_discounted

     if order.total < order.amount_discounted || PaymentProcessor.refund(order)
       order.financial_status = 'refunded'
       order.status = 'refunded'
       order.save

       discount = order.discounts.first
       ap '==========================='
       ap order.amount_discounted + discount.amount_current
       ap '==========================='
       discount.update_attribute(:amount_current, order.amount_discounted + discount.amount_current) if order.discounts.any?

       response.success = "Order refunded successfully"
     else
       response.error = "Error refunding order."
     end
   end

   render json: response
 end
 GET /admin/orders/status-options