effective_orders 6.6.3 → 6.7.1
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/MIT-LICENSE +1 -1
- data/README.md +1 -1
- data/app/controllers/admin/orders_controller.rb +2 -3
- data/app/controllers/effective/carts_controller.rb +3 -3
- data/app/controllers/effective/concerns/purchase.rb +1 -1
- data/app/controllers/effective/orders_controller.rb +1 -1
- data/app/controllers/effective/providers/moneris_checkout.rb +5 -0
- data/app/datatables/admin/effective_orders_datatable.rb +3 -0
- data/app/datatables/effective_orders_datatable.rb +2 -0
- data/app/helpers/effective_stripe_helper.rb +1 -1
- data/app/models/concerns/acts_as_purchasable.rb +8 -7
- data/app/models/effective/order.rb +80 -59
- data/app/models/effective/tax_rate_calculator.rb +8 -8
- data/app/views/effective/orders/_datatable_actions.html.haml +4 -1
- data/app/views/effective/orders/_order_header.html.haml +4 -0
- data/app/views/effective/orders/show.html.haml +1 -1
- data/config/routes.rb +3 -0
- data/db/migrate/01_create_effective_orders.rb.erb +3 -1
- data/lib/effective_orders/version.rb +1 -1
- data/lib/effective_orders.rb +1 -21
- data/lib/generators/templates/effective_orders_mailer_preview.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7459a763eab11675ddfe273af19f563ed661cf01919c7f16cded64d8e8b34d90
|
|
4
|
+
data.tar.gz: 4154b76b4bc53fb2b3e2061d37f87359550b9a73481727d169f828a2e892e09b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5e27bf43b30612c9867729ebb1c3b49c72df4141d8798e4a068c6aa22392affd0577fde516aba1abd184ef99e8ebb93554716bd63cf67f3734bd5a2b4fb569d7
|
|
7
|
+
data.tar.gz: ad8507d5fe1c7e497edac91d2b00869a40e48e70e979a10c14ceddbbb7280fca1994a7ab3b9c4e0338a59d43529b74b09a6464002d4571369e0725a23a99b809
|
data/MIT-LICENSE
CHANGED
data/README.md
CHANGED
|
@@ -353,7 +353,7 @@ The permissions you actually want to define for a regular user are as follows (u
|
|
|
353
353
|
can [:manage], Effective::Cart, user_id: user.id
|
|
354
354
|
|
|
355
355
|
can [:manage], Effective::Order, user_id: user.id # Orders cannot be deleted
|
|
356
|
-
cannot [:edit, :update], Effective::Order,
|
|
356
|
+
cannot [:edit, :update], Effective::Order, status: 'purchased'
|
|
357
357
|
|
|
358
358
|
can [:manage], Effective::Subscription, user_id: user.id
|
|
359
359
|
```
|
|
@@ -46,8 +46,7 @@ module Admin
|
|
|
46
46
|
|
|
47
47
|
if request.get?
|
|
48
48
|
@order.assign_confirmed_if_valid!
|
|
49
|
-
render(:checkout)
|
|
50
|
-
return
|
|
49
|
+
return render(:checkout)
|
|
51
50
|
end
|
|
52
51
|
|
|
53
52
|
# Otherwise a post
|
|
@@ -96,7 +95,7 @@ module Admin
|
|
|
96
95
|
|
|
97
96
|
@orders.each { |order| order.send_payment_request_to_buyer! }
|
|
98
97
|
render json: { status: 200, message: "Successfully sent #{@orders.length} payment request emails"}
|
|
99
|
-
rescue => e
|
|
98
|
+
rescue Exception => e
|
|
100
99
|
render json: { status: 500, message: "Bulk send payment request error: #{e.message}" }
|
|
101
100
|
end
|
|
102
101
|
end
|
|
@@ -33,7 +33,7 @@ module Effective
|
|
|
33
33
|
def add_to_cart
|
|
34
34
|
@purchasable = (add_to_cart_params[:purchasable_type].constantize.find(add_to_cart_params[:purchasable_id].to_i) rescue nil)
|
|
35
35
|
|
|
36
|
-
EffectiveResources.authorize!(self, :
|
|
36
|
+
EffectiveResources.authorize!(self, :add_to_cart, current_cart)
|
|
37
37
|
|
|
38
38
|
begin
|
|
39
39
|
raise "Please select a valid #{add_to_cart_params[:purchasable_type] || 'item' }." unless @purchasable
|
|
@@ -42,7 +42,7 @@ module Effective
|
|
|
42
42
|
flash[:success] = 'Successfully added item to cart.'
|
|
43
43
|
rescue EffectiveOrders::SoldOutException
|
|
44
44
|
flash[:warning] = 'This item is sold out.'
|
|
45
|
-
rescue => e
|
|
45
|
+
rescue Exception => e
|
|
46
46
|
flash[:danger] = 'Unable to add item to cart: ' + e.message
|
|
47
47
|
end
|
|
48
48
|
|
|
@@ -52,7 +52,7 @@ module Effective
|
|
|
52
52
|
def remove_from_cart
|
|
53
53
|
@cart_item = current_cart.cart_items.find(remove_from_cart_params[:id])
|
|
54
54
|
|
|
55
|
-
EffectiveResources.authorize!(self, :
|
|
55
|
+
EffectiveResources.authorize!(self, :remove_from_cart, current_cart)
|
|
56
56
|
|
|
57
57
|
if @cart_item.destroy
|
|
58
58
|
flash[:success] = 'Successfully removed item from cart.'
|
|
@@ -25,7 +25,7 @@ module Effective
|
|
|
25
25
|
def order_deferred(provider:, email: true, deferred_url: nil)
|
|
26
26
|
@order.defer!(provider: provider, email: email)
|
|
27
27
|
|
|
28
|
-
Effective::Cart.where(user:
|
|
28
|
+
Effective::Cart.where(user: current_user).destroy_all if current_user.present?
|
|
29
29
|
|
|
30
30
|
if flash[:success].blank?
|
|
31
31
|
if email
|
|
@@ -133,7 +133,7 @@ module Effective
|
|
|
133
133
|
end
|
|
134
134
|
|
|
135
135
|
render json: { status: 200, message: "Successfully sent #{@orders.length} receipt emails"}
|
|
136
|
-
rescue => e
|
|
136
|
+
rescue Exception => e
|
|
137
137
|
render json: { status: 500, message: "Bulk send buyer receipt error: #{e.message}" }
|
|
138
138
|
end
|
|
139
139
|
end
|
|
@@ -22,6 +22,11 @@ module Effective
|
|
|
22
22
|
)
|
|
23
23
|
end
|
|
24
24
|
|
|
25
|
+
if payment['card_type'].present?
|
|
26
|
+
active_card = "**** **** **** #{payment['first6last4'].to_s.last(4)} #{payment['card_type']} #{payment['expiry_date'].to_s.first(2)}/#{payment['expiry_date'].to_s.last(2)}"
|
|
27
|
+
payment = payment.except('first6last4').merge('active_card' => active_card)
|
|
28
|
+
end
|
|
29
|
+
|
|
25
30
|
order_purchased(
|
|
26
31
|
payment: payment,
|
|
27
32
|
provider: 'moneris_checkout',
|
|
@@ -20,6 +20,7 @@ module Admin
|
|
|
20
20
|
scope :purchased
|
|
21
21
|
|
|
22
22
|
scope :deferred if EffectiveOrders.deferred_providers.present?
|
|
23
|
+
scope :voided
|
|
23
24
|
|
|
24
25
|
scope :pending_refunds if EffectiveOrders.refund && !EffectiveOrders.buyer_purchases_refund?
|
|
25
26
|
scope :refunds if EffectiveOrders.refund
|
|
@@ -40,6 +41,8 @@ module Admin
|
|
|
40
41
|
'#' + order.to_param
|
|
41
42
|
end
|
|
42
43
|
|
|
44
|
+
col :status
|
|
45
|
+
|
|
43
46
|
col :purchased_at do |order|
|
|
44
47
|
order.purchased_at&.strftime('%F %H:%M') || ('pending refund' if order.pending_refund?) || ("pending #{order.payment_provider}" if order.deferred?) || 'not purchased'
|
|
45
48
|
end
|
|
@@ -30,10 +30,10 @@ module ActsAsPurchasable
|
|
|
30
30
|
has_many :order_items, as: :purchasable, class_name: 'Effective::OrderItem'
|
|
31
31
|
has_many :orders, -> { order(:id) }, through: :order_items, class_name: 'Effective::Order'
|
|
32
32
|
|
|
33
|
-
has_many :purchased_orders, -> { where(
|
|
33
|
+
has_many :purchased_orders, -> { where(status: :purchased).order(:purchased_at) },
|
|
34
34
|
through: :order_items, class_name: 'Effective::Order', source: :order
|
|
35
35
|
|
|
36
|
-
has_many :deferred_orders, -> { where(
|
|
36
|
+
has_many :deferred_orders, -> { where(status: :deferred).order(:created_at) },
|
|
37
37
|
through: :order_items, class_name: 'Effective::Order', source: :order
|
|
38
38
|
|
|
39
39
|
# Database max integer value is 2147483647. So let's round that down and use a max/min of $20 million (2000000000)
|
|
@@ -52,10 +52,11 @@ module ActsAsPurchasable
|
|
|
52
52
|
scope :purchased, -> { where.not(purchased_order_id: nil) }
|
|
53
53
|
scope :not_purchased, -> { where(purchased_order_id: nil) }
|
|
54
54
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
scope :
|
|
55
|
+
scope :purchased_by, lambda { |user| joins(order_items: :order).where(orders: { purchased_by: user, status: :purchased }).distinct }
|
|
56
|
+
scope :not_purchased_by, lambda { |user| where.not(id: purchased_by(user)) }
|
|
57
|
+
|
|
58
|
+
scope :purchased_or_deferred, -> { joins(order_items: :order).where(orders: { status: [:purchased, :deferred] }) }
|
|
59
|
+
scope :deferred, -> { joins(order_items: :order).where(orders: { status: :deferred }) }
|
|
59
60
|
end
|
|
60
61
|
|
|
61
62
|
module ClassMethods
|
|
@@ -110,7 +111,7 @@ module ActsAsPurchasable
|
|
|
110
111
|
end
|
|
111
112
|
|
|
112
113
|
def purchased_by?(user)
|
|
113
|
-
purchased_orders.any? { |order| order.
|
|
114
|
+
purchased_orders.any? { |order| order.purchased_by_id == user.id }
|
|
114
115
|
end
|
|
115
116
|
|
|
116
117
|
def purchased_download_url # Override me if this is a digital purchase.
|
|
@@ -1,24 +1,41 @@
|
|
|
1
|
-
# When an Order is first initialized it is done in the pending
|
|
2
|
-
# - when it's in the pending
|
|
1
|
+
# When an Order is first initialized it is done in the pending status
|
|
2
|
+
# - when it's in the pending status, none of the buyer entered information is required
|
|
3
3
|
# - when a pending order is rendered:
|
|
4
4
|
# - if the user has a billing address, go to step 2
|
|
5
5
|
# - if the user has no billing address, go to step 1
|
|
6
6
|
#
|
|
7
|
-
# After Step1, we go to the confirmed
|
|
8
|
-
# After Step2, we are in the purchased or declined
|
|
7
|
+
# After Step1, we go to the confirmed status
|
|
8
|
+
# After Step2, we are in the purchased or declined status
|
|
9
9
|
|
|
10
10
|
module Effective
|
|
11
11
|
class Order < ActiveRecord::Base
|
|
12
12
|
self.table_name = EffectiveOrders.orders_table_name.to_s
|
|
13
13
|
|
|
14
|
+
# Effective Resources
|
|
15
|
+
acts_as_statused(
|
|
16
|
+
:pending, # New orders are created in a pending state
|
|
17
|
+
:confirmed, # Once the order has passed checkout step 1
|
|
18
|
+
:deferred, # Deferred providers. cheque, etransfer or phone was selected.
|
|
19
|
+
:purchased, # Purchased by provider
|
|
20
|
+
:declined, # Declined by provider
|
|
21
|
+
:voided, # Voided by admin
|
|
22
|
+
:abandoned # Not set by this gem. Can be set outside it.
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
# Effective Addresses
|
|
26
|
+
acts_as_addressable(billing: { singular: true }, shipping: { singular: true })
|
|
27
|
+
|
|
28
|
+
# Effective Logging
|
|
29
|
+
log_changes if respond_to?(:log_changes)
|
|
30
|
+
|
|
31
|
+
# Effective Obfuscation
|
|
14
32
|
if EffectiveOrders.obfuscate_order_ids
|
|
15
33
|
raise('unsupported obfuscation with tenant') if defined?(Tenant)
|
|
16
34
|
acts_as_obfuscated format: '###-####-###'
|
|
17
35
|
end
|
|
18
36
|
|
|
19
|
-
|
|
37
|
+
# Effective Reports
|
|
20
38
|
acts_as_reportable if respond_to?(:acts_as_reportable)
|
|
21
|
-
log_changes if respond_to?(:log_changes)
|
|
22
39
|
|
|
23
40
|
attr_accessor :terms_and_conditions # Yes, I agree to the terms and conditions
|
|
24
41
|
attr_accessor :confirmed_checkout # Set on the Checkout Step 1
|
|
@@ -47,7 +64,10 @@ module Effective
|
|
|
47
64
|
|
|
48
65
|
# Attributes
|
|
49
66
|
effective_resource do
|
|
50
|
-
|
|
67
|
+
# Acts as Statused
|
|
68
|
+
status :string
|
|
69
|
+
status_steps :text
|
|
70
|
+
|
|
51
71
|
purchased_at :datetime
|
|
52
72
|
|
|
53
73
|
note :text # From buyer to admin
|
|
@@ -82,16 +102,20 @@ module Effective
|
|
|
82
102
|
scope :deep, -> { includes(:addresses, :user, :purchased_by, :organization, order_items: :purchasable) }
|
|
83
103
|
scope :sorted, -> { order(:id) }
|
|
84
104
|
|
|
85
|
-
scope :purchased, -> { where(
|
|
105
|
+
scope :purchased, -> { where(status: :purchased) }
|
|
106
|
+
scope :purchased_or_deferred, -> { where(status: [:purchased, :deferred]) }
|
|
107
|
+
|
|
86
108
|
scope :purchased_by, lambda { |user| purchased.where(user: user) }
|
|
87
|
-
scope :not_purchased, -> { where.not(state: [EffectiveOrders::PURCHASED, EffectiveOrders::DEFERRED]) }
|
|
88
|
-
scope :was_not_purchased, -> { where.not(state: EffectiveOrders::PURCHASED) }
|
|
89
109
|
|
|
90
|
-
scope :
|
|
91
|
-
scope :
|
|
92
|
-
|
|
93
|
-
scope :
|
|
94
|
-
scope :
|
|
110
|
+
scope :not_purchased, -> { where.not(status: [:purchased, :deferred]) }
|
|
111
|
+
scope :was_not_purchased, -> { where.not(status: :purchased) }
|
|
112
|
+
|
|
113
|
+
scope :pending, -> { where(status: :pending) }
|
|
114
|
+
scope :confirmed, -> { where(status: :confirmed) }
|
|
115
|
+
scope :deferred, -> { where(status: :deferred) }
|
|
116
|
+
scope :declined, -> { where(status: :declined) }
|
|
117
|
+
scope :abandoned, -> { where(status: :abandoned) }
|
|
118
|
+
scope :voided, -> { where(status: :voided) }
|
|
95
119
|
|
|
96
120
|
scope :refunds, -> { purchased.where('total < ?', 0) }
|
|
97
121
|
scope :pending_refunds, -> { not_purchased.where('total < ?', 0) }
|
|
@@ -102,8 +126,7 @@ module Effective
|
|
|
102
126
|
end
|
|
103
127
|
|
|
104
128
|
before_validation do
|
|
105
|
-
|
|
106
|
-
self.state = EffectiveOrders::CONFIRMED if pending? && confirmed_checkout
|
|
129
|
+
assign_attributes(status: :confirmed) if pending? && confirmed_checkout
|
|
107
130
|
end
|
|
108
131
|
|
|
109
132
|
before_validation do
|
|
@@ -126,7 +149,6 @@ module Effective
|
|
|
126
149
|
validates :cc, email_cc: true
|
|
127
150
|
|
|
128
151
|
validates :order_items, presence: { message: 'No items are present. Please add additional items.' }
|
|
129
|
-
validates :state, inclusion: { in: EffectiveOrders::STATES.keys }
|
|
130
152
|
|
|
131
153
|
validate do
|
|
132
154
|
if EffectiveOrders.organization_enabled?
|
|
@@ -179,8 +201,12 @@ module Effective
|
|
|
179
201
|
end
|
|
180
202
|
end
|
|
181
203
|
|
|
204
|
+
validate(if: -> { was_voided? }) do
|
|
205
|
+
errors.add(:status, "cannot update a voided order") unless (voided? || pending?)
|
|
206
|
+
end
|
|
207
|
+
|
|
182
208
|
# Sanity check
|
|
183
|
-
before_save(if: -> {
|
|
209
|
+
before_save(if: -> { status_was.to_s == 'purchased' }) do
|
|
184
210
|
raise('cannot unpurchase an order') unless purchased?
|
|
185
211
|
|
|
186
212
|
raise('cannot change subtotal of a purchased order') if changes[:subtotal].present?
|
|
@@ -204,7 +230,7 @@ module Effective
|
|
|
204
230
|
# Effective::Order.new(items: Product.first, user: User.first, billing_address: Effective::Address.new, shipping_address: Effective::Address.new)
|
|
205
231
|
|
|
206
232
|
def initialize(atts = nil, &block)
|
|
207
|
-
super(
|
|
233
|
+
super(status: :pending) # Initialize with status pending
|
|
208
234
|
|
|
209
235
|
return self unless atts.present?
|
|
210
236
|
|
|
@@ -383,6 +409,10 @@ module Effective
|
|
|
383
409
|
payment[:active_card][15,4]
|
|
384
410
|
end
|
|
385
411
|
|
|
412
|
+
last4 ||= if payment['active_card'] && payment['active_card'].include?('**** **** ****')
|
|
413
|
+
payment['active_card'][15,4]
|
|
414
|
+
end
|
|
415
|
+
|
|
386
416
|
# stripe, moneris, moneris_checkout
|
|
387
417
|
last4 ||= (payment['f4l4'] || payment['first6last4']).to_s.last(4)
|
|
388
418
|
|
|
@@ -406,24 +436,12 @@ module Effective
|
|
|
406
436
|
Array(billing_name.to_s.split(' ')[1..-1]).join(' ')
|
|
407
437
|
end
|
|
408
438
|
|
|
409
|
-
def pending?
|
|
410
|
-
state == EffectiveOrders::PENDING
|
|
411
|
-
end
|
|
412
|
-
|
|
413
|
-
def confirmed?
|
|
414
|
-
state == EffectiveOrders::CONFIRMED
|
|
415
|
-
end
|
|
416
|
-
|
|
417
|
-
def deferred?
|
|
418
|
-
state == EffectiveOrders::DEFERRED
|
|
419
|
-
end
|
|
420
|
-
|
|
421
439
|
def in_progress?
|
|
422
440
|
pending? || confirmed? || deferred?
|
|
423
441
|
end
|
|
424
442
|
|
|
425
443
|
def done?
|
|
426
|
-
persisted? && (purchased? || declined?)
|
|
444
|
+
persisted? && (purchased? || declined? || voided? || abandoned?)
|
|
427
445
|
end
|
|
428
446
|
|
|
429
447
|
# A custom order is one that was created by an admin
|
|
@@ -433,15 +451,11 @@ module Effective
|
|
|
433
451
|
end
|
|
434
452
|
|
|
435
453
|
def purchased?(provider = nil)
|
|
436
|
-
return false if (
|
|
454
|
+
return false if (status.to_sym != :purchased)
|
|
437
455
|
return true if provider.nil? || payment_provider == provider.to_s
|
|
438
456
|
false
|
|
439
457
|
end
|
|
440
458
|
|
|
441
|
-
def was_purchased?
|
|
442
|
-
state_was == EffectiveOrders::PURCHASED
|
|
443
|
-
end
|
|
444
|
-
|
|
445
459
|
def purchased_with_credit_card?
|
|
446
460
|
purchased? && EffectiveOrders.credit_card_payment_providers.include?(payment_provider)
|
|
447
461
|
end
|
|
@@ -450,14 +464,6 @@ module Effective
|
|
|
450
464
|
purchased? && EffectiveOrders.credit_card_payment_providers.exclude?(payment_provider)
|
|
451
465
|
end
|
|
452
466
|
|
|
453
|
-
def declined?
|
|
454
|
-
state == EffectiveOrders::DECLINED
|
|
455
|
-
end
|
|
456
|
-
|
|
457
|
-
def abandoned?
|
|
458
|
-
state == EffectiveOrders::ABANDONED
|
|
459
|
-
end
|
|
460
|
-
|
|
461
467
|
def purchasables
|
|
462
468
|
present_order_items.map { |order_item| order_item.purchasable }.compact
|
|
463
469
|
end
|
|
@@ -558,7 +564,7 @@ module Effective
|
|
|
558
564
|
def pending!
|
|
559
565
|
return false if purchased?
|
|
560
566
|
|
|
561
|
-
|
|
567
|
+
assign_attributes(status: :pending)
|
|
562
568
|
self.addresses.clear if addresses.any? { |address| address.valid? == false }
|
|
563
569
|
save!
|
|
564
570
|
|
|
@@ -572,18 +578,18 @@ module Effective
|
|
|
572
578
|
# Used by admin checkout only
|
|
573
579
|
def confirm!
|
|
574
580
|
return false if purchased?
|
|
575
|
-
|
|
581
|
+
confirmed!
|
|
576
582
|
end
|
|
577
583
|
|
|
578
584
|
# This lets us skip to the confirmed workflow for an admin...
|
|
579
585
|
def assign_confirmed_if_valid!
|
|
580
586
|
return unless pending?
|
|
581
587
|
|
|
582
|
-
|
|
588
|
+
assign_attributes(status: :confirmed)
|
|
583
589
|
return true if valid?
|
|
584
590
|
|
|
585
591
|
self.errors.clear
|
|
586
|
-
|
|
592
|
+
assign_attributes(status: :pending)
|
|
587
593
|
false
|
|
588
594
|
end
|
|
589
595
|
|
|
@@ -604,11 +610,13 @@ module Effective
|
|
|
604
610
|
def purchase!(payment: nil, provider: nil, card: nil, email: true, skip_buyer_validations: false, skip_quickbooks: false, current_user: nil)
|
|
605
611
|
return true if purchased?
|
|
606
612
|
|
|
613
|
+
raise('unable to purchase voided order') if voided?
|
|
614
|
+
|
|
607
615
|
# Assign attributes
|
|
608
616
|
assign_attributes(
|
|
609
|
-
state: EffectiveOrders::PURCHASED,
|
|
610
617
|
skip_buyer_validations: skip_buyer_validations,
|
|
611
618
|
|
|
619
|
+
status: :purchased,
|
|
612
620
|
purchased_at: (purchased_at.presence || Time.zone.now),
|
|
613
621
|
purchased_by: (purchased_by.presence || current_user),
|
|
614
622
|
|
|
@@ -633,7 +641,7 @@ module Effective
|
|
|
633
641
|
|
|
634
642
|
run_purchasable_callbacks(:after_purchase)
|
|
635
643
|
end
|
|
636
|
-
rescue => e
|
|
644
|
+
rescue ActiveRecord::RecordInvalid => e
|
|
637
645
|
Effective::Order.transaction do
|
|
638
646
|
save!(validate: false)
|
|
639
647
|
update_purchasables_purchased_order!
|
|
@@ -668,8 +676,8 @@ module Effective
|
|
|
668
676
|
def defer!(provider: 'none', email: true)
|
|
669
677
|
return false if purchased?
|
|
670
678
|
|
|
671
|
-
assign_attributes(
|
|
672
|
-
|
|
679
|
+
assign_attributes(payment_provider: provider)
|
|
680
|
+
deferred!
|
|
673
681
|
|
|
674
682
|
send_payment_request_to_buyer! if email
|
|
675
683
|
|
|
@@ -684,12 +692,15 @@ module Effective
|
|
|
684
692
|
error = nil
|
|
685
693
|
|
|
686
694
|
assign_attributes(
|
|
687
|
-
|
|
695
|
+
skip_buyer_validations: true,
|
|
696
|
+
|
|
697
|
+
status: :declined,
|
|
688
698
|
purchased_at: nil,
|
|
699
|
+
purchased_by: nil,
|
|
700
|
+
|
|
689
701
|
payment: payment_to_h(payment),
|
|
690
702
|
payment_provider: provider,
|
|
691
|
-
payment_card: (card.presence || 'none')
|
|
692
|
-
skip_buyer_validations: true
|
|
703
|
+
payment_card: (card.presence || 'none')
|
|
693
704
|
)
|
|
694
705
|
|
|
695
706
|
Effective::Order.transaction do
|
|
@@ -697,8 +708,8 @@ module Effective
|
|
|
697
708
|
run_purchasable_callbacks(:before_decline)
|
|
698
709
|
save!(validate: validate)
|
|
699
710
|
run_purchasable_callbacks(:after_decline)
|
|
700
|
-
rescue => e
|
|
701
|
-
self.
|
|
711
|
+
rescue ActiveRecord::RecordInvalid => e
|
|
712
|
+
self.status = status_was
|
|
702
713
|
|
|
703
714
|
error = e.message
|
|
704
715
|
raise ::ActiveRecord::Rollback
|
|
@@ -710,6 +721,16 @@ module Effective
|
|
|
710
721
|
true
|
|
711
722
|
end
|
|
712
723
|
|
|
724
|
+
def void!
|
|
725
|
+
raise('unable to void a purchased order') if purchased?
|
|
726
|
+
voided!
|
|
727
|
+
end
|
|
728
|
+
|
|
729
|
+
def unvoid!
|
|
730
|
+
raise('order must be voided to unvoid') unless voided?
|
|
731
|
+
pending!
|
|
732
|
+
end
|
|
733
|
+
|
|
713
734
|
# These are all the emails we send all notifications to
|
|
714
735
|
def emails
|
|
715
736
|
([purchased_by.try(:email)] + [email] + [user.try(:email)] + Array(organization.try(:billing_emails))).map(&:presence).compact.uniq
|
|
@@ -30,14 +30,14 @@ module Effective
|
|
|
30
30
|
country = country_code
|
|
31
31
|
state = state_code
|
|
32
32
|
|
|
33
|
-
if order.present?
|
|
34
|
-
country ||= order.billing_address.country_code
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
state ||= order.user.billing_address.state_code
|
|
33
|
+
if order.present?
|
|
34
|
+
country ||= order.billing_address.try(:country_code)
|
|
35
|
+
country ||= order.organization.try(:billing_address).try(:country_code)
|
|
36
|
+
country ||= order.user.try(:billing_address).try(:country_code)
|
|
37
|
+
|
|
38
|
+
state ||= order.billing_address.try(:state_code)
|
|
39
|
+
state ||= order.organization.try(:billing_address).try(:state_code)
|
|
40
|
+
state ||= order.user.try(:billing_address).try(:state_code)
|
|
41
41
|
end
|
|
42
42
|
|
|
43
43
|
rate = RATES[country]
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
= dropdown(variation: :dropleft) do
|
|
2
|
-
|
|
2
|
+
- if EffectiveResources.authorized?(controller, :checkout, order)
|
|
3
|
+
= dropdown_link_to 'Checkout', effective_orders.order_path(order)
|
|
4
|
+
- else
|
|
5
|
+
= dropdown_link_to 'View', effective_orders.order_path(order)
|
|
3
6
|
|
|
4
7
|
- if EffectiveResources.authorized?(controller, :send_buyer_receipt, order)
|
|
5
8
|
= dropdown_link_to 'E-mail Receipt', effective_orders.send_buyer_receipt_order_path(order),
|
data/config/routes.rb
CHANGED
data/lib/effective_orders.rb
CHANGED
|
@@ -4,22 +4,6 @@ require 'effective_orders/engine'
|
|
|
4
4
|
require 'effective_orders/version'
|
|
5
5
|
|
|
6
6
|
module EffectiveOrders
|
|
7
|
-
# Order states
|
|
8
|
-
PENDING = 'pending' # New orders are created in a pending state
|
|
9
|
-
CONFIRMED = 'confirmed' # Once the order has passed checkout step 1
|
|
10
|
-
DEFERRED = 'deferred' # Deferred providers. cheque, etransfer or phone was selected.
|
|
11
|
-
PURCHASED = 'purchased' # Purchased by provider
|
|
12
|
-
DECLINED = 'declined' # Declined by provider
|
|
13
|
-
ABANDONED = 'abandoned' # Not set by this gem. Can be set outside it.
|
|
14
|
-
|
|
15
|
-
STATES = {
|
|
16
|
-
PENDING => PENDING,
|
|
17
|
-
CONFIRMED => CONFIRMED,
|
|
18
|
-
DEFERRED => DEFERRED,
|
|
19
|
-
PURCHASED => PURCHASED,
|
|
20
|
-
DECLINED => DECLINED,
|
|
21
|
-
ABANDONED => ABANDONED
|
|
22
|
-
}
|
|
23
7
|
|
|
24
8
|
# Subscription statuses (as per stripe)
|
|
25
9
|
ACTIVE = 'active'
|
|
@@ -238,7 +222,7 @@ module EffectiveOrders
|
|
|
238
222
|
|
|
239
223
|
plans = begin
|
|
240
224
|
Stripe::Plan.respond_to?(:all) ? Stripe::Plan.all : Stripe::Plan.list
|
|
241
|
-
rescue => e
|
|
225
|
+
rescue Exception => e
|
|
242
226
|
raise e if Rails.env.production?
|
|
243
227
|
Rails.logger.info "[STRIPE ERROR]: #{e.message}"
|
|
244
228
|
Rails.logger.info "[STRIPE ERROR]: effective_orders continuing with empty stripe plans. This would fail loudly in Rails.env.production."
|
|
@@ -310,8 +294,4 @@ module EffectiveOrders
|
|
|
310
294
|
|
|
311
295
|
class SoldOutException < Exception; end
|
|
312
296
|
|
|
313
|
-
def self.gem_path
|
|
314
|
-
__dir__.chomp('/lib')
|
|
315
|
-
end
|
|
316
|
-
|
|
317
297
|
end
|
|
@@ -62,7 +62,7 @@ class EffectiveOrdersMailerPreview < ActionMailer::Preview
|
|
|
62
62
|
order.user = preview_user
|
|
63
63
|
preview_order_items.each { |atts| order.order_items.build(atts) }
|
|
64
64
|
|
|
65
|
-
order.
|
|
65
|
+
order.status = :purchased
|
|
66
66
|
order.payment_card = 'visa'
|
|
67
67
|
order.purchased_at = Time.zone.now
|
|
68
68
|
order.payment = { 'f4l4' => '1234'}
|
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.
|
|
4
|
+
version: 6.7.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: 2023-08-
|
|
11
|
+
date: 2023-08-14 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rails
|