Class: Admin::OrdersController

Inherits:
ApplicationController
  • Object
show all
Includes:
Effective::CrudController
Defined in:
app/controllers/admin/orders_controller.rb

Instance Method Summary collapse

Instance Method Details

#bulk_send_payment_requestObject



90
91
92
93
94
95
96
97
98
99
100
101
# File 'app/controllers/admin/orders_controller.rb', line 90

def bulk_send_payment_request
  @orders = Effective::Order.was_not_purchased.where(id: params[:ids])

  begin
    authorize_effective_order!

    @orders.each { |order| order.send_payment_request_to_buyer! }
    render json: { status: 200, message: "Successfully sent #{@orders.length} payment request emails"}
  rescue Exception => e
    render json: { status: 500, message: "Bulk send payment request error: #{e.message}" }
  end
end

#checkoutObject

The show page posts to this action See Effective::OrdersController checkout



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'app/controllers/admin/orders_controller.rb', line 40

def checkout
  @order = Effective::Order.was_not_purchased.find(params[:id])

  authorize_effective_order!

  @page_title ||= 'Checkout'

  if request.get?
    @order.assign_confirmed_if_valid!
    return render(:checkout)
  end

  # Otherwise a post
  @order.assign_attributes(checkout_params)

  if (@order.confirm! rescue false)
    redirect_to(effective_orders.checkout_admin_order_path(@order))
  else
    flash.now[:danger] = "Unable to proceed: #{flash_errors(@order)}. Please try again."
    render :checkout
  end
end

#createObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/controllers/admin/orders_controller.rb', line 23

def create
  @order = Effective::Order.new
  @order.assign_attributes(permitted_params)

  authorize_effective_order!

  @page_title ||= 'New Order'

  if save_resource(@order, :pending)
    respond_with_success(@order, :save)
  else
    respond_with_error(@order, :save)
  end
end

#destroyObject



63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'app/controllers/admin/orders_controller.rb', line 63

def destroy
  @order = Effective::Order.all.was_not_purchased.find(params[:id])

  authorize_effective_order!

  if @order.destroy
    flash[:success] = 'Successfully deleted order'
  else
    flash[:danger] = "Unable to delete order: #{@order.errors.full_messages.to_sentence}"
  end

  redirect_to(effective_orders.admin_orders_path)
end

#send_payment_requestObject



77
78
79
80
81
82
83
84
85
86
87
88
# File 'app/controllers/admin/orders_controller.rb', line 77

def send_payment_request
  @order = Effective::Order.was_not_purchased.find(params[:id])
  authorize_effective_order!

  if @order.send_payment_request_to_buyer!
    flash[:success] = "A request for payment has been sent to #{@order.emails_send_to}"
  else
    flash[:danger] = 'Unable to send payment request'
  end

  redirect_back(fallback_location: effective_orders.admin_order_path(@order))
end