effective_orders 4.0.0beta10 → 4.0.0beta11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ec9a4a2c292d467b812005f7f1d9c0574e9ac2d2
4
- data.tar.gz: 9f1803e3217276a89b2089e30ee71aed6667784c
3
+ metadata.gz: fe4a98dd89d5ffe64e9984a2f474d5d68ce02a45
4
+ data.tar.gz: d80c7ea4416f68d30a11ad80e5aa22555fa510da
5
5
  SHA512:
6
- metadata.gz: fb91eb87e7faa70156723d2021ef78a499cd4543d869705d13f94d6540acdec71f3ba798cf49c76d33c11368b95474ca970cca54a8720eb2269e56dd8c6c5913
7
- data.tar.gz: 00174cfdcd998155d3b20fc19aeedad1f206588c24971270ccddfa2f0a298cb68cb9122d79a1afd2672f82df5a8d654c6c39d236ad3e9de7943fcc5d3ab0a95e
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.subscription[:webhook_secret]) rescue nil)
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)).end_of_day
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
- # if current_plan && current_plan[:id] != 'trial' && plan[:amount] > current_plan[:amount]
175
- # Rails.logger.info " -> INVOICE GENERATED"
176
- # Stripe::Invoice.create(customer: customer.stripe_customer_id).pay rescue false
177
- # end
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.trial_expires_at.strftime('%F')}.
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
 
@@ -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 users 1, 3 and 7 days before expiring. false to disable.
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
@@ -1,3 +1,3 @@
1
1
  module EffectiveOrders
2
- VERSION = '4.0.0beta10'.freeze
2
+ VERSION = '4.0.0beta11'.freeze
3
3
  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.trial_expires_at == today
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.trial_expired? # We already notified them
51
+ next if subscribable.trial_past_due? # We already notified them
52
52
 
53
53
  reminders.each do |remind_at|
54
- next unless subscribable.trial_expires_at == (today + remind_at)
54
+ date = (subscribable.trialing_until - EffectiveOrders.trial.fetch(:length)) # Should be same as created_at.beginning_of_day
55
55
 
56
- puts "sending trial expiring to #{subscribable}. expires in #{(subscribable.trial_expires_at - today) / 1.day.to_i} days."
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.0beta10
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-22 00:00:00.000000000 Z
11
+ date: 2018-05-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails