effective_orders 6.10.0 → 6.11.0

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: d05dc976af35c0751fd5c638d2ab2fa0ae63343230ee620694b7363e86e14a61
4
- data.tar.gz: 0fc4e26794e6fa3bd90b1037eb1984c297eb1de4a60a0bce88aaeff9ae2d43c7
3
+ metadata.gz: 6a3716b7b619276755bac8d33027424eed7b97519fdc1454d498349074e2a022
4
+ data.tar.gz: 5071eb8c4733b659c1d6e72f0ad7974301af0c32d0df6701547eedddaefc723b
5
5
  SHA512:
6
- metadata.gz: c5f6e85d70807fc53e113e9e11221f7d168367c5728287101b1fb8613251f5e19aedcd3dd0d0c98f4408e9504889c698d5325c3a065a1c812eaae48421ee7719
7
- data.tar.gz: b0ced315e41f158d6efb30deb427f44e93577b4bd245d5b96553765e9ff04b8c7f030a829b480d5d8872042e931b959e30516909d71efbdc0c1821b7db75dd11
6
+ metadata.gz: 30ee25cf450e876da9a219c303c51d1469994fc055d039fe610e7abcddd3d988bc7fa5558ac17dcf05f06ff8afc0d23d6094a1aa106271b091b0fe2c69390310
7
+ data.tar.gz: abc8e9d7fac67cac46be97ad522f7ffce5e64a47a4a12e8bc9d6f1c17368788dceab075b9ef302f7d937872ebf7f16cbcaabd5d5f9b38ba4f316a46c5dcedc9e
@@ -62,6 +62,14 @@ module ActsAsPurchasable
62
62
  module ClassMethods
63
63
  def acts_as_purchasable?; true; end
64
64
 
65
+ def before_defer(&block)
66
+ send :define_method, :before_defer do |order, order_item| self.instance_exec(order, order_item, &block) end
67
+ end
68
+
69
+ def after_defer(&block)
70
+ send :define_method, :after_defer do |order, order_item| self.instance_exec(order, order_item, &block) end
71
+ end
72
+
65
73
  def before_purchase(&block)
66
74
  send :define_method, :before_purchase do |order, order_item| self.instance_exec(order, order_item, &block) end
67
75
  end
@@ -70,6 +78,10 @@ module ActsAsPurchasable
70
78
  send :define_method, :after_purchase do |order, order_item| self.instance_exec(order, order_item, &block) end
71
79
  end
72
80
 
81
+ def before_decline(&block)
82
+ send :define_method, :before_decline do |order, order_item| self.instance_exec(order, order_item, &block) end
83
+ end
84
+
73
85
  def after_decline(&block)
74
86
  send :define_method, :after_decline do |order, order_item| self.instance_exec(order, order_item, &block) end
75
87
  end
@@ -13,6 +13,14 @@ module ActsAsPurchasableParent
13
13
  module ClassMethods
14
14
  def acts_as_purchasable_parent?; true; end
15
15
 
16
+ def before_defer(&block)
17
+ send :define_method, :before_defer do |order| self.instance_exec(order, &block) end
18
+ end
19
+
20
+ def after_defer(&block)
21
+ send :define_method, :after_defer do |order| self.instance_exec(order, &block) end
22
+ end
23
+
16
24
  def before_purchase(&block)
17
25
  send :define_method, :before_purchase do |order| self.instance_exec(order, &block) end
18
26
  end
@@ -21,6 +29,10 @@ module ActsAsPurchasableParent
21
29
  send :define_method, :after_purchase do |order| self.instance_exec(order, &block) end
22
30
  end
23
31
 
32
+ def before_decline(&block)
33
+ send :define_method, :before_decline do |order| self.instance_exec(order, &block) end
34
+ end
35
+
24
36
  def after_decline(&block)
25
37
  send :define_method, :after_decline do |order| self.instance_exec(order, &block) end
26
38
  end
@@ -696,11 +696,41 @@ module Effective
696
696
  sync_quickbooks!(skip: true)
697
697
  end
698
698
 
699
- def defer!(provider: 'none', email: true)
700
- return false if purchased?
699
+ def defer!(provider: 'none', email: true, validate: true)
700
+ raise('order already purchased') if purchased?
701
+
702
+ # Assign attributes
703
+ assign_attributes(
704
+ payment_provider: provider,
705
+
706
+ status: :deferred,
707
+ purchased_at: nil,
708
+ purchased_by: nil,
709
+
710
+ deferred_at: (deferred_at.presence || Time.zone.now),
711
+ deferred_by: (deferred_by.presence || current_user)
712
+ )
713
+
714
+ if current_user&.email.present?
715
+ assign_attributes(email: current_user.email)
716
+ end
717
+
718
+ error = nil
701
719
 
702
- assign_attributes(payment_provider: provider)
703
- deferred!
720
+ begin
721
+ Effective::Order.transaction do
722
+ run_purchasable_callbacks(:before_defer)
723
+ save!(validate: validate)
724
+ run_purchasable_callbacks(:after_defer)
725
+ end
726
+ rescue ActiveRecord::RecordInvalid => e
727
+ self.status = status_was
728
+
729
+ error = e.message
730
+ raise ::ActiveRecord::Rollback
731
+ end
732
+
733
+ raise "Failed to defer order: #{error || errors.full_messages.to_sentence}" unless error.nil?
704
734
 
705
735
  send_payment_request_to_buyer! if email
706
736
 
@@ -709,11 +739,8 @@ module Effective
709
739
 
710
740
  def decline!(payment: 'none', provider: 'none', card: 'none', validate: true)
711
741
  return false if declined?
712
-
713
742
  raise('order already purchased') if purchased?
714
743
 
715
- error = nil
716
-
717
744
  assign_attributes(
718
745
  skip_buyer_validations: true,
719
746
 
@@ -726,6 +753,12 @@ module Effective
726
753
  payment_card: (card.presence || 'none')
727
754
  )
728
755
 
756
+ if current_user&.email.present?
757
+ assign_attributes(email: current_user.email)
758
+ end
759
+
760
+ error = nil
761
+
729
762
  Effective::Order.transaction do
730
763
  begin
731
764
  run_purchasable_callbacks(:before_decline)
@@ -1,3 +1,3 @@
1
1
  module EffectiveOrders
2
- VERSION = '6.10.0'.freeze
2
+ VERSION = '6.11.0'.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: 6.10.0
4
+ version: 6.11.0
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: 2024-05-07 00:00:00.000000000 Z
11
+ date: 2024-05-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails