Class: Effective::OrdersController

Inherits:
ApplicationController
  • Object
show all
Includes:
Concerns::Purchase, CrudController, Providers::Cheque, Providers::Deluxe, Providers::DeluxeDelayed, Providers::DeluxeDelayedPurchase, Providers::Etransfer, Providers::Free, Providers::MarkAsPaid, Providers::Moneris, Providers::MonerisCheckout, Providers::Paypal, Providers::Phone, Providers::Pretend, Providers::Refund, Providers::Stripe
Defined in:
app/controllers/effective/orders_controller.rb

Instance Method Summary collapse

Methods included from Providers::Stripe

#stripe

Methods included from Providers::Refund

#refund, #refund_params

Methods included from Providers::Pretend

#pretend, #pretend_params

Methods included from Providers::Phone

#phone, #phone_params

Methods included from Providers::Paypal

#paypal_postback

Methods included from Providers::MonerisCheckout

#moneris_checkout

Methods included from Providers::Moneris

#moneris_postback

Methods included from Providers::MarkAsPaid

#mark_as_paid, #mark_as_paid_params

Methods included from Providers::Free

#free, #free_params

Methods included from Providers::Etransfer

#etransfer, #etransfer_params

Methods included from Providers::DeluxeDelayedPurchase

#deluxe_delayed_purchase, #deluxe_delayed_purchase_params

Methods included from Providers::DeluxeDelayed

#deluxe_delayed

Methods included from Providers::Deluxe

#deluxe

Methods included from Providers::Cheque

#cheque, #cheque_params

Instance Method Details

#bulk_send_buyer_receiptObject



127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'app/controllers/effective/orders_controller.rb', line 127

def bulk_send_buyer_receipt
  @orders = Effective::Order.deep.purchased.where(id: params[:ids])

  begin
    EffectiveResources.authorize!(self, :index, Effective::Order.new(user: current_user))

    @orders.each do |order|
      next unless EffectiveResources.authorized?(self, :show, order)
      order.send_order_receipt_to_buyer!
    end

    render json: { status: 200, message: "Successfully sent #{@orders.length} receipt emails"}
  rescue Exception => e
    render json: { status: 500, message: "Bulk send buyer receipt error: #{e.message}" }
  end
end

#createObject

Confirms an order from the cart.



47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'app/controllers/effective/orders_controller.rb', line 47

def create
  @order ||= Effective::Order.deep.new(view_context.current_cart)
  EffectiveResources.authorize!(self, :create, @order)

  @order.assign_attributes(checkout_params)

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

#declinedObject



107
108
109
110
# File 'app/controllers/effective/orders_controller.rb', line 107

def declined
  @order = Effective::Order.deep.declined.find(params[:id])
  EffectiveResources.authorize!(self, :show, @order)
end

#deferredObject



102
103
104
105
# File 'app/controllers/effective/orders_controller.rb', line 102

def deferred
  @order = Effective::Order.deep.deferred.find(params[:id])
  EffectiveResources.authorize!(self, :show, @order)
end

#editObject

Always step1



74
75
76
77
78
79
# File 'app/controllers/effective/orders_controller.rb', line 74

def edit
  @order ||= Effective::Order.deep.was_not_purchased.find(params[:id])
  @page_title ||= view_context.order_page_title(@order)

  EffectiveResources.authorize!(self, :edit, @order)
end

#newObject

If you want to use the Add to Cart -> Checkout flow Add one or more items however you do. redirect_to effective_orders.new_order_path, which is here. This is the entry point for any Checkout button. It displayes an order based on the cart Always step1



34
35
36
37
38
39
40
41
42
43
44
# File 'app/controllers/effective/orders_controller.rb', line 34

def new
  @order ||= Effective::Order.deep.new(view_context.current_cart)

  EffectiveResources.authorize!(self, :new, @order)

  unless @order.valid?
    flash[:danger] = "Unable to proceed: #{flash_errors(@order)}. Please try again."
    redirect_to(effective_orders.cart_path)
    return
  end
end

#purchasedObject

Thank you for Purchasing this Order. This is where a successfully purchased order ends up



97
98
99
100
# File 'app/controllers/effective/orders_controller.rb', line 97

def purchased # Thank You!
  @order = Effective::Order.deep.purchased.find(params[:id])
  EffectiveResources.authorize!(self, :show, @order)
end

#send_buyer_receiptObject

This is used by both the Admin and User



113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'app/controllers/effective/orders_controller.rb', line 113

def send_buyer_receipt
  @order = Effective::Order.deep.purchased.find(params[:id])

  EffectiveResources.authorize!(self, :show, @order)

  if @order.send_order_receipt_to_buyer!
    flash[:success] = "A receipt has been sent to #{@order.emails_send_to}"
  else
    flash[:danger] = "Unable to send receipt."
  end

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

#showObject

If you want to use the order = Effective::Order.new(@thing); order.save! flow Add one or more items to the order. redirect_to effective_orders.order_path(order), which is here This is the entry point for an existing order. Might render step1 or step2



66
67
68
69
70
71
# File 'app/controllers/effective/orders_controller.rb', line 66

def show
  @order ||= Effective::Order.deep.find(params[:id])
  @page_title ||= view_context.order_page_title(@order)

  EffectiveResources.authorize!(self, :show, @order)
end

#updateObject

Confirms the order from existing order



82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'app/controllers/effective/orders_controller.rb', line 82

def update
  @order ||= Effective::Order.deep.was_not_purchased.find(params[:id])
  EffectiveResources.authorize!(self, :update, @order)

  @order.assign_attributes(checkout_params)

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