effective_orders 5.1.17 → 5.2.3
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/README.md +0 -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 +41 -29
- data/app/models/effective/subscripter.rb +3 -5
- data/app/models/effective/subscription.rb +4 -1
- data/app/views/effective/orders/_checkout_step2.html.haml +2 -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 +2 -2
- 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: b71f36aac1ec66c0744301209933bc4f642137519bf720a904f5b845f9970dff
|
4
|
+
data.tar.gz: 1aa4ccb644014cf6d3e1aa4913dc75e475f2b69c67332f8c3a6e07c6612f9259
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 720181b8b9446f583bb12c19dbb181fd9d31e7615cdccecaf4d6b10bcedbd10217ca1a8af85dca01974274a1f989901fb5aacc8825b2f48993b39ab6ea22f992
|
7
|
+
data.tar.gz: 857d43e8ffec647adf71a12088eee4800c364f687bb45a154b75df486c6759ffd4b10c462243f82f7a2907c12e902ffbf099134a8e7cfa76d68124105dd88e72
|
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
|
@@ -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) }
|
@@ -457,13 +459,16 @@ module Effective
|
|
457
459
|
self.payment = payment_to_h(payment) if self.payment.blank?
|
458
460
|
|
459
461
|
begin
|
460
|
-
|
462
|
+
EffectiveResources.transaction do
|
461
463
|
run_purchasable_callbacks(:before_purchase)
|
464
|
+
|
462
465
|
save!
|
463
466
|
update_purchasables_purchased_order!
|
467
|
+
|
468
|
+
run_purchasable_callbacks(:after_purchase)
|
464
469
|
end
|
465
470
|
rescue => e
|
466
|
-
|
471
|
+
EffectiveResources.transaction do
|
467
472
|
save!(validate: false)
|
468
473
|
update_purchasables_purchased_order!
|
469
474
|
end
|
@@ -471,7 +476,6 @@ module Effective
|
|
471
476
|
raise(e)
|
472
477
|
end
|
473
478
|
|
474
|
-
run_purchasable_callbacks(:after_purchase)
|
475
479
|
send_order_receipts! if email
|
476
480
|
|
477
481
|
true
|
@@ -504,9 +508,11 @@ module Effective
|
|
504
508
|
skip_buyer_validations: true
|
505
509
|
)
|
506
510
|
|
507
|
-
|
511
|
+
EffectiveResources.transaction do
|
508
512
|
begin
|
513
|
+
run_purchasable_callbacks(:before_decline)
|
509
514
|
save!(validate: validate)
|
515
|
+
run_purchasable_callbacks(:after_decline)
|
510
516
|
rescue => e
|
511
517
|
self.state = state_was
|
512
518
|
|
@@ -517,8 +523,6 @@ module Effective
|
|
517
523
|
|
518
524
|
raise "Failed to decline order: #{error || errors.full_messages.to_sentence}" unless error.nil?
|
519
525
|
|
520
|
-
run_purchasable_callbacks(:after_decline)
|
521
|
-
|
522
526
|
true
|
523
527
|
end
|
524
528
|
|
@@ -635,7 +639,15 @@ module Effective
|
|
635
639
|
end
|
636
640
|
|
637
641
|
def run_purchasable_callbacks(name)
|
638
|
-
order_items.
|
642
|
+
order_items.select { |item| item.purchasable.respond_to?(name) }.each do |item|
|
643
|
+
EffectiveResources.transaction(item) { item.purchasable.public_send(name, self, item) }
|
644
|
+
end
|
645
|
+
|
646
|
+
if parent.respond_to?(name)
|
647
|
+
EffectiveResources.transaction(parent) { parent.public_send(name, self) }
|
648
|
+
end
|
649
|
+
|
650
|
+
true
|
639
651
|
end
|
640
652
|
|
641
653
|
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
|
|
@@ -1,6 +1,7 @@
|
|
1
1
|
= render partial: 'effective/orders/order', locals: { order: order }
|
2
2
|
|
3
|
-
- if
|
3
|
+
- # Show this if I'm on the effective orders checkout screen. But not on a rendered order.
|
4
|
+
- if order.persisted? && order.user == current_user && request.path.to_s.start_with?(effective_orders.order_path(order))
|
4
5
|
.effective-order-change-items
|
5
6
|
= link_to 'Change Addresses', effective_orders.edit_order_path(order), rel: :nofollow, class: 'btn btn-secondary'
|
6
7
|
|
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
|
|
@@ -116,7 +116,7 @@ module EffectiveOrders
|
|
116
116
|
|
117
117
|
# The Effective::Order.payment_provider value must be in this collection
|
118
118
|
def self.payment_providers
|
119
|
-
|
119
|
+
[
|
120
120
|
('cheque' if cheque?),
|
121
121
|
('credit card' if mark_as_paid?),
|
122
122
|
('free' if free?),
|
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.
|
4
|
+
version: 5.2.3
|
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-12-03 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
|