effective_orders 5.1.16 → 5.2.2
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/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 +42 -30
- 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 +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: a7da6644ca7ccf8e9bcc7b2326e0b68e7290bb75ab21324a81ae7e94cc912473
|
4
|
+
data.tar.gz: 41de16ee30c34ec82299e9e372d7df60a9ae862a0fb44ae4accfb964910ae5c4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 06cc3930613fa6359f603df842a44ec24d85e4d104aad2f41c964eaf800f1b98d16e2e04a3a91cfe9f7ec6a56b3516e69b579a1b709cbbe413306f60fcf20070
|
7
|
+
data.tar.gz: b5d5f0e94ef38065f924d66fca1f6124baf15b956639c216e72a1da13e205fcf22304c9be410c07e2ee79f147f8abda0c17d1cb4cedc2a7eaa49fbbf6893ee0b
|
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) }
|
@@ -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
|
|
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.2
|
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-28 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
|