effective_orders 5.0.0 → 5.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -0
- data/app/assets/config/effective_orders_manifest.js +1 -0
- data/app/controllers/admin/orders_controller.rb +1 -1
- data/app/controllers/effective/concerns/purchase.rb +12 -19
- data/app/controllers/effective/orders_controller.rb +4 -5
- data/app/controllers/effective/providers/free.rb +0 -1
- data/app/controllers/effective/providers/mark_as_paid.rb +1 -2
- data/app/controllers/effective/providers/pretend.rb +1 -2
- data/app/controllers/effective/providers/refund.rb +1 -2
- data/app/controllers/effective/providers/stripe.rb +1 -2
- data/app/datatables/admin/effective_orders_datatable.rb +5 -8
- data/app/datatables/effective_orders_datatable.rb +3 -7
- data/app/helpers/effective_orders_helper.rb +1 -7
- data/app/models/effective/order.rb +24 -33
- data/app/models/effective/order_item.rb +10 -0
- data/app/models/effective/product.rb +2 -0
- data/app/views/effective/orders/_order_actions.html.haml +1 -1
- data/app/views/effective/orders/show.html.haml +4 -0
- data/lib/effective_orders/engine.rb +2 -2
- data/lib/effective_orders/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 195cc9c586145c7c43e3765a482e6f843926b9beb4043e437960602cec6dc87d
|
4
|
+
data.tar.gz: 5feb696f017b304b3ce0f4cb63eb529cbbcb61616822af3ce97b405caa68f149
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 559e82ca80af432a84c99fadfe16ebf413f7c39725ba652568828f88cd91a4e1853adf86e327feb06df9b7e6a9e2916be3b96519847b905fef7b09162415f4cb
|
7
|
+
data.tar.gz: 4bc2f1e00f75619f168c76d6d8b4a2716baee26dc6fe734bea1b7ff35faf781a4a33f908175e472f62032196a077baf1c5c84ab2f0366dbf1ca0012466936732
|
data/README.md
CHANGED
@@ -351,7 +351,10 @@ The permissions you actually want to define for a regular user are as follows (u
|
|
351
351
|
|
352
352
|
```ruby
|
353
353
|
can [:manage], Effective::Cart, user_id: user.id
|
354
|
+
|
354
355
|
can [:manage], Effective::Order, user_id: user.id # Orders cannot be deleted
|
356
|
+
cannot [:edit, :update], Effective::Order, state: 'purchased'
|
357
|
+
|
355
358
|
can [:manage], Effective::Subscription, user_id: user.id
|
356
359
|
```
|
357
360
|
|
@@ -0,0 +1 @@
|
|
1
|
+
//= link_directory ../images/effective_orders
|
@@ -5,28 +5,21 @@ module Effective
|
|
5
5
|
|
6
6
|
protected
|
7
7
|
|
8
|
-
def order_purchased(payment:, provider:, card: 'none', email: true, skip_buyer_validations: false, purchased_url: nil
|
9
|
-
|
10
|
-
@order.purchase!(payment: payment, provider: provider, card: card, email: email, skip_buyer_validations: skip_buyer_validations)
|
11
|
-
|
12
|
-
Effective::Cart.where(user: @order.user).destroy_all
|
13
|
-
|
14
|
-
if flash[:success].blank?
|
15
|
-
if EffectiveOrders.mailer[:send_order_receipt_to_buyer] && email
|
16
|
-
flash[:success] = "Payment successful! A receipt has been sent to #{@order.emails_send_to}"
|
17
|
-
else
|
18
|
-
flash[:success] = "Payment successful! An email receipt has not been sent."
|
19
|
-
end
|
20
|
-
end
|
8
|
+
def order_purchased(payment:, provider:, card: 'none', email: true, skip_buyer_validations: false, purchased_url: nil)
|
9
|
+
@order.purchase!(payment: payment, provider: provider, card: card, email: email, skip_buyer_validations: skip_buyer_validations)
|
21
10
|
|
22
|
-
|
23
|
-
redirect_to purchased_url.gsub(':id', @order.to_param.to_s)
|
24
|
-
rescue => e
|
25
|
-
flash[:danger] = "An error occurred while processing your payment: #{e.message}. Please try again."
|
11
|
+
Effective::Cart.where(user: @order.user).destroy_all
|
26
12
|
|
27
|
-
|
28
|
-
|
13
|
+
if flash[:success].blank?
|
14
|
+
if email && EffectiveOrders.mailer[:send_order_receipt_to_buyer]
|
15
|
+
flash[:success] = "Payment successful! A receipt has been sent to #{@order.emails_send_to}"
|
16
|
+
else
|
17
|
+
flash[:success] = "Payment successful! An email receipt has not been sent."
|
18
|
+
end
|
29
19
|
end
|
20
|
+
|
21
|
+
purchased_url ||= effective_orders.purchased_order_path(':id')
|
22
|
+
redirect_to purchased_url.gsub(':id', @order.to_param.to_s)
|
30
23
|
end
|
31
24
|
|
32
25
|
def order_deferred(provider:, email: true, deferred_url: nil)
|
@@ -1,5 +1,6 @@
|
|
1
1
|
module Effective
|
2
2
|
class OrdersController < ApplicationController
|
3
|
+
include Effective::CrudController
|
3
4
|
include Concerns::Purchase
|
4
5
|
|
5
6
|
include Providers::Cheque
|
@@ -12,8 +13,6 @@ module Effective
|
|
12
13
|
include Providers::Refund
|
13
14
|
include Providers::Stripe
|
14
15
|
|
15
|
-
include Effective::CrudController
|
16
|
-
|
17
16
|
if (config = EffectiveOrders.layout)
|
18
17
|
layout(config.kind_of?(Hash) ? (config[:orders] || config[:application]) : config)
|
19
18
|
end
|
@@ -68,13 +67,13 @@ module Effective
|
|
68
67
|
|
69
68
|
# Always step1
|
70
69
|
def edit
|
71
|
-
@order ||= Effective::Order.find(params[:id])
|
70
|
+
@order ||= Effective::Order.not_purchased.find(params[:id])
|
72
71
|
EffectiveResources.authorize!(self, :edit, @order)
|
73
72
|
end
|
74
73
|
|
75
74
|
# Confirms the order from existing order
|
76
75
|
def update
|
77
|
-
@order ||= Effective::Order.find(params[:id])
|
76
|
+
@order ||= Effective::Order.not_purchased.find(params[:id])
|
78
77
|
EffectiveResources.authorize!(self, :update, @order)
|
79
78
|
|
80
79
|
@order.assign_attributes(checkout_params)
|
@@ -110,7 +109,7 @@ module Effective
|
|
110
109
|
end
|
111
110
|
|
112
111
|
def send_buyer_receipt
|
113
|
-
@order = Effective::Order.find(params[:id])
|
112
|
+
@order = Effective::Order.purchased.find(params[:id])
|
114
113
|
EffectiveResources.authorize!(self, :show, @order)
|
115
114
|
|
116
115
|
if @order.send_order_receipt_to_buyer!
|
@@ -19,8 +19,7 @@ module Effective
|
|
19
19
|
card: mark_as_paid_params[:payment_card],
|
20
20
|
email: @order.send_mark_as_paid_email_to_buyer?,
|
21
21
|
skip_buyer_validations: true,
|
22
|
-
purchased_url: effective_orders.admin_order_path(@order)
|
23
|
-
declined_url: effective_orders.admin_order_path(@order)
|
22
|
+
purchased_url: effective_orders.admin_order_path(@order)
|
24
23
|
)
|
25
24
|
end
|
26
25
|
|
@@ -21,8 +21,7 @@ module Effective
|
|
21
21
|
order_purchased(
|
22
22
|
payment: 'refund. no payment required.',
|
23
23
|
provider: 'refund',
|
24
|
-
purchased_url: refund_params[:purchased_url]
|
25
|
-
declined_url: refund_params[:declined_url]
|
24
|
+
purchased_url: refund_params[:purchased_url]
|
26
25
|
)
|
27
26
|
end
|
28
27
|
|
@@ -14,12 +14,12 @@ class Admin::EffectiveOrdersDatatable < Effective::Datatable
|
|
14
14
|
end
|
15
15
|
|
16
16
|
filters do
|
17
|
-
|
18
|
-
scope :
|
17
|
+
unless attributes[:skip_filters]
|
18
|
+
scope :all
|
19
|
+
scope :purchased
|
19
20
|
scope :deferred
|
20
21
|
scope :refunds
|
21
22
|
scope :not_purchased
|
22
|
-
scope :all
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
@@ -84,13 +84,14 @@ class Admin::EffectiveOrdersDatatable < Effective::Datatable
|
|
84
84
|
end
|
85
85
|
|
86
86
|
collection do
|
87
|
-
scope = Effective::Order.all.
|
87
|
+
scope = Effective::Order.all.deep
|
88
88
|
|
89
89
|
if EffectiveOrders.orders_collection_scope.respond_to?(:call)
|
90
90
|
scope = EffectiveOrders.orders_collection_scope.call(scope)
|
91
91
|
end
|
92
92
|
|
93
93
|
if attributes[:user_id].present?
|
94
|
+
user = current_user.class.find(attributes[:user_id])
|
94
95
|
scope = scope.where(user: user)
|
95
96
|
end
|
96
97
|
|
@@ -101,8 +102,4 @@ class Admin::EffectiveOrdersDatatable < Effective::Datatable
|
|
101
102
|
scope
|
102
103
|
end
|
103
104
|
|
104
|
-
def user
|
105
|
-
@user ||= current_user.class.find(attributes[:user_id])
|
106
|
-
end
|
107
|
-
|
108
105
|
end
|
@@ -6,8 +6,6 @@ class EffectiveOrdersDatatable < Effective::Datatable
|
|
6
6
|
scope :purchased, default: true
|
7
7
|
scope :deferred
|
8
8
|
scope :refunds
|
9
|
-
scope :not_purchased
|
10
|
-
scope :all
|
11
9
|
end
|
12
10
|
end
|
13
11
|
|
@@ -61,7 +59,9 @@ class EffectiveOrdersDatatable < Effective::Datatable
|
|
61
59
|
end
|
62
60
|
|
63
61
|
collection do
|
64
|
-
|
62
|
+
user = current_user.class.find(attributes[:user_id])
|
63
|
+
|
64
|
+
scope = Effective::Order.all.deep.where(user: user)
|
65
65
|
|
66
66
|
if EffectiveOrders.orders_collection_scope.respond_to?(:call)
|
67
67
|
scope = EffectiveOrders.orders_collection_scope.call(scope)
|
@@ -78,8 +78,4 @@ class EffectiveOrdersDatatable < Effective::Datatable
|
|
78
78
|
scope
|
79
79
|
end
|
80
80
|
|
81
|
-
def user
|
82
|
-
@user ||= current_user.class.find(attributes[:user_id])
|
83
|
-
end
|
84
|
-
|
85
81
|
end
|
@@ -107,13 +107,7 @@ module EffectiveOrdersHelper
|
|
107
107
|
end
|
108
108
|
end
|
109
109
|
|
110
|
-
def render_orders(
|
111
|
-
orders = Array(obj.kind_of?(User) ? Effective::Order.purchased_by(obj) : obj)
|
112
|
-
|
113
|
-
if orders.any? { |order| order.kind_of?(Effective::Order) == false }
|
114
|
-
raise 'expected a User or Effective::Order'
|
115
|
-
end
|
116
|
-
|
110
|
+
def render_orders(orders, opts = {})
|
117
111
|
render(partial: 'effective/orders/orders_table', locals: { orders: orders }.merge(opts))
|
118
112
|
end
|
119
113
|
|
@@ -34,10 +34,6 @@ module Effective
|
|
34
34
|
belongs_to :user, polymorphic: true, validate: false # This is the buyer/user of the order. We validate it below.
|
35
35
|
has_many :order_items, -> { order(:id) }, inverse_of: :order, dependent: :delete_all
|
36
36
|
|
37
|
-
if defined?(EffectiveQbSync)
|
38
|
-
has_one :qb_order_item
|
39
|
-
end
|
40
|
-
|
41
37
|
accepts_nested_attributes_for :order_items, allow_destroy: false, reject_if: :all_blank
|
42
38
|
accepts_nested_attributes_for :user, allow_destroy: false, update_only: true
|
43
39
|
|
@@ -78,6 +74,10 @@ module Effective
|
|
78
74
|
self.state = EffectiveOrders::CONFIRMED if pending?
|
79
75
|
end
|
80
76
|
|
77
|
+
before_save(if: -> { state_was == EffectiveOrders::PURCHASED }) do
|
78
|
+
raise EffectiveOrders::AlreadyPurchasedException.new('cannot unpurchase an order') unless purchased?
|
79
|
+
end
|
80
|
+
|
81
81
|
# Order validations
|
82
82
|
validates :user_id, presence: true
|
83
83
|
validates :email, presence: true, email: true # email and cc validators are from effective_resources
|
@@ -137,7 +137,7 @@ module Effective
|
|
137
137
|
validates :payment_provider, presence: true, inclusion: { in: EffectiveOrders.deferred_providers }
|
138
138
|
end
|
139
139
|
|
140
|
-
scope :deep, -> { includes(:user, order_items: :purchasable) }
|
140
|
+
scope :deep, -> { includes(:addresses, :user, order_items: :purchasable) }
|
141
141
|
scope :sorted, -> { order(:id) }
|
142
142
|
|
143
143
|
scope :purchased, -> { where(state: EffectiveOrders::PURCHASED) }
|
@@ -261,12 +261,6 @@ module Effective
|
|
261
261
|
end
|
262
262
|
end
|
263
263
|
|
264
|
-
# first or build
|
265
|
-
def qb_item_name
|
266
|
-
raise('expected EffectiveQbSync gem') unless defined?(EffectiveQbSync)
|
267
|
-
(qb_order_item || build_qb_order_item(name: purchasable.qb_item_name)).name
|
268
|
-
end
|
269
|
-
|
270
264
|
def pending?
|
271
265
|
state == EffectiveOrders::PENDING
|
272
266
|
end
|
@@ -338,6 +332,8 @@ module Effective
|
|
338
332
|
# It skips any address or bad user validations
|
339
333
|
# It's basically the same as save! on a new order, except it might send the payment request to buyer
|
340
334
|
def pending!
|
335
|
+
return false if purchased?
|
336
|
+
|
341
337
|
self.state = EffectiveOrders::PENDING
|
342
338
|
self.addresses.clear if addresses.any? { |address| address.valid? == false }
|
343
339
|
save!
|
@@ -348,6 +344,7 @@ module Effective
|
|
348
344
|
|
349
345
|
# Used by admin checkout only
|
350
346
|
def confirm!
|
347
|
+
return false if purchased?
|
351
348
|
update!(state: EffectiveOrders::CONFIRMED)
|
352
349
|
end
|
353
350
|
|
@@ -365,38 +362,31 @@ module Effective
|
|
365
362
|
|
366
363
|
# Effective::Order.new(items: Product.first, user: User.first).purchase!(email: false)
|
367
364
|
def purchase!(payment: 'none', provider: 'none', card: 'none', email: true, skip_buyer_validations: false)
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
assign_attributes(
|
372
|
-
state: EffectiveOrders::PURCHASED,
|
373
|
-
payment: payment_to_h(payment),
|
374
|
-
payment_provider: provider,
|
375
|
-
payment_card: (card.presence || 'none'),
|
376
|
-
skip_buyer_validations: skip_buyer_validations
|
377
|
-
)
|
365
|
+
# Assign attributes
|
366
|
+
self.state = EffectiveOrders::PURCHASED
|
367
|
+
self.skip_buyer_validations = skip_buyer_validations
|
378
368
|
|
369
|
+
self.payment_provider ||= provider
|
370
|
+
self.payment_card ||= (card.presence || 'none')
|
379
371
|
self.purchased_at ||= Time.zone.now
|
372
|
+
self.payment = payment_to_h(payment) if self.payment.blank?
|
380
373
|
|
381
|
-
|
382
|
-
|
374
|
+
begin
|
375
|
+
Effective::Order.transaction do
|
383
376
|
run_purchasable_callbacks(:before_purchase)
|
384
377
|
save!
|
385
378
|
update_purchasables_purchased_order!
|
386
|
-
rescue => e
|
387
|
-
self.state = state_was
|
388
|
-
self.purchased_at = nil
|
389
|
-
|
390
|
-
error = e.message
|
391
|
-
raise ::ActiveRecord::Rollback
|
392
379
|
end
|
393
|
-
|
380
|
+
rescue => e
|
381
|
+
Effective::Order.transaction do
|
382
|
+
save!(validate: false)
|
383
|
+
update_purchasables_purchased_order!
|
384
|
+
end
|
394
385
|
|
395
|
-
|
386
|
+
raise(e)
|
387
|
+
end
|
396
388
|
|
397
389
|
run_purchasable_callbacks(:after_purchase)
|
398
|
-
|
399
|
-
send_refund_notification! if email && refund?
|
400
390
|
send_order_receipts! if email
|
401
391
|
|
402
392
|
true
|
@@ -459,6 +449,7 @@ module Effective
|
|
459
449
|
def send_order_receipts!
|
460
450
|
send_order_receipt_to_admin! if EffectiveOrders.mailer[:send_order_receipt_to_admin]
|
461
451
|
send_order_receipt_to_buyer! if EffectiveOrders.mailer[:send_order_receipt_to_buyer]
|
452
|
+
send_refund_notification! if refund?
|
462
453
|
end
|
463
454
|
|
464
455
|
def send_order_receipt_to_admin!
|
@@ -5,6 +5,10 @@ module Effective
|
|
5
5
|
belongs_to :order
|
6
6
|
belongs_to :purchasable, polymorphic: true
|
7
7
|
|
8
|
+
if defined?(EffectiveQbSync)
|
9
|
+
has_one :qb_order_item
|
10
|
+
end
|
11
|
+
|
8
12
|
effective_resource do
|
9
13
|
name :string
|
10
14
|
quantity :integer
|
@@ -61,5 +65,11 @@ module Effective
|
|
61
65
|
end
|
62
66
|
end
|
63
67
|
|
68
|
+
# first or build
|
69
|
+
def qb_item_name
|
70
|
+
raise('expected EffectiveQbSync gem') unless defined?(EffectiveQbSync)
|
71
|
+
(qb_order_item || build_qb_order_item(name: purchasable.qb_item_name)).name
|
72
|
+
end
|
73
|
+
|
64
74
|
end
|
65
75
|
end
|
@@ -3,7 +3,7 @@
|
|
3
3
|
= link_to 'Print', '#', class: 'btn btn-primary print-button', data: { role: 'print-button' }, onClick: 'window.print(); false;'
|
4
4
|
|
5
5
|
- if order.purchased?
|
6
|
-
= link_to '
|
6
|
+
= link_to 'E-mail Receipt', effective_orders.send_buyer_receipt_order_path(order),
|
7
7
|
class: 'btn btn-secondary',
|
8
8
|
data: { confirm: "Send receipt to #{order.emails_send_to}?" }
|
9
9
|
|
@@ -16,8 +16,8 @@ module EffectiveOrders
|
|
16
16
|
eval File.read("#{config.root}/config/effective_orders.rb")
|
17
17
|
end
|
18
18
|
|
19
|
-
initializer
|
20
|
-
|
19
|
+
initializer 'effective_orders.assets' do |app|
|
20
|
+
app.config.assets.precompile += ['effective_orders_manifest.js', 'effective_orders/*']
|
21
21
|
end
|
22
22
|
|
23
23
|
initializer 'effective_orders.refund', after: :load_config_initializers do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: effective_orders
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.0.
|
4
|
+
version: 5.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Code and Effect
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-03-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -118,6 +118,7 @@ extra_rdoc_files: []
|
|
118
118
|
files:
|
119
119
|
- MIT-LICENSE
|
120
120
|
- README.md
|
121
|
+
- app/assets/config/effective_orders_manifest.js
|
121
122
|
- app/assets/images/effective_orders/stripe.png
|
122
123
|
- app/assets/javascripts/effective_orders.js
|
123
124
|
- app/assets/javascripts/effective_orders/customers.js.coffee
|