effective_orders 4.4.9 → 4.4.10

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 91f309d8560e78018e04639fa0e733cc40632b33048b22b30458e888216420d9
4
- data.tar.gz: 6562b45ee4e8e400d94d85e568126ad67648eda2525bdc7fdbfefa6b78bc3ab1
3
+ metadata.gz: c92ae430fbce8f9ee7692d921653fffda8419a6d76eb2a4b43f3efcc932b7902
4
+ data.tar.gz: 9ce838e457cb9a3d365641b1d6d975f55fa118eed1df7be6d8071044a845fc38
5
5
  SHA512:
6
- metadata.gz: c15aa6b827a544df46d52c2fff312a7dd4500bfd2e5c94cd3a59a88687ef29e053555038685601d578e92c385b00a3e253daec03b7893405adb21d75dad54a80
7
- data.tar.gz: 39eabeb2eacc02d433ea2eb2545bb007d56d3cc96e0868f87febd719903dbb574c776c197ab301216c1f994c81619fb2d71fd26b6c26d843ffdad3086de20a6a
6
+ metadata.gz: 4f2999ad4d947a2f3623d4dfa82aa6f9a31daabef750715bc2d4671dae7f64e3dee7076e26dd6e678b4e1ecc394ea96f4a37f241fc258eea53f533e7040a1216
7
+ data.tar.gz: 825f4065b65081552b68d6228c5c7d72e96d60cc6967e1789485df31366aa9f6ce5e09c2508604e697180ef7ccd7b9c5e5b75bc94ee9c954cb7dce091c885a5d
@@ -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
- 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
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
- instance = new()
11
- raise 'must respond to trialing_until' unless instance.respond_to?(:trialing_until)
12
- raise 'must respond to subscription_status' unless instance.respond_to?(:subscription_status)
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: -> { trialing_until.blank? && EffectiveOrders.trial? }) do
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
- validates :trialing_until, presence: true, if: -> { EffectiveOrders.trial? }
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}"
@@ -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.stripe_customer.invoices.present?
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.stripe_customer.invoices.each do |invoice|
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
@@ -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])
@@ -1,3 +1,3 @@
1
1
  module EffectiveOrders
2
- VERSION = '4.4.9'.freeze
2
+ VERSION = '4.4.10'.freeze
3
3
  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.4.9
4
+ version: 4.4.10
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-05-26 00:00:00.000000000 Z
11
+ date: 2020-06-22 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.0.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.