effective_orders 4.0.0beta10 → 4.0.0beta11
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/controllers/effective/webhooks_controller.rb +11 -1
- data/app/models/concerns/acts_as_subscribable.rb +1 -1
- data/app/models/effective/subscripter.rb +9 -5
- data/app/views/effective/orders_mailer/subscription_trial_expiring.html.haml +1 -1
- data/config/effective_orders.rb +1 -1
- data/lib/effective_orders/version.rb +1 -1
- data/lib/tasks/effective_orders_tasks.rake +6 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fe4a98dd89d5ffe64e9984a2f474d5d68ce02a45
|
4
|
+
data.tar.gz: d80c7ea4416f68d30a11ad80e5aa22555fa510da
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4c40948325d0ef895a19aaa982343f09e4195ceb220399522a9f2759678394d479a90ef6d5ed4cae1d6c9eea34c415cd94901a74343e386b69138d41d445a051
|
7
|
+
data.tar.gz: 4d3928148ff0b56537f61eb0e06d0c1441171b0b7ee6b118973272118a69195096785a875ed7cbb007012783304c4a123a1613bdbaf6d26a2d7bc706aea7fb5e
|
@@ -1,10 +1,20 @@
|
|
1
|
+
# New workflow is:
|
2
|
+
# customer.updated
|
3
|
+
# customer.created
|
4
|
+
# customer.subscription.created
|
5
|
+
# customer.updated
|
6
|
+
# customer.source.created
|
7
|
+
# charge.succeeded
|
8
|
+
# invoice.created
|
9
|
+
# invoice.payment_succeeded
|
10
|
+
|
1
11
|
module Effective
|
2
12
|
class WebhooksController < ApplicationController
|
3
13
|
protect_from_forgery except: [:stripe]
|
4
14
|
skip_authorization_check if defined?(CanCan)
|
5
15
|
|
6
16
|
def stripe
|
7
|
-
@event = (Stripe::Webhook.construct_event(request.body.read, request.env['HTTP_STRIPE_SIGNATURE'], EffectiveOrders.
|
17
|
+
@event = (Stripe::Webhook.construct_event(request.body.read, request.env['HTTP_STRIPE_SIGNATURE'], EffectiveOrders.subscriptions[:webhook_secret]) rescue nil)
|
8
18
|
(head(:bad_request) and return) unless @event
|
9
19
|
|
10
20
|
unless EffectiveOrders.subscriptions[:ignore_livemode]
|
@@ -21,7 +21,7 @@ module ActsAsSubscribable
|
|
21
21
|
has_one :customer, through: :subscription, class_name: 'Effective::Customer'
|
22
22
|
|
23
23
|
before_validation(if: -> { trialing_until.blank? && EffectiveOrders.trial? }) do
|
24
|
-
self.trialing_until = (Time.zone.now + EffectiveOrders.trial.fetch(:length)).
|
24
|
+
self.trialing_until = (Time.zone.now + EffectiveOrders.trial.fetch(:length)).beginning_of_day
|
25
25
|
end
|
26
26
|
|
27
27
|
before_destroy(if: -> { subscribed? }) do
|
@@ -134,12 +134,16 @@ module Effective
|
|
134
134
|
return
|
135
135
|
end
|
136
136
|
|
137
|
-
# Update stripe subscription items
|
137
|
+
# Update stripe subscription items. Keep track if quantity changed here or not
|
138
|
+
quantity_increased = false
|
139
|
+
|
138
140
|
customer.stripe_subscription.items.each do |stripe_item|
|
139
141
|
item = items.find { |item| item[:plan] == stripe_item['plan']['id'] }
|
140
142
|
|
141
143
|
next if item.blank? || item[:quantity] == stripe_item['quantity']
|
142
144
|
|
145
|
+
quantity_increased ||= (item[:quantity] > stripe_item['quantity']) # Any quantity increased
|
146
|
+
|
143
147
|
stripe_item.quantity = item[:quantity]
|
144
148
|
stripe_item.metadata = item[:metadata]
|
145
149
|
|
@@ -171,10 +175,10 @@ module Effective
|
|
171
175
|
end
|
172
176
|
|
173
177
|
# When upgrading a plan, invoice immediately.
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
+
if quantity_increased
|
179
|
+
Rails.logger.info " -> QUANTITY INCREASED SO INVOICE GENERATED"
|
180
|
+
Stripe::Invoice.create(customer: customer.stripe_customer_id).pay
|
181
|
+
end
|
178
182
|
|
179
183
|
customer.status = customer.stripe_subscription.status
|
180
184
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
%p.effective-orders-receipt-info Trial expiring
|
2
2
|
|
3
|
-
%p Your trial for #{@subscribable} expires on #{@subscribable.
|
3
|
+
%p Your trial for #{@subscribable} expires on #{@subscribable.trialing_until.strftime('%F')}.
|
4
4
|
|
5
5
|
%p Please upgrade to a paid plan before your trial expires.
|
6
6
|
|
data/config/effective_orders.rb
CHANGED
@@ -256,7 +256,7 @@ EffectiveOrders.setup do |config|
|
|
256
256
|
# name: 'Free Trial',
|
257
257
|
# description: '45-Day Free Trial',
|
258
258
|
# length: 45.days,
|
259
|
-
# remind_at: [1.day, 3.days, 7.days], # Send email notification to trialing
|
259
|
+
# remind_at: [1.day, 3.days, 7.days, 40.days, 44.days], # Send email notification to trialing owners on day 1, 3, 7 40 and 44. false to disable
|
260
260
|
# }
|
261
261
|
|
262
262
|
end
|
@@ -43,17 +43,19 @@ namespace :effective_orders do
|
|
43
43
|
begin
|
44
44
|
ActsAsSubscribable.descendants.each do |klass|
|
45
45
|
klass.trialing.find_each do |subscribable|
|
46
|
-
if subscribable.
|
46
|
+
if subscribable.trialing_until == today
|
47
47
|
puts "sending trial expired to #{subscribable}"
|
48
48
|
Effective::OrdersMailer.subscription_trial_expired(subscribable).deliver_now
|
49
49
|
end
|
50
50
|
|
51
|
-
next if subscribable.
|
51
|
+
next if subscribable.trial_past_due? # We already notified them
|
52
52
|
|
53
53
|
reminders.each do |remind_at|
|
54
|
-
|
54
|
+
date = (subscribable.trialing_until - EffectiveOrders.trial.fetch(:length)) # Should be same as created_at.beginning_of_day
|
55
55
|
|
56
|
-
|
56
|
+
next unless date == (today + remind_at)
|
57
|
+
|
58
|
+
puts "sending trial expiring to #{subscribable}. expires in #{(subscribable.trialing_until - today) / 1.day.to_i} days."
|
57
59
|
Effective::OrdersMailer.subscription_trial_expiring(subscribable).deliver_now
|
58
60
|
end
|
59
61
|
end
|
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.0.
|
4
|
+
version: 4.0.0beta11
|
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: 2018-05-
|
11
|
+
date: 2018-05-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|