effective_orders 4.4.8 → 4.5.2

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
  SHA256:
3
- metadata.gz: 9e201446ccdd9da7fa7afe58f64d9721438bfa2eb9d0f820dcab879c9f447204
4
- data.tar.gz: 4db859784870c6e04572dcf53d9ed9cd6ecafd1a1cef1adc68bdb642d333fbba
3
+ metadata.gz: 36b254eb8e99a4c04b3b63135b2b1caa15f5a8d7803bcad0fff8323b0aab957a
4
+ data.tar.gz: 699ccd522afef972528e9dcee5b5eae8abad124cf11e0002f84e5c7a06bf0e8b
5
5
  SHA512:
6
- metadata.gz: b8ea3eb173f2db102c4539bc08add41a15f399df5d9f24a88cdf116bf98ec37e07b75ae7de6a5476a4682fe91425de25d4ece1b10ac02655f03907bcae59be11
7
- data.tar.gz: d5796fd79c659f9c25c8ac6389c101d1ccc4dc42a8b60e167c9ebad59fe46a652ce18955d871fffbfa607acae9076dad4700c63911ebbabb718f3a6e6353f82e
6
+ metadata.gz: 784ec95030d906ab226f26d7f50651062979a3e50fdf286135fc81e3907d6bc23a93c77e1504433012ea59e49bcb4613702723b69a9fe58b858fd36a15ae1590
7
+ data.tar.gz: 7f1cf4534c235f84a025a040b2988fcfa8664046d7026de8665f4c14b139afdbd570a4491ffb46ade0d5ba40f80bd6403064f6de6aa5fa4e3ace5e1032331f83
@@ -14,11 +14,13 @@ class Admin::EffectiveOrdersDatatable < Effective::Datatable
14
14
  end
15
15
 
16
16
  filters do
17
- scope :purchased, default: true
18
- scope :deferred
19
- scope :refunds
20
- scope :not_purchased
21
- scope :all
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
- 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}"
@@ -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}"
@@ -337,13 +358,14 @@ module Effective
337
358
 
338
359
  assign_attributes(
339
360
  state: EffectiveOrders::PURCHASED,
340
- purchased_at: Time.zone.now,
341
361
  payment: payment_to_h(payment),
342
362
  payment_provider: provider,
343
363
  payment_card: (card.presence || 'none'),
344
364
  skip_buyer_validations: skip_buyer_validations
345
365
  )
346
366
 
367
+ self.purchased_at ||= Time.zone.now
368
+
347
369
  Effective::Order.transaction do
348
370
  begin
349
371
  run_purchasable_callbacks(:before_purchase)
@@ -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
@@ -2,6 +2,10 @@ class CreateEffectiveOrders < ActiveRecord::Migration[4.2]
2
2
  def self.up
3
3
  create_table <%= @orders_table_name %> do |t|
4
4
  t.integer :user_id
5
+
6
+ t.integer :parent_id
7
+ t.string :parent_type
8
+
5
9
  t.string :state
6
10
  t.datetime :purchased_at
7
11
 
@@ -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.8'.freeze
2
+ VERSION = '4.5.2'.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.8
4
+ version: 4.5.2
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-22 00:00:00.000000000 Z
11
+ date: 2020-07-25 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.