effective_orders 6.6.3 → 6.7.1

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: 02717fdbe9f5c91a4c6331982a1af5dd676fc06ababd575d0df0d8d80d2c5849
4
- data.tar.gz: de81310a27bedc63d827cc0aaaff6073afa5c634136bceabe2ad7e286964b8c3
3
+ metadata.gz: 7459a763eab11675ddfe273af19f563ed661cf01919c7f16cded64d8e8b34d90
4
+ data.tar.gz: 4154b76b4bc53fb2b3e2061d37f87359550b9a73481727d169f828a2e892e09b
5
5
  SHA512:
6
- metadata.gz: 8792b83fbfc309b9c351665c8f4a3cf34e3d87014c27465c8211d98ae7e1623b16a34cdea8199fab78647b060e75e38f53b89189d955317188e9a630543015d7
7
- data.tar.gz: a514c76ef7b8ccba74b3ae81bb2da0a9534193044471811d2a09a9ca65b93d6caa86aa57e27cf90f05041b9a6ef9e591b9f6a224c63b5455e4ca3db60bc1d077
6
+ metadata.gz: 5e27bf43b30612c9867729ebb1c3b49c72df4141d8798e4a068c6aa22392affd0577fde516aba1abd184ef99e8ebb93554716bd63cf67f3734bd5a2b4fb569d7
7
+ data.tar.gz: ad8507d5fe1c7e497edac91d2b00869a40e48e70e979a10c14ceddbbb7280fca1994a7ab3b9c4e0338a59d43529b74b09a6464002d4571369e0725a23a99b809
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2021 Code and Effect Inc.
1
+ Copyright 2023 Code and Effect Inc.
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
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, state: 'purchased'
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, :update, current_cart)
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, :update, current_cart)
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: @order.user).destroy_all if @order.user.present?
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
@@ -24,6 +24,8 @@ class EffectiveOrdersDatatable < Effective::Datatable
24
24
 
25
25
  col :parent, visible: false, search: :string
26
26
 
27
+ col :status
28
+
27
29
  unless attributes[:not_purchased]
28
30
  col :purchased_at do |order|
29
31
  order.purchased_at&.strftime('%F %H:%M') || 'not purchased'
@@ -50,7 +50,7 @@ module EffectiveStripeHelper
50
50
 
51
51
  begin
52
52
  stripe_payment_intent_payload(order, customer)
53
- rescue => e
53
+ rescue Exception => e
54
54
  raise unless Rails.env.development?
55
55
  stripe_payment_intent_payload(order, Effective::Customer.new(user: order.user))
56
56
  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(state: EffectiveOrders::PURCHASED).order(:purchased_at) },
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(state: EffectiveOrders::DEFERRED).order(:created_at) },
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
- # scope :purchased, -> { joins(order_items: :order).where(orders: {state: EffectiveOrders::PURCHASED}).distinct }
56
- # scope :not_purchased, -> { where('id NOT IN (?)', purchased.pluck(:id).presence || [0]) }
57
- scope :purchased_by, lambda { |user| joins(order_items: :order).where(orders: { user_id: user.try(:id), state: EffectiveOrders::PURCHASED }).distinct }
58
- scope :not_purchased_by, lambda { |user| where('id NOT IN (?)', purchased_by(user).pluck(:id).presence || [0]) }
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.user_id == user.id }
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 state
2
- # - when it's in the pending state, none of the buyer entered information is required
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 state
8
- # After Step2, we are in the purchased or declined state
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
- acts_as_addressable(billing: { singular: true }, shipping: { singular: true })
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
- state :string
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(state: EffectiveOrders::PURCHASED) }
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 :pending, -> { where(state: EffectiveOrders::PENDING) }
91
- scope :confirmed, -> { where(state: EffectiveOrders::CONFIRMED) }
92
- scope :deferred, -> { where(state: EffectiveOrders::DEFERRED) }
93
- scope :declined, -> { where(state: EffectiveOrders::DECLINED) }
94
- scope :abandoned, -> { where(state: EffectiveOrders::ABANDONED) }
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
- self.state ||= EffectiveOrders::PENDING
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: -> { was_purchased? }) do
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(state: EffectiveOrders::PENDING) # Initialize with state: PENDING
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 (state != EffectiveOrders::PURCHASED)
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
- self.state = EffectiveOrders::PENDING
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
- update!(state: EffectiveOrders::CONFIRMED)
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
- self.state = EffectiveOrders::CONFIRMED
588
+ assign_attributes(status: :confirmed)
583
589
  return true if valid?
584
590
 
585
591
  self.errors.clear
586
- self.state = EffectiveOrders::PENDING
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(state: EffectiveOrders::DEFERRED, payment_provider: provider)
672
- save!
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
- state: EffectiveOrders::DECLINED,
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.state = state_was
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? && order.billing_address.present?
34
- country ||= order.billing_address.country_code
35
- state ||= order.billing_address.state_code
36
- end
37
-
38
- if order.present? && order.user.respond_to?(:billing_address) && order.user.billing_address.present?
39
- country ||= order.user.billing_address.country_code
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
- = dropdown_link_to (order.purchased? ? 'View' : 'Checkout'), effective_orders.order_path(order)
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),
@@ -5,3 +5,7 @@
5
5
  %h2 #{order.label} from Example Inc.
6
6
 
7
7
  %p.text-muted= order.to_s
8
+
9
+ - if order.voided?
10
+ %p
11
+ %strong VOID
@@ -1,7 +1,7 @@
1
1
  = render 'layout' do
2
2
  %h1.effective-heading= @page_title
3
3
 
4
- - if !@order.purchased? && EffectiveResources.authorized?(self, :update, @order)
4
+ - if EffectiveResources.authorized?(self, :checkout, @order)
5
5
  = render_checkout(@order)
6
6
  - else
7
7
  = render(@order)
data/config/routes.rb CHANGED
@@ -51,6 +51,9 @@ EffectiveOrders::Engine.routes.draw do
51
51
  post :send_payment_request
52
52
  post :send_buyer_receipt
53
53
 
54
+ post :void
55
+ post :unvoid
56
+
54
57
  # GET should be last here
55
58
  post :checkout
56
59
  patch :checkout
@@ -10,7 +10,9 @@ class CreateEffectiveOrders < ActiveRecord::Migration[4.2]
10
10
  t.integer :parent_id
11
11
  t.string :parent_type
12
12
 
13
- t.string :state
13
+ t.string :status
14
+ t.text :status_steps
15
+
14
16
  t.datetime :purchased_at
15
17
 
16
18
  t.integer :purchased_by_id
@@ -1,3 +1,3 @@
1
1
  module EffectiveOrders
2
- VERSION = '6.6.3'.freeze
2
+ VERSION = '6.7.1'.freeze
3
3
  end
@@ -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.state = 'purchased'
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.6.3
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-03 00:00:00.000000000 Z
11
+ date: 2023-08-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails