Class: Effective::OrdersController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- Effective::OrdersController
show all
- Includes:
- Concerns::Purchase, Providers::AppCheckout, Providers::Ccbill, Providers::Cheque, Providers::Free, Providers::MarkAsPaid, Providers::Moneris, Providers::Paypal, Providers::Pretend, Providers::Refund, Providers::Stripe, Providers::StripeConnect, EffectiveCartsHelper
- Defined in:
- app/controllers/effective/orders_controller.rb
Instance Method Summary
collapse
#stripe_connect_redirect_uri
#stripe_charge
#refund, #refund_params
#pretend
#paypal_postback
#moneris_postback
#mark_as_paid, #mark_as_paid_params
#free, #free_params
#pay_by_cheque
#ccbill_postback
#app_checkout
#current_cart, #link_to_add_to_cart, #link_to_checkout, #link_to_current_cart, #link_to_empty_cart, #link_to_remove_from_cart, #render_cart, #render_purchasables
Instance Method Details
#bulk_send_buyer_receipt ⇒ Object
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
|
# File 'app/controllers/effective/orders_controller.rb', line 163
def bulk_send_buyer_receipt
@orders = Effective::Order.purchased.where(id: params[:ids])
begin
EffectiveOrders.authorize!(self, :index, Effective::Order.new(user: current_user))
@orders.each do |order|
next unless (EffectiveOrders.authorize!(self, :show, order) rescue false)
order.send_order_receipt_to_buyer!
end
render json: { status: 200, message: "Successfully sent #{@orders.length} receipt emails"}
rescue => e
render json: { status: 500, message: "Bulk send buyer receipt error: #{e.message}" }
end
end
|
#create ⇒ Object
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'app/controllers/effective/orders_controller.rb', line 50
def create
@order ||= Effective::Order.new(current_cart, user: current_user)
EffectiveOrders.authorize!(self, :create, @order)
@order.assign_attributes(checkout_params) if params[:effective_order]
Effective::Order.transaction do
begin
@order.save!
redirect_to(effective_orders.order_path(@order)) and return
rescue => e
raise ActiveRecord::Rollback
end
end
flash.now[:danger] = "Unable to proceed: #{@order.errors.full_messages.to_sentence}. Please try again."
render :new
end
|
#declined ⇒ Object
137
138
139
140
141
142
|
# File 'app/controllers/effective/orders_controller.rb', line 137
def declined
@order = Effective::Order.find(params[:id])
EffectiveOrders.authorize!(self, :show, @order)
redirect_to(effective_orders.order_path(@order)) unless @order.declined?
end
|
#my_purchases ⇒ Object
Basically an index page.
Purchases is an Order History page. List of purchased orders
#my_sales ⇒ Object
Sales is a list of what products beign sold by me have been purchased
#new ⇒ Object
This is the entry point for any Checkout button
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'app/controllers/effective/orders_controller.rb', line 26
def new
@order ||= Effective::Order.new(current_cart, user: current_user)
EffectiveOrders.authorize!(self, :new, @order)
@order.valid?
if @order.errors[:order_items].present?
flash[:danger] = @order.errors[:order_items].first
redirect_to(effective_orders.cart_path)
return
elsif @order.errors[:total].present?
flash[:danger] = @order.errors[:total].first
redirect_to(effective_orders.cart_path)
return
end
@order.errors.clear
@order.billing_address.errors.clear if @order.billing_address
@order.shipping_address.errors.clear if @order.shipping_address
end
|
#purchased ⇒ Object
Thank you for Purchasing this Order. This is where a successfully purchased order ends up
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
# File 'app/controllers/effective/orders_controller.rb', line 121
def purchased @order = if params[:id].present?
Effective::Order.find(params[:id])
elsif current_user.present?
Effective::Order.purchased_by(current_user).first
end
if @order.blank?
redirect_to(effective_orders.my_purchases_orders_path) and return
end
EffectiveOrders.authorize!(self, :show, @order)
redirect_to(effective_orders.order_path(@order)) unless @order.purchased?
end
|
#send_buyer_receipt ⇒ Object
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
|
# File 'app/controllers/effective/orders_controller.rb', line 144
def send_buyer_receipt
@order = Effective::Order.find(params[:id])
EffectiveOrders.authorize!(self, :show, @order)
if @order.send_order_receipt_to_buyer!
flash[:success] = "A receipt has been sent to #{@order.user.email}"
else
flash[:danger] = "Unable to send receipt."
end
if respond_to?(:redirect_back)
redirect_back(fallback_location: effective_orders.order_path(@order))
elsif request.referrer.present?
redirect_to :back
else
redirect_to effective_orders.order_path(@order)
end
end
|
#show ⇒ Object
93
94
95
96
97
98
|
# File 'app/controllers/effective/orders_controller.rb', line 93
def show
@order = Effective::Order.find(params[:id])
EffectiveOrders.authorize!(self, :show, @order)
@page_title ||= ((@order.user == current_user && !@order.purchased?) ? 'Checkout' : @order.to_s)
end
|
#update ⇒ Object
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
# File 'app/controllers/effective/orders_controller.rb', line 74
def update
@order ||= Effective::Order.find(params[:id])
EffectiveOrders.authorize!(self, :update, @order)
@order.assign_attributes(checkout_params)
Effective::Order.transaction do
begin
@order.save!
redirect_to(effective_orders.order_path(@order)) and return
rescue => e
raise ActiveRecord::Rollback
end
end
flash.now[:danger] = "Unable to proceed: #{@order.errors.full_messages.to_sentence}. Please try again."
render :edit
end
|