effective_orders 4.4.9 → 4.5.3
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 +16 -5
- data/app/models/effective/customer.rb +7 -0
- data/app/models/effective/order.rb +21 -0
- data/app/models/effective/subscripter.rb +7 -1
- data/app/models/effective/subscription.rb +8 -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 +9 -5
- 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: d2216991c7430e4902a33b35ee0d8d4ea9e637c927a587b1dbedf1eaf4cf57fe
|
4
|
+
data.tar.gz: a51f8b35bfebb1e375664ee006e24717cec9ddac464f17e008296a87e2883c81
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7b5a07d109578b5bc7654ca5eaa6ec3f18b7cd89841b15e7f0a5a1128089e9715cd9b317c884ef0afb6cb4a9fed7f0934b7693f7e0b3ba4648544769a00ef3be
|
7
|
+
data.tar.gz: e94f3d309875b26bbf6f185990e80e1d1911ae0d320050550915dd7970f025a07645c402aa1b6422e114f1e1563b1d86420cba3a8d8058123ce437650c900269
|
@@ -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) }
|
@@ -62,6 +67,12 @@ module ActsAsSubscribable
|
|
62
67
|
subscribed? && subscription_status == EffectiveOrders::PAST_DUE
|
63
68
|
end
|
64
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
|
65
76
|
def trialing?
|
66
77
|
subscription_status.blank?
|
67
78
|
end
|
@@ -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}"
|
@@ -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,
|
@@ -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
|
@@ -75,6 +79,10 @@ module Effective
|
|
75
79
|
name.to_s <=> other&.name.to_s
|
76
80
|
end
|
77
81
|
|
82
|
+
def trialing?
|
83
|
+
status == 'trialing'
|
84
|
+
end
|
85
|
+
|
78
86
|
def active?
|
79
87
|
status == 'active'
|
80
88
|
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
@@ -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
|
@@ -183,7 +184,7 @@ module EffectiveOrders
|
|
183
184
|
Rails.logger.info '[STRIPE] index plans'
|
184
185
|
|
185
186
|
plans = begin
|
186
|
-
Stripe::Plan.all
|
187
|
+
Stripe::Plan.respond_to?(:all) ? Stripe::Plan.all : Stripe::Plan.list
|
187
188
|
rescue => e
|
188
189
|
raise e if Rails.env.production?
|
189
190
|
Rails.logger.info "[STRIPE ERROR]: #{e.message}"
|
@@ -192,15 +193,18 @@ module EffectiveOrders
|
|
192
193
|
end
|
193
194
|
|
194
195
|
plans = plans.map do |plan|
|
196
|
+
description = ("$#{'%0.2f' % (plan.amount / 100.0)}" + ' ' + plan.currency.upcase + '/' + plan.interval.to_s)
|
197
|
+
|
195
198
|
{
|
196
199
|
id: plan.id,
|
197
200
|
product_id: plan.product,
|
198
|
-
name: plan.nickname,
|
201
|
+
name: plan.nickname || description,
|
202
|
+
description: description,
|
199
203
|
amount: plan.amount,
|
200
204
|
currency: plan.currency,
|
201
|
-
description: ("$#{'%0.2f' % (plan.amount / 100.0)}" + ' ' + plan.currency.upcase + '/' + plan.interval.to_s),
|
202
205
|
interval: plan.interval,
|
203
|
-
interval_count: plan.interval_count
|
206
|
+
interval_count: plan.interval_count,
|
207
|
+
trial_period_days: plan.trial_period_days
|
204
208
|
}
|
205
209
|
end.sort do |x, y|
|
206
210
|
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.3
|
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-08-06 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.
|