effective_orders 4.4.10 → 4.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/datatables/admin/effective_orders_datatable.rb +13 -5
- data/app/datatables/effective_orders_datatable.rb +6 -0
- data/app/helpers/effective_orders_helper.rb +4 -4
- data/app/models/concerns/acts_as_subscribable.rb +6 -0
- data/app/models/effective/order.rb +27 -2
- data/app/models/effective/subscripter.rb +7 -1
- data/app/models/effective/subscription.rb +4 -0
- data/db/migrate/01_create_effective_orders.rb.erb +4 -0
- data/lib/effective_orders.rb +2 -1
- data/lib/effective_orders/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0144e9b8480285f5329cdb80f310ae893afc715ef1515a9d466d19075e5f0795
|
4
|
+
data.tar.gz: c4f7848248c853fc25f8123113cb863087ed92b0cfc01b78f85892ea09bb24ea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 06ed32afc06143accff761edb35b4018196558a9f3a76e6817be18e772f746acc84ec7ddc202f13713fc66316c64040518748116b2c68011d5d2358e5ad6be74
|
7
|
+
data.tar.gz: 11ffb123b02a984def655fae15a9c35a3f7f6266f7245faea219169090839683b7c17509295c99450443faa0cbb66ceb1b01a742008cab9b7e641ccb01990579
|
@@ -14,11 +14,13 @@ class Admin::EffectiveOrdersDatatable < Effective::Datatable
|
|
14
14
|
end
|
15
15
|
|
16
16
|
filters do
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
17
|
+
if attributes[:user_id].blank? && attributes[:parent_id].blank?
|
18
|
+
scope :purchased, default: true
|
19
|
+
scope :deferred
|
20
|
+
scope :refunds
|
21
|
+
scope :not_purchased
|
22
|
+
scope :all
|
23
|
+
end
|
22
24
|
end
|
23
25
|
|
24
26
|
datatable do
|
@@ -43,6 +45,8 @@ class Admin::EffectiveOrdersDatatable < Effective::Datatable
|
|
43
45
|
col :email, visible: false
|
44
46
|
end
|
45
47
|
|
48
|
+
col :parent, visible: false, search: :string
|
49
|
+
|
46
50
|
col :cc, visible: false
|
47
51
|
|
48
52
|
if EffectiveOrders.billing_address
|
@@ -90,6 +94,10 @@ class Admin::EffectiveOrdersDatatable < Effective::Datatable
|
|
90
94
|
scope = scope.where(user: user)
|
91
95
|
end
|
92
96
|
|
97
|
+
if attributes[:parent_id].present? && attributes[:parent_type].present?
|
98
|
+
scope = scope.where(parent_id: attributes[:parent_id], parent_type: attributes[:parent_type])
|
99
|
+
end
|
100
|
+
|
93
101
|
scope
|
94
102
|
end
|
95
103
|
|
@@ -21,6 +21,8 @@ class EffectiveOrdersDatatable < Effective::Datatable
|
|
21
21
|
'#' + order.to_param
|
22
22
|
end
|
23
23
|
|
24
|
+
col :parent, visible: false, search: :string
|
25
|
+
|
24
26
|
unless attributes[:not_purchased]
|
25
27
|
col :purchased_at do |order|
|
26
28
|
order.purchased_at&.strftime('%F %H:%M') || 'not purchased'
|
@@ -69,6 +71,10 @@ class EffectiveOrdersDatatable < Effective::Datatable
|
|
69
71
|
scope = scope.not_purchased
|
70
72
|
end
|
71
73
|
|
74
|
+
if attributes[:parent_id].present? && attributes[:parent_type].present?
|
75
|
+
scope = scope.where(parent_id: attributes[:parent_id], parent_type: attributes[:parent_type])
|
76
|
+
end
|
77
|
+
|
72
78
|
scope
|
73
79
|
end
|
74
80
|
|
@@ -86,13 +86,13 @@ module EffectiveOrdersHelper
|
|
86
86
|
end
|
87
87
|
end
|
88
88
|
|
89
|
-
def render_checkout_step1(order, namespace: nil, purchased_url: nil, declined_url: nil)
|
90
|
-
locals = { order: order, purchased_url: purchased_url, declined_url: declined_url, namespace: namespace }
|
89
|
+
def render_checkout_step1(order, namespace: nil, purchased_url: nil, declined_url: nil, deferred_url: nil)
|
90
|
+
locals = { order: order, purchased_url: purchased_url, declined_url: declined_url, deferred_url: deferred_url, namespace: namespace }
|
91
91
|
render(partial: 'effective/orders/checkout_step1', locals: locals)
|
92
92
|
end
|
93
93
|
|
94
|
-
def render_checkout_step2(order, namespace: nil, purchased_url: nil, declined_url: nil)
|
95
|
-
locals = { order: order, purchased_url: purchased_url, declined_url: declined_url, namespace: namespace }
|
94
|
+
def render_checkout_step2(order, namespace: nil, purchased_url: nil, declined_url: nil, deferred_url: nil)
|
95
|
+
locals = { order: order, purchased_url: purchased_url, declined_url: declined_url, deferred_url: deferred_url, namespace: namespace }
|
96
96
|
render(partial: 'effective/orders/checkout_step2', locals: locals)
|
97
97
|
end
|
98
98
|
|
@@ -67,6 +67,12 @@ module ActsAsSubscribable
|
|
67
67
|
subscribed? && subscription_status == EffectiveOrders::PAST_DUE
|
68
68
|
end
|
69
69
|
|
70
|
+
# If we do use stripe
|
71
|
+
def subscription_trialing?
|
72
|
+
subscribed? && subscription_status == EffectiveOrders::TRIALING
|
73
|
+
end
|
74
|
+
|
75
|
+
# If we don't use stripe
|
70
76
|
def trialing?
|
71
77
|
subscription_status.blank?
|
72
78
|
end
|
@@ -28,6 +28,9 @@ module Effective
|
|
28
28
|
attr_accessor :send_mark_as_paid_email_to_buyer # Set by Admin::Orders#mark_as_paid
|
29
29
|
attr_accessor :skip_buyer_validations # Set by Admin::Orders#create
|
30
30
|
|
31
|
+
# If we want to use orders in a has_many way
|
32
|
+
belongs_to :parent, polymorphic: true, optional: true
|
33
|
+
|
31
34
|
belongs_to :user, validate: false # This is the buyer/user of the order. We validate it below.
|
32
35
|
has_many :order_items, -> { order(:id) }, inverse_of: :order, class_name: 'Effective::OrderItem', dependent: :delete_all
|
33
36
|
|
@@ -222,6 +225,24 @@ module Effective
|
|
222
225
|
retval.size == 1 ? retval.first : retval
|
223
226
|
end
|
224
227
|
|
228
|
+
|
229
|
+
def update_prices!
|
230
|
+
raise('already purchased') if purchased?
|
231
|
+
raise('must be pending') unless pending?
|
232
|
+
|
233
|
+
order_items.each do |item|
|
234
|
+
purchasable = item.purchasable
|
235
|
+
|
236
|
+
if purchasable.blank? || purchasable.marked_for_destruction?
|
237
|
+
item.mark_for_destruction
|
238
|
+
else
|
239
|
+
item.price = purchasable.price
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
save!
|
244
|
+
end
|
245
|
+
|
225
246
|
def to_s
|
226
247
|
if refund?
|
227
248
|
"Refund ##{to_param}"
|
@@ -466,13 +487,17 @@ module Effective
|
|
466
487
|
|
467
488
|
def get_tax
|
468
489
|
return nil unless tax_rate.present?
|
469
|
-
|
490
|
+
present_order_items.reject { |oi| oi.tax_exempt? }.map { |oi| (oi.subtotal * (tax_rate / 100.0)).round(0).to_i }.sum
|
470
491
|
end
|
471
492
|
|
472
493
|
private
|
473
494
|
|
495
|
+
def present_order_items
|
496
|
+
order_items.reject { |oi| oi.marked_for_destruction? }
|
497
|
+
end
|
498
|
+
|
474
499
|
def assign_order_totals
|
475
|
-
self.subtotal =
|
500
|
+
self.subtotal = present_order_items.map { |oi| oi.subtotal }.sum
|
476
501
|
self.tax_rate = get_tax_rate() unless (tax_rate || 0) > 0
|
477
502
|
self.tax = get_tax()
|
478
503
|
self.total = subtotal + (tax || 0)
|
@@ -126,7 +126,13 @@ module Effective
|
|
126
126
|
return false unless subscription.stripe_subscription.blank?
|
127
127
|
|
128
128
|
Rails.logger.info "[STRIPE] create subscription: #{items}"
|
129
|
-
|
129
|
+
|
130
|
+
stripe_subscription = Stripe::Subscription.create(
|
131
|
+
customer: customer.stripe_customer_id,
|
132
|
+
items: items,
|
133
|
+
metadata: metadata,
|
134
|
+
trial_from_plan: true
|
135
|
+
)
|
130
136
|
|
131
137
|
subscription.update!(
|
132
138
|
stripe_subscription: stripe_subscription,
|
data/lib/effective_orders.rb
CHANGED
@@ -14,9 +14,10 @@ module EffectiveOrders
|
|
14
14
|
# Subscription statuses (as per stripe)
|
15
15
|
ACTIVE = 'active'.freeze
|
16
16
|
PAST_DUE = 'past_due'.freeze
|
17
|
+
TRIALING = 'trialing'.freeze
|
17
18
|
CANCELED = 'canceled'.freeze
|
18
19
|
|
19
|
-
STATUSES = { ACTIVE => ACTIVE, PAST_DUE => PAST_DUE, CANCELED => CANCELED }
|
20
|
+
STATUSES = { ACTIVE => ACTIVE, PAST_DUE => PAST_DUE, CANCELED => CANCELED, TRIALING => TRIALING }
|
20
21
|
|
21
22
|
# The following are all valid config keys
|
22
23
|
mattr_accessor :orders_table_name
|
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: 4.4
|
4
|
+
version: 4.5.4
|
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: 2020-
|
11
|
+
date: 2020-08-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|