effective_orders 4.5.1 → 4.5.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/javascripts/effective_orders/providers/stripe.js.coffee +2 -1
- data/app/controllers/effective/carts_controller.rb +2 -0
- data/app/controllers/effective/customers_controller.rb +2 -0
- data/app/datatables/admin/effective_orders_datatable.rb +13 -5
- data/app/datatables/effective_orders_datatable.rb +6 -0
- data/app/models/concerns/acts_as_subscribable.rb +6 -0
- data/app/models/effective/order.rb +24 -2
- data/app/models/effective/subscripter.rb +7 -1
- data/app/models/effective/subscription.rb +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: 108bf2867a6343e481d8e492c4e86fe7e3b1548594441c0b87a95b4a8181047a
|
4
|
+
data.tar.gz: 9d7b4cb4ca78ed441b178e613eb610ec2270a52e56d970683a74fab2b0b21aa2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 581d284694814a347ec8b5f9839e17778927dce8a9be9cbf310ef350fa8cd4f3551ea6190de14720c17be63a0e99a928717bbc64b31bdf58331938729e76a56f
|
7
|
+
data.tar.gz: 1a8d09ecfc10fde8c7ff8524d2b34b30d01348c33d1d06999852638bbb806de98bacbb9aa510fc065b642e2597bfbc08e42fa8bfd3eedeb3328d29f86285b507
|
@@ -8,7 +8,7 @@ this.StripeForm ||= class StripeForm
|
|
8
8
|
@card = null
|
9
9
|
|
10
10
|
initialize: ->
|
11
|
-
@form = $('form[data-stripe-form]').first()
|
11
|
+
@form = $('form[data-stripe-form]:not(.initialized)').first()
|
12
12
|
return false unless @form.length > 0
|
13
13
|
|
14
14
|
@paymentIntent = @form.find("input[name$='[payment_intent_id]']").first()
|
@@ -17,6 +17,7 @@ this.StripeForm ||= class StripeForm
|
|
17
17
|
@card = @stripe.elements().create('card', @style())
|
18
18
|
|
19
19
|
@mount()
|
20
|
+
@form.addClass('initialized')
|
20
21
|
|
21
22
|
style: ->
|
22
23
|
style: {
|
@@ -2,6 +2,8 @@ module Effective
|
|
2
2
|
class CartsController < ApplicationController
|
3
3
|
layout (EffectiveOrders.layout.kind_of?(Hash) ? EffectiveOrders.layout[:carts] : EffectiveOrders.layout)
|
4
4
|
|
5
|
+
before_action :authenticate_user!
|
6
|
+
|
5
7
|
def show
|
6
8
|
@cart = current_cart
|
7
9
|
@pending_orders = Effective::Order.pending.where(user: current_user) if current_user.present?
|
@@ -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
|
|
@@ -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
|
@@ -225,6 +225,24 @@ module Effective
|
|
225
225
|
retval.size == 1 ? retval.first : retval
|
226
226
|
end
|
227
227
|
|
228
|
+
|
229
|
+
def update_prices!
|
230
|
+
raise('already purchased') if purchased?
|
231
|
+
raise('must be pending or confirmed') unless pending? || confirmed?
|
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
|
+
|
228
246
|
def to_s
|
229
247
|
if refund?
|
230
248
|
"Refund ##{to_param}"
|
@@ -469,13 +487,17 @@ module Effective
|
|
469
487
|
|
470
488
|
def get_tax
|
471
489
|
return nil unless tax_rate.present?
|
472
|
-
|
490
|
+
present_order_items.reject { |oi| oi.tax_exempt? }.map { |oi| (oi.subtotal * (tax_rate / 100.0)).round(0).to_i }.sum
|
473
491
|
end
|
474
492
|
|
475
493
|
private
|
476
494
|
|
495
|
+
def present_order_items
|
496
|
+
order_items.reject { |oi| oi.marked_for_destruction? }
|
497
|
+
end
|
498
|
+
|
477
499
|
def assign_order_totals
|
478
|
-
self.subtotal =
|
500
|
+
self.subtotal = present_order_items.map { |oi| oi.subtotal }.sum
|
479
501
|
self.tax_rate = get_tax_rate() unless (tax_rate || 0) > 0
|
480
502
|
self.tax = get_tax()
|
481
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.5.
|
4
|
+
version: 4.5.6
|
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-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|