effective_orders 5.1.15 → 5.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +0 -2
- data/app/controllers/effective/providers/free.rb +1 -2
- data/app/models/concerns/acts_as_purchasable_parent.rb +34 -0
- data/app/models/concerns/acts_as_subscribable.rb +1 -3
- data/app/models/effective/order.rb +26 -23
- data/app/models/effective/subscripter.rb +3 -5
- data/app/models/effective/subscription.rb +4 -1
- data/app/views/effective/orders/_order_shipping.html.haml +1 -1
- data/config/effective_orders.rb +0 -1
- data/lib/effective_orders/engine.rb +1 -0
- data/lib/effective_orders/version.rb +1 -1
- data/lib/effective_orders.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7b2e8598ea6f759b602e70d61c5942080c2e528fc8c123b93e3396cbc2a8a26a
|
4
|
+
data.tar.gz: 004e0db3016e081294d9c6fe49a02eb800a13f49f7917f0d83c445e5a615ebdc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 071a7b38a0c5817e3165ac17b2193288e435b0e92c3a54163bfa7997c7132f9f5c02329421198ad51e9078dc351e77a5984aafa96a2f51bef518913886bf0870
|
7
|
+
data.tar.gz: d2825cd0a8f2c66c6975bcdaf926ab9ac35081383547ad41965813d26a4d2ea059426340a1bba723f22f1ada37c19d2e16a0d34c23423189981fb8611ffdbbbd
|
data/README.md
CHANGED
@@ -399,8 +399,6 @@ On the Checkout page (`effective_orders.new_order_path`) a new `Effective::Order
|
|
399
399
|
|
400
400
|
If the configuration options `config.billing_address` and/or `config.shipping_address` options are `true` then the user will be prompted for the appropriate addresses, based on [effective_addresses](https://github.com/code-and-effect/effective_addresses/).
|
401
401
|
|
402
|
-
If `config.use_address_full_name` is set to `true` then appropriate form field will be shown and the user will be prompted for the appropriate address full name during the checkout process, based on [effective_addresses](https://github.com/code-and-effect/effective_addresses/).
|
403
|
-
|
404
402
|
When the user submits the form on this screen, a POST to `effective_orders.order_path` is made, and the `Effective::Order` object is validated and created.
|
405
403
|
|
406
404
|
On this final checkout screen, links to all configured payment providers are displayed, and the user may choose which payment processor should be used to make a payment.
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# Mostly for the callbacks
|
2
|
+
|
3
|
+
module ActsAsPurchasableParent
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
module Base
|
7
|
+
def acts_as_purchasable_parent(*options)
|
8
|
+
@acts_as_purchasable_parent = options || []
|
9
|
+
include ::ActsAsPurchasableParent
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
module ClassMethods
|
14
|
+
def acts_as_purchasable_parent?; true; end
|
15
|
+
|
16
|
+
def before_purchase(&block)
|
17
|
+
send :define_method, :before_purchase do |order| self.instance_exec(order, &block) end
|
18
|
+
end
|
19
|
+
|
20
|
+
def after_purchase(&block)
|
21
|
+
send :define_method, :after_purchase do |order| self.instance_exec(order, &block) end
|
22
|
+
end
|
23
|
+
|
24
|
+
def after_decline(&block)
|
25
|
+
send :define_method, :after_decline do |order| self.instance_exec(order, &block) end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
included do
|
30
|
+
has_many :orders, -> { order(:id) }, as: :parent, class_name: 'Effective::Order', dependent: :nullify
|
31
|
+
accepts_nested_attributes_for :orders
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
@@ -24,9 +24,7 @@ module ActsAsSubscribable
|
|
24
24
|
raise :abort unless (subscripter.destroy! rescue false)
|
25
25
|
end
|
26
26
|
|
27
|
-
if EffectiveOrders.trial?
|
28
|
-
validates :trialing_until, presence: true
|
29
|
-
end
|
27
|
+
validates :trialing_until, presence: true, if: -> { EffectiveOrders.trial? }
|
30
28
|
|
31
29
|
validates :subscription_status, inclusion: { allow_nil: true, in: EffectiveOrders::STATUSES.keys }
|
32
30
|
|
@@ -12,13 +12,11 @@ module Effective
|
|
12
12
|
self.table_name = EffectiveOrders.orders_table_name.to_s
|
13
13
|
|
14
14
|
if EffectiveOrders.obfuscate_order_ids
|
15
|
+
raise('unsupported obfuscation with tenant') if defined?(Tenant)
|
15
16
|
acts_as_obfuscated format: '###-####-###'
|
16
17
|
end
|
17
18
|
|
18
|
-
acts_as_addressable(
|
19
|
-
billing: { singular: true, use_full_name: EffectiveOrders.use_address_full_name },
|
20
|
-
shipping: { singular: true, use_full_name: EffectiveOrders.use_address_full_name }
|
21
|
-
)
|
19
|
+
acts_as_addressable(billing: { singular: true }, shipping: { singular: true })
|
22
20
|
|
23
21
|
attr_accessor :terms_and_conditions # Yes, I agree to the terms and conditions
|
24
22
|
attr_accessor :confirmed_checkout # Set on the Checkout Step 1
|
@@ -68,8 +66,8 @@ module Effective
|
|
68
66
|
before_validation { assign_order_totals }
|
69
67
|
before_validation { assign_billing_name }
|
70
68
|
before_validation { assign_email }
|
71
|
-
before_validation { assign_last_address }
|
72
69
|
before_validation { assign_user_address }
|
70
|
+
before_validation { assign_last_address }
|
73
71
|
|
74
72
|
before_validation(if: -> { confirmed_checkout }) do
|
75
73
|
assign_attributes(state: EffectiveOrders::CONFIRMED) if pending?
|
@@ -88,11 +86,14 @@ module Effective
|
|
88
86
|
validates :state, inclusion: { in: EffectiveOrders::STATES.keys }
|
89
87
|
validates :subtotal, presence: true
|
90
88
|
|
91
|
-
if EffectiveOrders.minimum_charge.to_i > 0
|
92
|
-
validates :total, presence: true
|
93
|
-
|
94
|
-
|
95
|
-
|
89
|
+
with_options(if: -> { EffectiveOrders.minimum_charge.to_i > 0 }) do
|
90
|
+
validates :total, presence: true
|
91
|
+
|
92
|
+
validate(unless: -> { (free? && EffectiveOrders.free?) || (refund? && EffectiveOrders.refund?) }) do
|
93
|
+
if total.present? && total < EffectiveOrders.minimum_charge
|
94
|
+
self.errors.add(:total, "must be $#{'%0.2f' % (EffectiveOrders.minimum_charge.to_i / 100.0)} or more. Please add additional items.")
|
95
|
+
end
|
96
|
+
end
|
96
97
|
end
|
97
98
|
|
98
99
|
validate(if: -> { tax_rate.present? }) do
|
@@ -106,17 +107,9 @@ module Effective
|
|
106
107
|
validates :tax_rate, presence: { message: "can't be determined based on billing address" }
|
107
108
|
validates :tax, presence: true
|
108
109
|
|
109
|
-
if EffectiveOrders.billing_address
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
if EffectiveOrders.shipping_address
|
114
|
-
validates :shipping_address, presence: true
|
115
|
-
end
|
116
|
-
|
117
|
-
if EffectiveOrders.collect_note_required
|
118
|
-
validates :note, presence: true
|
119
|
-
end
|
110
|
+
validates :billing_address, presence: true, if: -> { EffectiveOrders.billing_address }
|
111
|
+
validates :shipping_address, presence: true, if: -> { EffectiveOrders.shipping_address }
|
112
|
+
validates :note, presence: true, if: -> { EffectiveOrders.collect_note_required }
|
120
113
|
end
|
121
114
|
|
122
115
|
# When Purchased
|
@@ -124,12 +117,21 @@ module Effective
|
|
124
117
|
validates :purchased_at, presence: true
|
125
118
|
validates :payment, presence: true
|
126
119
|
|
127
|
-
validates :payment_provider, presence: true
|
120
|
+
validates :payment_provider, presence: true
|
121
|
+
|
122
|
+
validate do
|
123
|
+
self.errors.add(:payment_provider, "unknown payment provider") unless EffectiveOrders.payment_providers.include?(payment_provider)
|
124
|
+
end
|
125
|
+
|
128
126
|
validates :payment_card, presence: true
|
129
127
|
end
|
130
128
|
|
131
129
|
with_options if: -> { deferred? } do
|
132
|
-
validates :payment_provider, presence: true
|
130
|
+
validates :payment_provider, presence: true
|
131
|
+
|
132
|
+
validate do
|
133
|
+
self.errors.add(:payment_provider, "unknown deferred payment provider") unless EffectiveOrders.deferred_providers.include?(payment_provider)
|
134
|
+
end
|
133
135
|
end
|
134
136
|
|
135
137
|
scope :deep, -> { includes(:addresses, :user, order_items: :purchasable) }
|
@@ -636,6 +638,7 @@ module Effective
|
|
636
638
|
|
637
639
|
def run_purchasable_callbacks(name)
|
638
640
|
order_items.each { |oi| oi.purchasable.public_send(name, self, oi) if oi.purchasable.respond_to?(name) }
|
641
|
+
parent.public_send(name, self) if parent.respond_to?(name)
|
639
642
|
end
|
640
643
|
|
641
644
|
def send_email(email, *args)
|
@@ -11,11 +11,9 @@ module Effective
|
|
11
11
|
validates :subscribable, presence: true, if: -> { stripe_plan_id.present? }
|
12
12
|
validates :customer, presence: true
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
message: 'unknown plan'
|
18
|
-
}
|
14
|
+
validate(if: -> { stripe_plan_id.present? }) do
|
15
|
+
self.errors.add(:stripe_plan_id, 'unknown plan') unless EffectiveOrders.stripe_plans.map { |plan| plan[:id] }.include?(stripe_plan_id)
|
16
|
+
end
|
19
17
|
|
20
18
|
validate(if: -> { stripe_plan_id && plan && plan[:amount] > 0 }) do
|
21
19
|
self.errors.add(:stripe_token, 'updated payment card required') if stripe_token.blank? && token_required?
|
@@ -47,7 +47,10 @@ module Effective
|
|
47
47
|
validates :subscribable, presence: true
|
48
48
|
|
49
49
|
validates :stripe_plan_id, presence: true
|
50
|
-
|
50
|
+
|
51
|
+
validate(if: -> { stripe_plan_id.present? }) do
|
52
|
+
self.errors.add(:stripe_plan_id, 'unknown plan') unless EffectiveOrders.stripe_plans.map { |plan| plan[:id] }.include?(stripe_plan_id)
|
53
|
+
end
|
51
54
|
|
52
55
|
validates :stripe_subscription_id, presence: true
|
53
56
|
|
data/config/effective_orders.rb
CHANGED
@@ -19,7 +19,6 @@ EffectiveOrders.setup do |config|
|
|
19
19
|
# Require these addresses when creating a new Order. Works with effective_addresses gem
|
20
20
|
config.billing_address = true
|
21
21
|
config.shipping_address = false
|
22
|
-
config.use_address_full_name = true
|
23
22
|
|
24
23
|
# Use effective_obfuscation gem to change order.id into a seemingly random 10-digit number
|
25
24
|
config.obfuscate_order_ids = false
|
@@ -6,6 +6,7 @@ module EffectiveOrders
|
|
6
6
|
initializer 'effective_orders.active_record' do |app|
|
7
7
|
ActiveSupport.on_load :active_record do
|
8
8
|
ActiveRecord::Base.extend(ActsAsPurchasable::Base)
|
9
|
+
ActiveRecord::Base.extend(ActsAsPurchasableParent::Base)
|
9
10
|
ActiveRecord::Base.extend(ActsAsSubscribable::Base)
|
10
11
|
ActiveRecord::Base.extend(ActsAsSubscribableBuyer::Base)
|
11
12
|
end
|
data/lib/effective_orders.rb
CHANGED
@@ -36,7 +36,7 @@ module EffectiveOrders
|
|
36
36
|
:layout, :mailer_class_name, :mailer,
|
37
37
|
:orders_collection_scope, :order_tax_rate_method,
|
38
38
|
:obfuscate_order_ids, :use_effective_qb_sync,
|
39
|
-
:billing_address, :shipping_address,
|
39
|
+
:billing_address, :shipping_address,
|
40
40
|
:collect_note, :collect_note_required, :collect_note_message,
|
41
41
|
:terms_and_conditions, :terms_and_conditions_label, :minimum_charge,
|
42
42
|
|
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: 5.1
|
4
|
+
version: 5.2.1
|
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: 2021-
|
11
|
+
date: 2021-11-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -215,6 +215,7 @@ files:
|
|
215
215
|
- app/helpers/effective_subscriptions_helper.rb
|
216
216
|
- app/mailers/effective/orders_mailer.rb
|
217
217
|
- app/models/concerns/acts_as_purchasable.rb
|
218
|
+
- app/models/concerns/acts_as_purchasable_parent.rb
|
218
219
|
- app/models/concerns/acts_as_subscribable.rb
|
219
220
|
- app/models/concerns/acts_as_subscribable_buyer.rb
|
220
221
|
- app/models/effective/cart.rb
|