effective_orders 5.8.2 → 5.9.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: 88341609720b1eea6a41fbe9aef2556b14791e12072e195f966d17460355d26d
4
- data.tar.gz: dcb1636b46c9b788a925e36708f6d1aebb433424eaac25657773bc4e04aba6e4
3
+ metadata.gz: 460e5652f16e49b5751f29cecd6d1cd41f8b92c5d9cb10d36f8f7f863fad9ca5
4
+ data.tar.gz: d2f4c23a86b09022a38779718232ebe2b5226c5e1ca03b9286a6cf6a3504564e
5
5
  SHA512:
6
- metadata.gz: b23cfd1c483fae1ed2387ce838b8cace69bbde2c925bb97057c4e1b58836f0f50b65b2e523de335ff856295b49125c5e68ddf93f9a0eb159a2728e4dd48d8550
7
- data.tar.gz: 8db2613a663b3ed0fb929f717ba95a04470fdbbe1d836823650c6294e4d7f0021922b62a8ed0afa3a2da9dc8f35517ec4708041d40d567c16a44ac3f261b75f4
6
+ metadata.gz: cee63481230c23907ef97547657e402d566b09c0f030fb4bae984608f352ca9a7715beedf5ccc6b7cba9e0f3ef96c4f550dd55d9ca50d57d7051a3e173316143
7
+ data.tar.gz: fee709031224ca9818f454f73c7781dfb1259ec1bca86938b6f31450f3d1dddb2d71ae1521ad8fc7d026c405cac078fe5cb81ab1a6a18b7b1c309a241c2d0e2e
@@ -5,6 +5,7 @@ module Effective
5
5
 
6
6
  def refund
7
7
  raise('refund provider is not available') unless EffectiveOrders.refund?
8
+ raise('refund provider is not configured for buyer purchase') unless EffectiveOrders.buyer_purchases_refund?
8
9
 
9
10
  @order ||= Order.find(params[:id])
10
11
 
@@ -19,6 +19,8 @@ class Admin::EffectiveOrdersDatatable < Effective::Datatable
19
19
  scope :purchased
20
20
 
21
21
  scope :deferred if EffectiveOrders.deferred_providers.present?
22
+
23
+ scope :pending_refunds if EffectiveOrders.refund && !EffectiveOrders.buyer_purchases_refund?
22
24
  scope :refunds if EffectiveOrders.refund
23
25
 
24
26
  scope :not_purchased
@@ -38,7 +40,7 @@ class Admin::EffectiveOrdersDatatable < Effective::Datatable
38
40
  end
39
41
 
40
42
  col :purchased_at do |order|
41
- order.purchased_at&.strftime('%F %H:%M') || 'not purchased'
43
+ order.purchased_at&.strftime('%F %H:%M') || ('pending refund' if order.pending_refund?) || ("pending #{order.payment_provider}" if order.deferred?) || 'not purchased'
42
44
  end
43
45
 
44
46
  if attributes[:user_id].blank?
@@ -64,6 +66,7 @@ class Admin::EffectiveOrdersDatatable < Effective::Datatable
64
66
  end
65
67
 
66
68
  col :payment_method
69
+ col :payment_provider
67
70
 
68
71
  col :subtotal, as: :price, visible: false
69
72
  col :tax, as: :price, visible: false
@@ -1,3 +1,15 @@
1
+ # Acts as purchasable
2
+ # Add to your model:
3
+ # t.integer :purchased_order_id
4
+ # t.integer :price
5
+ # t.boolean :tax_exempt, default: false
6
+ # t.string :qb_item_name
7
+ # or
8
+ # add_column :resources, :purchased_order_id, :integer
9
+ # add_column :resources, :price, :integer
10
+ # add_column :resources, :tax_exempt, :boolean, default: false
11
+ # add_column :resources, :qb_item_name, :string
12
+
1
13
  module ActsAsPurchasable
2
14
  extend ActiveSupport::Concern
3
15
 
@@ -75,7 +75,9 @@ module Effective
75
75
  scope :deferred, -> { where(state: EffectiveOrders::DEFERRED) }
76
76
  scope :declined, -> { where(state: EffectiveOrders::DECLINED) }
77
77
  scope :abandoned, -> { where(state: EffectiveOrders::ABANDONED) }
78
+
78
79
  scope :refunds, -> { purchased.where('total < ?', 0) }
80
+ scope :pending_refunds, -> { not_purchased.where('total < ?', 0) }
79
81
 
80
82
  before_validation do
81
83
  self.state ||= EffectiveOrders::PENDING
@@ -445,6 +447,13 @@ module Effective
445
447
  total.to_i < 0
446
448
  end
447
449
 
450
+ def pending_refund?
451
+ return false if EffectiveOrders.buyer_purchases_refund?
452
+ return false if purchased?
453
+
454
+ refund?
455
+ end
456
+
448
457
  def num_items
449
458
  present_order_items.map { |oi| oi.quantity }.sum
450
459
  end
@@ -466,6 +475,11 @@ module Effective
466
475
  EffectiveResources.truthy?(send_payment_request_to_buyer)
467
476
  end
468
477
 
478
+ def send_refund_notification_to_admin?
479
+ return false unless refund?
480
+ EffectiveOrders.send_refund_notification_to_admin
481
+ end
482
+
469
483
  def send_mark_as_paid_email_to_buyer?
470
484
  EffectiveResources.truthy?(send_mark_as_paid_email_to_buyer)
471
485
  end
@@ -622,7 +636,7 @@ module Effective
622
636
  def send_order_receipts!
623
637
  send_order_receipt_to_admin! if send_order_receipt_to_admin?
624
638
  send_order_receipt_to_buyer! if send_order_receipt_to_buyer?
625
- send_refund_notification! if refund?
639
+ send_refund_notification! if send_refund_notification_to_admin?
626
640
  end
627
641
 
628
642
  def send_order_receipt_to_admin!
@@ -642,7 +656,7 @@ module Effective
642
656
  end
643
657
 
644
658
  def send_refund_notification!
645
- EffectiveOrders.send_email(:refund_notification_to_admin, self) if purchased? && refund?
659
+ EffectiveOrders.send_email(:refund_notification_to_admin, self) if refund?
646
660
  end
647
661
 
648
662
  protected
@@ -8,7 +8,7 @@
8
8
  = dropdown_link_to 'Email receipt to buyer', effective_orders.send_buyer_receipt_order_path(order),
9
9
  data: { method: :post, confirm: "Send receipt to #{order.emails_send_to}?" }
10
10
 
11
- - if order.pending? || order.confirmed? || order.deferred?
11
+ - if (order.pending? || order.confirmed? || order.deferred?) && !order.refund?
12
12
  = dropdown_link_to 'Email request for payment to buyer', effective_orders.send_payment_request_admin_order_path(order),
13
13
  data: { method: :post, confirm: "Send request for payment to #{order.emails_send_to}?" }
14
14
 
@@ -0,0 +1,2 @@
1
+ .effective-orders
2
+ = yield
@@ -1,3 +1,4 @@
1
- %h1.effective-admin-heading= @page_title
1
+ = render 'layout' do
2
+ %h1.effective-admin-heading= @page_title
2
3
 
3
- = render_checkout(@order, namespace: :admin, purchased_url: effective_orders.admin_order_path(@order), declined_url: effective_orders.admin_order_path(@order))
4
+ = render_checkout(@order, namespace: :admin, purchased_url: effective_orders.admin_order_path(@order), declined_url: effective_orders.admin_order_path(@order))
@@ -1,15 +1,16 @@
1
- %h1.effective-admin-heading= @page_title
1
+ = render 'layout' do
2
+ %h1.effective-admin-heading= @page_title
2
3
 
3
- - if @order.custom_order? && @order.in_progress?
4
- = render 'effective/orders/order_actions', order: @order
4
+ - if @order.custom_order? && @order.in_progress?
5
+ = render 'effective/orders/order_actions', order: @order
5
6
 
6
- .mb-4
7
- = collapse('show order') do
8
- = render 'effective/orders/order', order: @order, no_order_actions: true
7
+ .mb-4
8
+ = collapse('show order') do
9
+ = render 'effective/orders/order', order: @order, no_order_actions: true
9
10
 
10
- = render 'admin/orders/form', order: @order
11
+ = render 'admin/orders/form', order: @order
11
12
 
12
- - else
13
- - # Same as the show action
14
- = render 'effective/orders/order', order: @order
15
- = render 'admin/orders/form_note_internal', order: @order
13
+ - else
14
+ - # Same as the show action
15
+ = render 'effective/orders/order', order: @order
16
+ = render 'admin/orders/form_note_internal', order: @order
@@ -1,6 +1,7 @@
1
- %h1.effective-admin-heading= @page_title
1
+ = render 'layout' do
2
+ %h1.effective-admin-heading= @page_title
2
3
 
3
- %p.text-right.effective-admin-actions
4
- = link_to 'New Order', effective_orders.new_admin_order_path, class: 'btn btn-primary'
4
+ %p.text-right.effective-admin-actions
5
+ = link_to 'New Order', effective_orders.new_admin_order_path, class: 'btn btn-primary'
5
6
 
6
- = render_datatable @datatable
7
+ = render_datatable @datatable
@@ -1,3 +1,4 @@
1
- %h1.effective-admin-heading= @page_title
1
+ = render 'layout' do
2
+ %h1.effective-admin-heading= @page_title
2
3
 
3
- = render 'admin/orders/form', order: @order
4
+ = render 'admin/orders/form', order: @order
@@ -1,4 +1,5 @@
1
- %h1.effective-admin-heading= @page_title
1
+ = render 'layout' do
2
+ %h1.effective-admin-heading= @page_title
2
3
 
3
- = render 'effective/orders/order', order: @order
4
- = render 'admin/orders/form_note_internal', order: @order
4
+ = render 'effective/orders/order', order: @order
5
+ = render 'admin/orders/form_note_internal', order: @order
@@ -0,0 +1,2 @@
1
+ .effective-orders
2
+ = yield
@@ -15,9 +15,10 @@
15
15
  - if params[:action] == 'edit'
16
16
  = link_to('Show', effective_orders.admin_order_path(order), class: 'btn btn-primary')
17
17
 
18
- = link_to 'Email request for payment to buyer', effective_orders.send_payment_request_admin_order_path(order),
19
- class: 'btn btn-secondary',
20
- data: { method: :post, confirm: "Send request for payment to #{order.emails_send_to}?" }
18
+ - unless order.refund?
19
+ = link_to 'Email request for payment to buyer', effective_orders.send_payment_request_admin_order_path(order),
20
+ class: 'btn btn-secondary',
21
+ data: { method: :post, confirm: "Send request for payment to #{order.emails_send_to}?" }
21
22
 
22
23
  = link_to 'Delete', effective_orders.admin_order_path(order),
23
24
  class: 'btn btn-danger',
@@ -1,10 +1,11 @@
1
- %h1.effective-heading= @page_title
1
+ = render 'layout' do
2
+ %h1.effective-heading= @page_title
2
3
 
3
- %p.effective-orders-page-content
4
- - if current_cart.present?
5
- Your #{link_to_current_cart(label: 'Cart')} items have been saved. Please try again.
6
- - else
7
- Please try again.
4
+ %p.effective-orders-page-content
5
+ - if current_cart.present?
6
+ Your #{link_to_current_cart(label: 'Cart')} items have been saved. Please try again.
7
+ - else
8
+ Please try again.
8
9
 
9
- %p.text-center
10
- = link_to 'Continue', root_path, class: 'btn btn-primary'
10
+ %p.text-center
11
+ = link_to 'Continue', root_path, class: 'btn btn-primary'
@@ -1,11 +1,12 @@
1
- %h1.effective-heading= @page_title
1
+ = render 'layout' do
2
+ %h1.effective-heading= @page_title
2
3
 
3
- %p.effective-orders-page-content
4
- You have indicated that this order will be paid by #{@order.payment_provider}.
5
- Your order will not be considered purchased until we receive your payment.
6
- Please contact us at your earliest convenience.
4
+ %p.effective-orders-page-content
5
+ You have indicated that this order will be paid by #{@order.payment_provider}.
6
+ Your order will not be considered purchased until we receive your payment.
7
+ Please contact us at your earliest convenience.
7
8
 
8
- = render @order
9
+ = render @order
9
10
 
10
- %p.text-center
11
- = link_to 'Continue', root_path, class: 'btn btn-primary'
11
+ %p.text-center
12
+ = link_to 'Continue', root_path, class: 'btn btn-primary'
@@ -1,3 +1,4 @@
1
- %h1.effective-heading= @page_title
1
+ = render 'layout' do
2
+ %h1.effective-heading= @page_title
2
3
 
3
- = render_checkout_step1(@order)
4
+ = render_checkout_step1(@order)
@@ -1,3 +1,4 @@
1
- %h1.effective-heading= @page_title
1
+ = render 'layout' do
2
+ %h1.effective-heading= @page_title
2
3
 
3
- = render_datatable(@datatable)
4
+ = render_datatable(@datatable)
@@ -13,7 +13,7 @@
13
13
  label: 'Payment card type, cheque, e-transfer or transaction number',
14
14
  hint: 'Do not enter credit card numbers here, or anywhere.'
15
15
 
16
- = f.datetime_field :purchased_at
16
+ = f.datetime_field :purchased_at, label: 'Purchased or completed'
17
17
 
18
18
  = f.check_box :send_mark_as_paid_email_to_buyer,
19
19
  label: 'Yes, send a receipt email to the buyer.',
@@ -25,4 +25,5 @@
25
25
  .col
26
26
  = f.text_area :note_internal, hint: 'For or internal admin use only. This note will never be displayed to the buyer.'
27
27
 
28
- = f.submit order_checkout_label(order.refund? ? :refund : :mark_as_paid)
28
+ = f.submit(center: true) do
29
+ = f.save(order.refund? ? 'Complete Refund' : 'Mark as Paid')
@@ -1,3 +1,4 @@
1
- %h1.effective-heading= @page_title
1
+ = render 'layout' do
2
+ %h1.effective-heading= @page_title
2
3
 
3
- = render_checkout_step1(@order)
4
+ = render_checkout_step1(@order)
@@ -1,9 +1,10 @@
1
- %h1.effective-heading= @page_title
1
+ = render 'layout' do
2
+ %h1.effective-heading= @page_title
2
3
 
3
- %p.effective-orders-page-content
4
- You have successfully purchased the following:
4
+ %p.effective-orders-page-content
5
+ You have successfully purchased the following:
5
6
 
6
- = render @order
7
+ = render @order
7
8
 
8
- %p.text-center
9
- = link_to 'Continue', root_path, class: 'btn btn-primary'
9
+ %p.text-center
10
+ = link_to 'Continue', root_path, class: 'btn btn-primary'
@@ -1,5 +1,10 @@
1
- = effective_form_with(scope: :refund, url: effective_orders.refund_order_path(order), method: :post) do |f|
2
- = f.hidden_field :purchased_url, value: purchased_url
3
- = f.hidden_field :declined_url, value: declined_url
1
+ - if EffectiveOrders.buyer_purchases_refund?
2
+ = effective_form_with(scope: :refund, url: effective_orders.refund_order_path(order), method: :post) do |f|
3
+ = f.hidden_field :purchased_url, value: purchased_url
4
+ = f.hidden_field :declined_url, value: declined_url
4
5
 
5
- = f.submit order_checkout_label(:refund), center: true, border: false
6
+ = f.submit order_checkout_label(:refund), center: true, border: false
7
+
8
+ - else
9
+ .text-center
10
+ = EffectiveOrders.refund[:pending].presence || 'Refund pending'
@@ -1,9 +1,10 @@
1
- %h1.effective-heading= @page_title
1
+ = render 'layout' do
2
+ %h1.effective-heading= @page_title
2
3
 
3
- - if !@order.purchased? && @order.user == current_user
4
- = render_checkout(@order)
5
- - else
6
- = render(@order)
4
+ - if !@order.purchased? && @order.user == current_user
5
+ = render_checkout(@order)
6
+ - else
7
+ = render(@order)
7
8
 
8
- %p.text-center
9
- = link_to 'Continue', effective_orders.orders_path, class: 'btn btn-primary'
9
+ %p.text-center
10
+ = link_to 'Continue', effective_orders.orders_path, class: 'btn btn-primary'
@@ -95,6 +95,8 @@ EffectiveOrders.setup do |config|
95
95
  config.send_payment_request_to_buyer = true
96
96
  config.send_pending_order_invoice_to_buyer = true
97
97
 
98
+ config.send_refund_notification_to_admin = true
99
+
98
100
  config.send_order_receipts_when_mark_as_paid = true
99
101
  config.send_order_receipts_when_free = true
100
102
 
@@ -201,17 +203,33 @@ EffectiveOrders.setup do |config|
201
203
  # success: 'Thank you! You have indicated that this order will be purchased by phone. Please give us a call at your earliest convenience.'
202
204
  # }
203
205
 
204
-
205
206
  # Refunds
206
207
  # This does not issue a refund with the payment processor at all.
207
- # Instead, we mark the order as purchased, create a refund object to track it, and
208
- # send an email to config.mailer_admin with instructions to issue a refund
208
+ #
209
+ # The historic way of doing refunds was the user would click Accept Refund
210
+ # Which marks the order as purchased and sends an admin the notification to issue a refund with processor
211
+ # To support this, set:
212
+ # config.buyer_purchases_refund = true
213
+ # config.send_refund_notification_to_admin = true
214
+ #
215
+ # The newer way of doing refunds is driven by the admin
216
+ # The user just sees a pending refund and cannot purchase the order
217
+ # The admin does the refund with processor, then uses Admin: Mark as Paid to mark order as purchased thereby completing the refund
218
+ # To support this, set:
219
+ # config.buyer_purchases_refund = false
220
+ # config.send_refund_notification_to_admin = false
221
+ #
222
+ # You can call order.send_refund_notification! directly or implement a better one in your app
209
223
  config.refund = false
210
224
 
211
225
  # config.refund = {
212
- # success: 'Thank you! Your refund will be processed in the next few business days.'
226
+ # success: 'Thank you! Your refund will be processed in the next few business days.',
227
+ # pending: 'Thank you! Your refund will be processed in the next few business days.'
213
228
  # }
214
229
 
230
+ config.buyer_purchases_refund = true
231
+ config.send_refund_notification_to_admin = true # On Purchase
232
+
215
233
  # Stripe
216
234
  config.stripe = false
217
235
 
@@ -1,3 +1,3 @@
1
1
  module EffectiveOrders
2
- VERSION = '5.8.2'.freeze
2
+ VERSION = '5.9.1'.freeze
3
3
  end
@@ -48,9 +48,10 @@ module EffectiveOrders
48
48
  :send_order_receipts_when_mark_as_paid, :send_order_receipts_when_free,
49
49
  :send_subscription_events,
50
50
  :send_subscription_trialing, :send_subscription_trial_expired,
51
+ :send_refund_notification_to_admin,
51
52
 
52
53
  # Features
53
- :free_enabled, :mark_as_paid_enabled, :pretend_enabled, :pretend_message,
54
+ :free_enabled, :mark_as_paid_enabled, :pretend_enabled, :pretend_message, :buyer_purchases_refund,
54
55
 
55
56
  # Payment processors. false or Hash
56
57
  :cheque, :etransfer, :moneris, :moneris_checkout, :paypal, :phone, :refund, :stripe, :subscriptions, :trial
@@ -112,6 +113,10 @@ module EffectiveOrders
112
113
  refund.kind_of?(Hash)
113
114
  end
114
115
 
116
+ def self.buyer_purchases_refund?
117
+ buyer_purchases_refund == true
118
+ end
119
+
115
120
  def self.stripe?
116
121
  stripe.kind_of?(Hash)
117
122
  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: 5.8.2
4
+ version: 5.9.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: 2022-10-05 00:00:00.000000000 Z
11
+ date: 2022-11-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -236,6 +236,7 @@ files:
236
236
  - app/views/admin/orders/_datatable_actions.html.haml
237
237
  - app/views/admin/orders/_form.html.haml
238
238
  - app/views/admin/orders/_form_note_internal.html.haml
239
+ - app/views/admin/orders/_layout.html.haml
239
240
  - app/views/admin/orders/_order_actions.html.haml
240
241
  - app/views/admin/orders/_order_item_fields.html.haml
241
242
  - app/views/admin/orders/checkout.html.haml
@@ -257,6 +258,7 @@ files:
257
258
  - app/views/effective/orders/_fields.html.haml
258
259
  - app/views/effective/orders/_fields_note.html.haml
259
260
  - app/views/effective/orders/_fields_terms.html.haml
261
+ - app/views/effective/orders/_layout.html.haml
260
262
  - app/views/effective/orders/_order.html.haml
261
263
  - app/views/effective/orders/_order_actions.html.haml
262
264
  - app/views/effective/orders/_order_deferred.html.haml