effective_orders 4.6.1 → 4.6.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/MIT-LICENSE +1 -1
- data/README.md +86 -11
- data/app/controllers/admin/customers_controller.rb +16 -5
- data/app/controllers/admin/order_items_controller.rb +9 -6
- data/app/controllers/admin/orders_controller.rb +81 -17
- data/app/controllers/effective/carts_controller.rb +6 -10
- data/app/controllers/effective/customers_controller.rb +2 -4
- data/app/controllers/effective/orders_controller.rb +23 -27
- data/app/controllers/effective/providers/cheque.rb +1 -3
- data/app/controllers/effective/providers/free.rb +1 -3
- data/app/controllers/effective/providers/mark_as_paid.rb +2 -4
- data/app/controllers/effective/providers/moneris.rb +1 -3
- data/app/controllers/effective/providers/paypal.rb +2 -3
- data/app/controllers/effective/providers/phone.rb +1 -3
- data/app/controllers/effective/providers/pretend.rb +1 -3
- data/app/controllers/effective/providers/refund.rb +1 -3
- data/app/controllers/effective/providers/stripe.rb +1 -3
- data/app/controllers/effective/subscripter_controller.rb +2 -4
- data/app/controllers/effective/webhooks_controller.rb +3 -12
- data/app/datatables/admin/effective_customers_datatable.rb +3 -7
- data/app/datatables/admin/effective_orders_datatable.rb +2 -2
- data/app/datatables/effective_orders_datatable.rb +1 -1
- data/app/mailers/effective/orders_mailer.rb +96 -131
- data/app/models/concerns/acts_as_purchasable.rb +11 -0
- data/app/models/concerns/acts_as_subscribable.rb +6 -0
- data/app/models/effective/access_denied.rb +17 -0
- data/app/models/effective/cart.rb +5 -7
- data/app/models/effective/cart_item.rb +4 -7
- data/app/models/effective/customer.rb +6 -7
- data/app/models/effective/order.rb +42 -51
- data/app/models/effective/order_item.rb +8 -10
- data/app/models/effective/product.rb +6 -9
- data/app/models/effective/subscription.rb +12 -13
- data/app/views/admin/orders/_form.html.haml +9 -5
- data/app/views/admin/orders/_order_item_fields.html.haml +12 -8
- data/app/views/effective/orders/_checkout_step2.html.haml +2 -1
- data/app/views/effective/orders/_order_actions.html.haml +1 -1
- data/config/effective_orders.rb +32 -8
- data/config/routes.rb +17 -16
- data/db/migrate/01_create_effective_orders.rb.erb +0 -4
- data/lib/effective_orders.rb +76 -34
- data/lib/effective_orders/engine.rb +7 -0
- data/lib/effective_orders/version.rb +1 -1
- data/lib/generators/templates/effective_orders_mailer_preview.rb +13 -13
- data/lib/tasks/effective_orders_tasks.rake +2 -2
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 07ed479ba56ebd55dae9b20168feec83435c0264cf7b00738a4438aa5104024e
|
4
|
+
data.tar.gz: 5756b29a14db32c53571fe75991285ed9864864e9a245b2b051886a68ed19229
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8de08c2426a57c57176a585131e211242fad9cb9f3bb18bac6216375798388e951021f6a58354be3c0810c3fa59b9d4b8f4505aae9f24b6377b34c0db8793a3d
|
7
|
+
data.tar.gz: 9a9bba6683d48272c12f4e509617afa99f1721bc53bd448e3689b07782d9b6e8a31cf28b29a031bf0be00ce621f0405eef56d2ca06c1323ec4f306d8a3852c53
|
data/MIT-LICENSE
CHANGED
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Carts, Orders, and collecting payment via Stripe, PayPal and Moneris.
|
4
4
|
|
5
|
-
A Rails Engine to handle the purchase workflow in a Rails application.
|
5
|
+
A Rails Engine to handle the purchase workflow in a Rails 3.2.x / Rails 4 application.
|
6
6
|
|
7
7
|
Also works with Stripe Subscriptions.
|
8
8
|
|
@@ -10,9 +10,17 @@ Sends order receipt emails automatically.
|
|
10
10
|
|
11
11
|
Has Order History, My Purchases, My Sales and Admin screens.
|
12
12
|
|
13
|
-
## effective_orders
|
13
|
+
## Upgrade to effective_orders 4.3
|
14
14
|
|
15
|
-
|
15
|
+
Add the migration
|
16
|
+
|
17
|
+
```
|
18
|
+
add_column :customers, :payment_method_id, :string
|
19
|
+
```
|
20
|
+
|
21
|
+
## effective_orders 4.0
|
22
|
+
|
23
|
+
This is the 4.0 series of effective_orders.
|
16
24
|
|
17
25
|
This requires Twitter Bootstrap 4 and Rails 5.1+
|
18
26
|
|
@@ -152,18 +160,32 @@ Once the database has been migrated, it is time to scaffold/build the CRUD Produ
|
|
152
160
|
|
153
161
|
### Products#new/#edit
|
154
162
|
|
155
|
-
Use an [
|
163
|
+
Use an [effective_form_inputs](https://github.com/code-and-effect/effective_form_inputs#effective-price) effective_price input to enter the price.
|
156
164
|
|
157
165
|
It displays the underlying Integer price as a currency formatted value, ensures that a properly formatted price is entered by the user, and POSTs the appropriate Integer value back to the server.
|
158
166
|
|
159
167
|
This is available for simple_form, formtastic and Rails default FormBuilder.
|
160
168
|
|
161
169
|
```haml
|
162
|
-
=
|
163
|
-
= f.
|
164
|
-
= f.
|
165
|
-
= f.
|
166
|
-
= f.submit
|
170
|
+
= simple_form_for(@product) do |f|
|
171
|
+
= f.input :name
|
172
|
+
= f.input :tax_exempt
|
173
|
+
= f.input :price, as: :effective_price
|
174
|
+
= f.button :submit
|
175
|
+
```
|
176
|
+
|
177
|
+
or
|
178
|
+
|
179
|
+
```ruby
|
180
|
+
= semantic_form_for(@product) do |f|
|
181
|
+
= f.input :price, as: :effective_price
|
182
|
+
```
|
183
|
+
|
184
|
+
or
|
185
|
+
|
186
|
+
```haml
|
187
|
+
= form_for(@product) do |f|
|
188
|
+
= f.effective_price :price
|
167
189
|
```
|
168
190
|
|
169
191
|
### Products#show
|
@@ -265,6 +287,8 @@ end
|
|
265
287
|
|
266
288
|
Of course, there's no mechanism here to prevent someone from just copy&pasting this URL to a friend.
|
267
289
|
|
290
|
+
If you're interested in that kind of restricted-download functionality, please check out [effective_assets](https://github.com/code-and-effect/effective_assets) and the authenticated-read temporary URLs.
|
291
|
+
|
268
292
|
|
269
293
|
### Tax Exempt
|
270
294
|
|
@@ -343,7 +367,54 @@ end
|
|
343
367
|
|
344
368
|
## Authorization
|
345
369
|
|
346
|
-
All authorization checks are handled via the
|
370
|
+
All authorization checks are handled via the config.authorization_method found in the `config/initializers/effective_orders.rb` file.
|
371
|
+
|
372
|
+
It is intended for flow through to CanCan or Pundit, but neither of those gems are required.
|
373
|
+
|
374
|
+
This method is called by the controller action with the appropriate action and resource.
|
375
|
+
|
376
|
+
Action will be one of [:index, :show, :new, :create, :edit, :update, :destroy]
|
377
|
+
|
378
|
+
Resource will the appropriate Effective::Order, Effective::Cart or Effective::Subscription ActiveRecord object or class
|
379
|
+
|
380
|
+
The authorization method is defined in the initializer file:
|
381
|
+
|
382
|
+
```ruby
|
383
|
+
# As a Proc (with CanCan)
|
384
|
+
config.authorization_method = Proc.new { |controller, action, resource| authorize!(action, resource) }
|
385
|
+
```
|
386
|
+
|
387
|
+
```ruby
|
388
|
+
# As a Custom Method
|
389
|
+
config.authorization_method = :my_authorization_method
|
390
|
+
```
|
391
|
+
|
392
|
+
and then in your application_controller.rb:
|
393
|
+
|
394
|
+
```ruby
|
395
|
+
def my_authorization_method(action, resource)
|
396
|
+
current_user.is?(:admin) || EffectivePunditPolicy.new(current_user, resource).send('#{action}?')
|
397
|
+
end
|
398
|
+
```
|
399
|
+
|
400
|
+
or disabled entirely:
|
401
|
+
|
402
|
+
```ruby
|
403
|
+
config.authorization_method = false
|
404
|
+
```
|
405
|
+
|
406
|
+
If the method or proc returns false (user is not authorized) an Effective::AccessDenied exception will be raised
|
407
|
+
|
408
|
+
You can rescue from this exception by adding the following to your application_controller.rb:
|
409
|
+
|
410
|
+
```ruby
|
411
|
+
rescue_from Effective::AccessDenied do |exception|
|
412
|
+
respond_to do |format|
|
413
|
+
format.html { render 'static_pages/access_denied', status: 403 }
|
414
|
+
format.any { render text: 'Access Denied', status: 403 }
|
415
|
+
end
|
416
|
+
end
|
417
|
+
```
|
347
418
|
|
348
419
|
### Permissions
|
349
420
|
|
@@ -381,6 +452,7 @@ Only when the user proceeds to Checkout will they be required to login.
|
|
381
452
|
Upon log in, the session Cart will be assigned to that User's ID, and if the User had a previous existing cart, all CartItems will be merged.
|
382
453
|
|
383
454
|
|
455
|
+
|
384
456
|
You shouldn't need to deal with the Cart object at all, except to make a link from your Site Menu to the 'My Cart' page (as documented above).
|
385
457
|
|
386
458
|
However, if you want to render a Cart on another page, or play with the Cart object directly, you totally can.
|
@@ -428,6 +500,9 @@ If you are using effective_orders to roll your own custom payment workflow, you
|
|
428
500
|
|
429
501
|
Emails will be sent immediately unless `config.mailer[:deliver_method] == :deliver_later`.
|
430
502
|
|
503
|
+
If you are using [Delayed::Job](https://github.com/collectiveidea/delayed_job) to send emails in a background process then you should set the `delayed_job_deliver` option so that `config.mailer[:delayed_job_deliver] == true`.
|
504
|
+
|
505
|
+
|
431
506
|
### Effective::Order Model
|
432
507
|
|
433
508
|
There may be times where you want to deal with the `Effective::Order` object directly.
|
@@ -922,7 +997,7 @@ You should generate separate private and public certificates/keys for this and i
|
|
922
997
|
|
923
998
|
## License
|
924
999
|
|
925
|
-
MIT License.
|
1000
|
+
MIT License. Copyright [Code and Effect Inc.](http://www.codeandeffect.com/)
|
926
1001
|
|
927
1002
|
## Contributing
|
928
1003
|
|
@@ -1,12 +1,23 @@
|
|
1
1
|
module Admin
|
2
2
|
class CustomersController < ApplicationController
|
3
|
-
before_action
|
4
|
-
before_action { EffectiveResources.authorize!(self, :admin, :effective_orders) }
|
3
|
+
before_action :authenticate_user!
|
5
4
|
|
6
|
-
|
5
|
+
layout (EffectiveOrders.layout.kind_of?(Hash) ? EffectiveOrders.layout[:admin_customers] : EffectiveOrders.layout)
|
7
6
|
|
8
|
-
|
9
|
-
|
7
|
+
def index
|
8
|
+
@datatable = Admin::EffectiveCustomersDatatable.new(self)
|
9
|
+
|
10
|
+
@page_title = 'Customers'
|
11
|
+
|
12
|
+
EffectiveOrders.authorize!(self, :admin, :effective_orders)
|
13
|
+
EffectiveOrders.authorize!(self, :index, Effective::Customer)
|
14
|
+
end
|
15
|
+
|
16
|
+
def show
|
17
|
+
@customer = Effective::Customer.find(params[:id])
|
18
|
+
|
19
|
+
@page_title ||= @customer.to_s
|
20
|
+
EffectiveOrders.authorize!(self, :show, Effective::Customer)
|
10
21
|
end
|
11
22
|
|
12
23
|
end
|
@@ -1,13 +1,16 @@
|
|
1
1
|
module Admin
|
2
2
|
class OrderItemsController < ApplicationController
|
3
|
-
before_action
|
4
|
-
before_action { EffectiveResources.authorize!(self, :admin, :effective_orders) }
|
3
|
+
before_action :authenticate_user!
|
5
4
|
|
6
|
-
|
5
|
+
layout (EffectiveOrders.layout.kind_of?(Hash) ? EffectiveOrders.layout[:admin_orders] : EffectiveOrders.layout)
|
7
6
|
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
def index
|
8
|
+
@datatable = Admin::EffectiveOrderItemsDatatable.new(self)
|
9
|
+
|
10
|
+
@page_title = 'Order Items'
|
11
11
|
|
12
|
+
EffectiveOrders.authorize!(self, :admin, :effective_orders)
|
13
|
+
EffectiveOrders.authorize!(self, :index, Effective::OrderItem)
|
14
|
+
end
|
12
15
|
end
|
13
16
|
end
|
@@ -1,21 +1,32 @@
|
|
1
1
|
module Admin
|
2
2
|
class OrdersController < ApplicationController
|
3
|
-
before_action
|
4
|
-
before_action { EffectiveResources.authorize!(self, :admin, :effective_orders) }
|
3
|
+
before_action :authenticate_user!
|
5
4
|
|
6
|
-
|
5
|
+
layout (EffectiveOrders.layout.kind_of?(Hash) ? EffectiveOrders.layout[:admin_orders] : EffectiveOrders.layout)
|
7
6
|
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
def new
|
8
|
+
@order = Effective::Order.new
|
9
|
+
|
10
|
+
if params[:user_id]
|
11
|
+
@order.user = User.where(id: params[:user_id]).first
|
12
|
+
end
|
13
|
+
|
14
|
+
if params[:duplicate_id]
|
15
|
+
@duplicate = Effective::Order.deep.find(params[:duplicate_id])
|
16
|
+
EffectiveOrders.authorize!(self, :show, @duplicate)
|
17
|
+
|
18
|
+
@order.add(@duplicate)
|
19
|
+
end
|
11
20
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
21
|
+
@page_title = 'New Order'
|
22
|
+
|
23
|
+
raise 'please install cocoon gem to use this page' unless defined?(Cocoon)
|
24
|
+
|
25
|
+
authorize_effective_order!
|
26
|
+
end
|
16
27
|
|
17
28
|
def create
|
18
|
-
@user =
|
29
|
+
@user = User.find_by_id(order_params[:user_id])
|
19
30
|
@order = Effective::Order.new(user: @user)
|
20
31
|
|
21
32
|
authorize_effective_order!
|
@@ -43,10 +54,46 @@ module Admin
|
|
43
54
|
end
|
44
55
|
|
45
56
|
@page_title = 'New Order'
|
46
|
-
flash.now[:danger] = flash_danger(@order)
|
57
|
+
flash.now[:danger] = flash_danger(@order)
|
47
58
|
render :new
|
48
59
|
end
|
49
60
|
|
61
|
+
def edit
|
62
|
+
@order = Effective::Order.find(params[:id])
|
63
|
+
@page_title ||= @order.to_s
|
64
|
+
|
65
|
+
authorize_effective_order!
|
66
|
+
end
|
67
|
+
|
68
|
+
def update
|
69
|
+
@order = Effective::Order.find(params[:id])
|
70
|
+
|
71
|
+
@page_title ||= @order.to_s
|
72
|
+
|
73
|
+
authorize_effective_order!
|
74
|
+
|
75
|
+
Effective::Order.transaction do
|
76
|
+
begin
|
77
|
+
@order.assign_attributes(order_params)
|
78
|
+
@order.save!
|
79
|
+
redirect_to(admin_redirect_path) and return
|
80
|
+
rescue => e
|
81
|
+
raise ActiveRecord::Rollback
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
flash.now[:danger] = "Unable to update order: #{@order.errors.full_messages.to_sentence}"
|
86
|
+
render :edit
|
87
|
+
end
|
88
|
+
|
89
|
+
def show
|
90
|
+
@order = Effective::Order.find(params[:id])
|
91
|
+
|
92
|
+
@page_title ||= @order.to_s
|
93
|
+
|
94
|
+
authorize_effective_order!
|
95
|
+
end
|
96
|
+
|
50
97
|
# The show page posts to this action
|
51
98
|
# See Effective::OrdersController checkout
|
52
99
|
def checkout
|
@@ -75,6 +122,14 @@ module Admin
|
|
75
122
|
render :checkout
|
76
123
|
end
|
77
124
|
|
125
|
+
def index
|
126
|
+
@datatable = Admin::EffectiveOrdersDatatable.new(self)
|
127
|
+
|
128
|
+
@page_title = 'Orders'
|
129
|
+
|
130
|
+
authorize_effective_order!
|
131
|
+
end
|
132
|
+
|
78
133
|
def destroy
|
79
134
|
@order = Effective::Order.all.not_purchased.find(params[:id])
|
80
135
|
|
@@ -124,12 +179,12 @@ module Admin
|
|
124
179
|
private
|
125
180
|
|
126
181
|
def order_params
|
127
|
-
params.require(:effective_order).permit(:user_id, :
|
182
|
+
params.require(:effective_order).permit(:user_id, :cc,
|
128
183
|
:send_payment_request_to_buyer, :note_internal, :note_to_buyer,
|
129
184
|
:payment_provider, :payment_card, :payment, :send_mark_as_paid_email_to_buyer,
|
130
185
|
order_items_attributes: [
|
131
186
|
:quantity, :_destroy, purchasable_attributes: [
|
132
|
-
:name, :
|
187
|
+
:name, :price, :tax_exempt
|
133
188
|
]
|
134
189
|
]
|
135
190
|
)
|
@@ -140,18 +195,27 @@ module Admin
|
|
140
195
|
end
|
141
196
|
|
142
197
|
def authorize_effective_order!
|
143
|
-
|
198
|
+
EffectiveOrders.authorize!(self, :admin, :effective_orders)
|
199
|
+
EffectiveOrders.authorize!(self, action_name.to_sym, @order || Effective::Order)
|
144
200
|
end
|
145
201
|
|
146
202
|
def admin_redirect_path
|
203
|
+
# Allow an app to define effective_orders_admin_redirect_path in their ApplicationController
|
204
|
+
path = if self.respond_to?(:effective_orders_admin_redirect_path)
|
205
|
+
effective_orders_admin_redirect_path(params[:commit], @order)
|
206
|
+
end
|
207
|
+
|
208
|
+
return path if path.present?
|
209
|
+
|
147
210
|
case params[:commit].to_s
|
148
211
|
when 'Save' ; effective_orders.admin_order_path(@order)
|
212
|
+
|
149
213
|
when 'Continue' ; effective_orders.admin_orders_path
|
150
214
|
when 'Add New' ; effective_orders.new_admin_order_path(user_id: @order.user.try(:to_param))
|
151
215
|
when 'Duplicate' ; effective_orders.new_admin_order_path(duplicate_id: @order.to_param)
|
152
216
|
when 'Checkout' ; effective_orders.checkout_admin_order_path(@order.to_param)
|
153
|
-
|
154
|
-
|
217
|
+
|
218
|
+
else effective_orders.admin_order_path(@order)
|
155
219
|
end
|
156
220
|
end
|
157
221
|
|
@@ -1,25 +1,21 @@
|
|
1
1
|
module Effective
|
2
2
|
class CartsController < ApplicationController
|
3
|
-
|
3
|
+
layout (EffectiveOrders.layout.kind_of?(Hash) ? EffectiveOrders.layout[:carts] : EffectiveOrders.layout)
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
if (config = EffectiveOrders.layout)
|
8
|
-
layout(config.kind_of?(Hash) ? (config[:carts] || config[:application]) : config)
|
9
|
-
end
|
5
|
+
before_action :authenticate_user!
|
10
6
|
|
11
7
|
def show
|
12
8
|
@cart = current_cart
|
13
9
|
@pending_orders = Effective::Order.not_purchased.where(user: current_user) if current_user.present?
|
14
10
|
|
15
11
|
@page_title ||= 'My Cart'
|
16
|
-
|
12
|
+
EffectiveOrders.authorize!(self, :show, @cart)
|
17
13
|
end
|
18
14
|
|
19
15
|
def destroy
|
20
16
|
@cart = current_cart
|
21
17
|
|
22
|
-
|
18
|
+
EffectiveOrders.authorize!(self, :destroy, @cart)
|
23
19
|
|
24
20
|
if @cart.destroy
|
25
21
|
flash[:success] = 'Successfully emptied cart.'
|
@@ -33,7 +29,7 @@ module Effective
|
|
33
29
|
def add_to_cart
|
34
30
|
@purchasable = (add_to_cart_params[:purchasable_type].constantize.find(add_to_cart_params[:purchasable_id].to_i) rescue nil)
|
35
31
|
|
36
|
-
|
32
|
+
EffectiveOrders.authorize!(self, :update, current_cart)
|
37
33
|
|
38
34
|
begin
|
39
35
|
raise "Please select a valid #{add_to_cart_params[:purchasable_type] || 'item' }." unless @purchasable
|
@@ -52,7 +48,7 @@ module Effective
|
|
52
48
|
def remove_from_cart
|
53
49
|
@cart_item = current_cart.cart_items.find(remove_from_cart_params[:id])
|
54
50
|
|
55
|
-
|
51
|
+
EffectiveOrders.authorize!(self, :update, current_cart)
|
56
52
|
|
57
53
|
if @cart_item.destroy
|
58
54
|
flash[:success] = 'Successfully removed item from cart.'
|
@@ -1,12 +1,10 @@
|
|
1
1
|
module Effective
|
2
2
|
class CustomersController < ApplicationController
|
3
|
-
|
3
|
+
layout (EffectiveOrders.layout.kind_of?(Hash) ? EffectiveOrders.layout[:customers] : EffectiveOrders.layout)
|
4
4
|
|
5
5
|
include Effective::CrudController
|
6
6
|
|
7
|
-
|
8
|
-
layout(config.kind_of?(Hash) ? (config[:customers] || config[:application]) : config)
|
9
|
-
end
|
7
|
+
before_action :authenticate_user!
|
10
8
|
|
11
9
|
submit :save, 'Save', success: -> { 'Successfully updated card.' }
|
12
10
|
page_title 'Customer Settings'
|
@@ -2,21 +2,17 @@ module Effective
|
|
2
2
|
class OrdersController < ApplicationController
|
3
3
|
include Concerns::Purchase
|
4
4
|
|
5
|
-
include Providers::Cheque
|
6
|
-
include Providers::Free
|
7
|
-
include Providers::MarkAsPaid
|
8
|
-
include Providers::Moneris
|
9
|
-
include Providers::Paypal
|
10
|
-
include Providers::Phone
|
11
|
-
include Providers::Pretend
|
12
|
-
include Providers::Refund
|
13
|
-
include Providers::Stripe
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
if (config = EffectiveOrders.layout)
|
18
|
-
layout(config.kind_of?(Hash) ? (config[:orders] || config[:application]) : config)
|
19
|
-
end
|
5
|
+
include Providers::Cheque if EffectiveOrders.cheque?
|
6
|
+
include Providers::Free if EffectiveOrders.free?
|
7
|
+
include Providers::MarkAsPaid if EffectiveOrders.mark_as_paid?
|
8
|
+
include Providers::Moneris if EffectiveOrders.moneris?
|
9
|
+
include Providers::Paypal if EffectiveOrders.paypal?
|
10
|
+
include Providers::Phone if EffectiveOrders.phone?
|
11
|
+
include Providers::Pretend if EffectiveOrders.pretend?
|
12
|
+
include Providers::Refund if EffectiveOrders.refund?
|
13
|
+
include Providers::Stripe if EffectiveOrders.stripe?
|
14
|
+
|
15
|
+
layout (EffectiveOrders.layout.kind_of?(Hash) ? EffectiveOrders.layout[:orders] : EffectiveOrders.layout)
|
20
16
|
|
21
17
|
before_action :authenticate_user!, except: [:ccbill_postback, :free, :paypal_postback, :moneris_postback, :pretend]
|
22
18
|
before_action :set_page_title, except: [:show]
|
@@ -30,7 +26,7 @@ module Effective
|
|
30
26
|
def new
|
31
27
|
@order ||= Effective::Order.new(view_context.current_cart)
|
32
28
|
|
33
|
-
|
29
|
+
EffectiveOrders.authorize!(self, :new, @order)
|
34
30
|
|
35
31
|
unless @order.valid?
|
36
32
|
flash[:danger] = "Unable to proceed: #{flash_errors(@order)}. Please try again."
|
@@ -42,7 +38,7 @@ module Effective
|
|
42
38
|
# Confirms an order from the cart.
|
43
39
|
def create
|
44
40
|
@order ||= Effective::Order.new(view_context.current_cart)
|
45
|
-
|
41
|
+
EffectiveOrders.authorize!(self, :create, @order)
|
46
42
|
|
47
43
|
@order.assign_attributes(checkout_params)
|
48
44
|
|
@@ -61,7 +57,7 @@ module Effective
|
|
61
57
|
# Might render step1 or step2
|
62
58
|
def show
|
63
59
|
@order = Effective::Order.find(params[:id])
|
64
|
-
|
60
|
+
EffectiveOrders.authorize!(self, :show, @order)
|
65
61
|
|
66
62
|
@page_title ||= ((@order.user == current_user && !@order.purchased?) ? 'Checkout' : @order.to_s)
|
67
63
|
end
|
@@ -69,13 +65,13 @@ module Effective
|
|
69
65
|
# Always step1
|
70
66
|
def edit
|
71
67
|
@order ||= Effective::Order.find(params[:id])
|
72
|
-
|
68
|
+
EffectiveOrders.authorize!(self, :edit, @order)
|
73
69
|
end
|
74
70
|
|
75
71
|
# Confirms the order from existing order
|
76
72
|
def update
|
77
73
|
@order ||= Effective::Order.find(params[:id])
|
78
|
-
|
74
|
+
EffectiveOrders.authorize!(self, :update, @order)
|
79
75
|
|
80
76
|
@order.assign_attributes(checkout_params)
|
81
77
|
|
@@ -90,28 +86,28 @@ module Effective
|
|
90
86
|
# My Orders History
|
91
87
|
def index
|
92
88
|
@datatable = EffectiveOrdersDatatable.new(user_id: current_user.id)
|
93
|
-
|
89
|
+
EffectiveOrders.authorize!(self, :index, Effective::Order.new(user: current_user))
|
94
90
|
end
|
95
91
|
|
96
92
|
# Thank you for Purchasing this Order. This is where a successfully purchased order ends up
|
97
93
|
def purchased # Thank You!
|
98
94
|
@order = Effective::Order.purchased.find(params[:id])
|
99
|
-
|
95
|
+
EffectiveOrders.authorize!(self, :show, @order)
|
100
96
|
end
|
101
97
|
|
102
98
|
def deferred
|
103
99
|
@order = Effective::Order.deferred.find(params[:id])
|
104
|
-
|
100
|
+
EffectiveOrders.authorize!(self, :show, @order)
|
105
101
|
end
|
106
102
|
|
107
103
|
def declined
|
108
104
|
@order = Effective::Order.declined.find(params[:id])
|
109
|
-
|
105
|
+
EffectiveOrders.authorize!(self, :show, @order)
|
110
106
|
end
|
111
107
|
|
112
108
|
def send_buyer_receipt
|
113
109
|
@order = Effective::Order.find(params[:id])
|
114
|
-
|
110
|
+
EffectiveOrders.authorize!(self, :show, @order)
|
115
111
|
|
116
112
|
if @order.send_order_receipt_to_buyer!
|
117
113
|
flash[:success] = "A receipt has been sent to #{@order.emails_send_to}"
|
@@ -132,10 +128,10 @@ module Effective
|
|
132
128
|
@orders = Effective::Order.purchased.where(id: params[:ids])
|
133
129
|
|
134
130
|
begin
|
135
|
-
|
131
|
+
EffectiveOrders.authorize!(self, :index, Effective::Order.new(user: current_user))
|
136
132
|
|
137
133
|
@orders.each do |order|
|
138
|
-
next unless
|
134
|
+
next unless EffectiveOrders.authorized?(self, :show, order)
|
139
135
|
order.send_order_receipt_to_buyer!
|
140
136
|
end
|
141
137
|
|