effective_orders 4.4.8 → 4.5.2
Sign up to get free protection for your applications and to get access to all the features.
- 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_purchasable.rb +9 -9
- data/app/models/concerns/acts_as_subscribable.rb +10 -5
- data/app/models/effective/customer.rb +7 -0
- data/app/models/effective/order.rb +23 -1
- data/app/models/effective/subscription.rb +4 -0
- data/app/views/effective/customers/_customer.html.haml +2 -2
- data/db/migrate/01_create_effective_orders.rb.erb +4 -0
- data/lib/effective_orders.rb +7 -4
- data/lib/effective_orders/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 36b254eb8e99a4c04b3b63135b2b1caa15f5a8d7803bcad0fff8323b0aab957a
|
4
|
+
data.tar.gz: 699ccd522afef972528e9dcee5b5eae8abad124cf11e0002f84e5c7a06bf0e8b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 784ec95030d906ab226f26d7f50651062979a3e50fdf286135fc81e3907d6bc23a93c77e1504433012ea59e49bcb4613702723b69a9fe58b858fd36a15ae1590
|
7
|
+
data.tar.gz: 7f1cf4534c235f84a025a040b2988fcfa8664046d7026de8665f4c14b139afdbd570a4491ffb46ade0d5ba40f80bd6403064f6de6aa5fa4e3ace5e1032331f83
|
@@ -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
|
|
@@ -5,15 +5,15 @@ module ActsAsPurchasable
|
|
5
5
|
def acts_as_purchasable(*options)
|
6
6
|
@acts_as_purchasable = options || []
|
7
7
|
|
8
|
-
if table_exists?
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
end
|
8
|
+
# if table_exists?
|
9
|
+
# instance = new()
|
10
|
+
# raise 'must respond_to price' unless instance.respond_to?(:price)
|
11
|
+
# raise 'must respond_to purchased_order_id' unless instance.respond_to?(:purchased_order_id)
|
12
|
+
|
13
|
+
# if defined?(EffectiveQbSync)
|
14
|
+
# raise 'must respond to qb_item_name' unless instance.respond_to?(:qb_item_name)
|
15
|
+
# end
|
16
|
+
# end
|
17
17
|
|
18
18
|
include ::ActsAsPurchasable
|
19
19
|
end
|
@@ -7,9 +7,11 @@ module ActsAsSubscribable
|
|
7
7
|
def acts_as_subscribable(*options)
|
8
8
|
@acts_as_subscribable = options || []
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
raise 'must respond to
|
10
|
+
# if table_exists?
|
11
|
+
# instance = new()
|
12
|
+
# raise 'must respond to trialing_until' unless instance.respond_to?(:trialing_until) || !EffectiveOrders.trial?
|
13
|
+
# raise 'must respond to subscription_status' unless instance.respond_to?(:subscription_status)
|
14
|
+
# end
|
13
15
|
|
14
16
|
include ::ActsAsSubscribable
|
15
17
|
(ActsAsSubscribable.descendants ||= []) << self
|
@@ -20,7 +22,7 @@ module ActsAsSubscribable
|
|
20
22
|
has_one :subscription, as: :subscribable, class_name: 'Effective::Subscription', inverse_of: :subscribable
|
21
23
|
has_one :customer, through: :subscription, class_name: 'Effective::Customer'
|
22
24
|
|
23
|
-
before_validation(if: -> {
|
25
|
+
before_validation(if: -> { EffectiveOrders.trial? && trialing_until.blank? }) do
|
24
26
|
self.trialing_until = (Time.zone.now + EffectiveOrders.trial.fetch(:length)).beginning_of_day
|
25
27
|
end
|
26
28
|
|
@@ -28,7 +30,10 @@ module ActsAsSubscribable
|
|
28
30
|
raise :abort unless (subscripter.destroy! rescue false)
|
29
31
|
end
|
30
32
|
|
31
|
-
|
33
|
+
if EffectiveOrders.trial?
|
34
|
+
validates :trialing_until, presence: true
|
35
|
+
end
|
36
|
+
|
32
37
|
validates :subscription_status, inclusion: { allow_nil: true, in: EffectiveOrders::STATUSES.keys }
|
33
38
|
|
34
39
|
scope :trialing, -> { where(subscription_status: nil).where('trialing_until > ?', Time.zone.now) }
|
@@ -51,6 +51,13 @@ module Effective
|
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
+
def invoices
|
55
|
+
@invoices ||= if stripe_customer_id.present?
|
56
|
+
Rails.logger.info "[STRIPE] list invoices: #{stripe_customer_id}"
|
57
|
+
::Stripe::Invoice.list(customer: stripe_customer_id) rescue nil
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
54
61
|
def upcoming_invoice
|
55
62
|
@upcoming_invoice ||= if stripe_customer_id.present?
|
56
63
|
Rails.logger.info "[STRIPE] get upcoming invoice: #{stripe_customer_id}"
|
@@ -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}"
|
@@ -337,13 +358,14 @@ module Effective
|
|
337
358
|
|
338
359
|
assign_attributes(
|
339
360
|
state: EffectiveOrders::PURCHASED,
|
340
|
-
purchased_at: Time.zone.now,
|
341
361
|
payment: payment_to_h(payment),
|
342
362
|
payment_provider: provider,
|
343
363
|
payment_card: (card.presence || 'none'),
|
344
364
|
skip_buyer_validations: skip_buyer_validations
|
345
365
|
)
|
346
366
|
|
367
|
+
self.purchased_at ||= Time.zone.now
|
368
|
+
|
347
369
|
Effective::Order.transaction do
|
348
370
|
begin
|
349
371
|
run_purchasable_callbacks(:before_purchase)
|
@@ -56,6 +56,10 @@ module Effective
|
|
56
56
|
|
57
57
|
validates :status, inclusion: { in: EffectiveOrders::STATUSES.keys }
|
58
58
|
|
59
|
+
before_validation do
|
60
|
+
self.name ||= EffectiveOrders.stripe_plans.find { |plan| plan[:id] == stripe_plan_id }&[:name] || 'Subscribed Plan'
|
61
|
+
end
|
62
|
+
|
59
63
|
def to_s
|
60
64
|
name || 'New Subscription'
|
61
65
|
end
|
@@ -15,7 +15,7 @@
|
|
15
15
|
%td= sub.quantity
|
16
16
|
%td= sub.interval
|
17
17
|
|
18
|
-
- if customer.
|
18
|
+
- if customer.invoices.present?
|
19
19
|
.card.my-4
|
20
20
|
.card-header Invoices
|
21
21
|
.card-body
|
@@ -26,7 +26,7 @@
|
|
26
26
|
%th Invoice
|
27
27
|
%th Total
|
28
28
|
%tbody
|
29
|
-
- customer.
|
29
|
+
- customer.invoices.each do |invoice|
|
30
30
|
- date_method = [(:date if invoice.respond_to?(:date)), (:period_start if invoice.respond_to?(:period_start)), :created].compact.first
|
31
31
|
%tr
|
32
32
|
%td= link_to Time.zone.at(invoice.public_send(date_method)).strftime('%F'), invoice.invoice_pdf
|
data/lib/effective_orders.rb
CHANGED
@@ -183,7 +183,7 @@ module EffectiveOrders
|
|
183
183
|
Rails.logger.info '[STRIPE] index plans'
|
184
184
|
|
185
185
|
plans = begin
|
186
|
-
Stripe::Plan.all
|
186
|
+
Stripe::Plan.respond_to?(:all) ? Stripe::Plan.all : Stripe::Plan.list
|
187
187
|
rescue => e
|
188
188
|
raise e if Rails.env.production?
|
189
189
|
Rails.logger.info "[STRIPE ERROR]: #{e.message}"
|
@@ -192,15 +192,18 @@ module EffectiveOrders
|
|
192
192
|
end
|
193
193
|
|
194
194
|
plans = plans.map do |plan|
|
195
|
+
description = ("$#{'%0.2f' % (plan.amount / 100.0)}" + ' ' + plan.currency.upcase + '/' + plan.interval.to_s)
|
196
|
+
|
195
197
|
{
|
196
198
|
id: plan.id,
|
197
199
|
product_id: plan.product,
|
198
|
-
name: plan.nickname,
|
200
|
+
name: plan.nickname || description,
|
201
|
+
description: description,
|
199
202
|
amount: plan.amount,
|
200
203
|
currency: plan.currency,
|
201
|
-
description: ("$#{'%0.2f' % (plan.amount / 100.0)}" + ' ' + plan.currency.upcase + '/' + plan.interval.to_s),
|
202
204
|
interval: plan.interval,
|
203
|
-
interval_count: plan.interval_count
|
205
|
+
interval_count: plan.interval_count,
|
206
|
+
trial_period_days: plan.trial_period_days
|
204
207
|
}
|
205
208
|
end.sort do |x, y|
|
206
209
|
val ||= (x[:interval] <=> y[:interval])
|
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
|
+
version: 4.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Code and Effect
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-07-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -253,7 +253,7 @@ homepage: https://github.com/code-and-effect/effective_orders
|
|
253
253
|
licenses:
|
254
254
|
- MIT
|
255
255
|
metadata: {}
|
256
|
-
post_install_message:
|
256
|
+
post_install_message:
|
257
257
|
rdoc_options: []
|
258
258
|
require_paths:
|
259
259
|
- lib
|
@@ -268,8 +268,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
268
268
|
- !ruby/object:Gem::Version
|
269
269
|
version: '0'
|
270
270
|
requirements: []
|
271
|
-
rubygems_version: 3.
|
272
|
-
signing_key:
|
271
|
+
rubygems_version: 3.1.2
|
272
|
+
signing_key:
|
273
273
|
specification_version: 4
|
274
274
|
summary: Quickly build an online store with carts, orders, automatic email receipts
|
275
275
|
and payment collection via Stripe, StripeConnect, PayPal and Moneris.
|