effective_orders 4.3.2 → 4.4.0
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/app/controllers/effective/concerns/purchase.rb +6 -6
- data/app/controllers/effective/orders_controller.rb +1 -1
- data/app/controllers/effective/providers/free.rb +3 -3
- data/app/controllers/effective/providers/refund.rb +8 -14
- data/app/helpers/effective_orders_helper.rb +1 -1
- data/app/mailers/effective/orders_mailer.rb +10 -0
- data/app/models/effective/order.rb +6 -1
- data/app/views/effective/orders/_checkout_step2.html.haml +3 -6
- data/app/views/effective/orders/free/_form.html.haml +3 -3
- data/app/views/effective/orders/refund/_form.html.haml +4 -25
- data/app/views/effective/orders_mailer/refund_notification_to_admin.html.haml +15 -0
- data/config/effective_orders.rb +13 -6
- data/config/routes.rb +1 -1
- data/lib/effective_orders.rb +5 -4
- data/lib/effective_orders/engine.rb +8 -0
- data/lib/effective_orders/version.rb +1 -1
- metadata +2 -2
- data/app/models/effective/providers/stripe_charge.rb +0 -24
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a3c5dc28f41342a9aaa1a3bb051ffba863a967ad6ffc29f4b7e314b699a8a840
|
4
|
+
data.tar.gz: a79cb8afd1238efee7e12fd2817900e6f68244bd420b5d0fa0a41d4bad634193
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 86af0e572fc9e7dbfec253786dd984f342bd926e5b4ecf5edc7ed7cc90a29478c8de6ee353c936aa0b87c9602cdbb99e136f53ed28da3a3818e260c7293f2e12
|
7
|
+
data.tar.gz: 2cafc367de7ffaedd679581bc969e3a98637ce4125ad3641b52c721743ef0b89a2c3abedd3fa31a73173cea2b04727d2bdcc866ac7c29eed63e56d06588b8248
|
@@ -11,12 +11,12 @@ module Effective
|
|
11
11
|
|
12
12
|
Effective::Cart.where(user_id: @order.user_id).destroy_all
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
14
|
+
unless flash[:success]
|
15
|
+
if EffectiveOrders.mailer[:send_order_receipt_to_buyer] && email
|
16
|
+
flash[:success] = "Payment successful! A receipt has been sent to #{@order.user.email}"
|
17
|
+
else
|
18
|
+
flash[:success] = "Payment successful! An email receipt has not been sent."
|
19
|
+
end
|
20
20
|
end
|
21
21
|
|
22
22
|
redirect_to (purchased_url.presence || effective_orders.purchased_order_path(':id')).gsub(':id', @order.to_param.to_s)
|
@@ -8,7 +8,7 @@ module Effective
|
|
8
8
|
include Providers::Moneris if EffectiveOrders.moneris?
|
9
9
|
include Providers::Paypal if EffectiveOrders.paypal?
|
10
10
|
include Providers::Pretend if EffectiveOrders.pretend?
|
11
|
-
include Providers::Refund if EffectiveOrders.
|
11
|
+
include Providers::Refund if EffectiveOrders.refund?
|
12
12
|
include Providers::Stripe if EffectiveOrders.stripe?
|
13
13
|
|
14
14
|
layout (EffectiveOrders.layout.kind_of?(Hash) ? EffectiveOrders.layout[:orders] : EffectiveOrders.layout)
|
@@ -18,14 +18,14 @@ module Effective
|
|
18
18
|
payment: 'free order. no payment required.',
|
19
19
|
provider: 'free',
|
20
20
|
card: 'none',
|
21
|
-
purchased_url:
|
22
|
-
declined_url:
|
21
|
+
purchased_url: free_params[:purchased_url],
|
22
|
+
declined_url: free_params[:declined_url],
|
23
23
|
email: false
|
24
24
|
)
|
25
25
|
end
|
26
26
|
|
27
27
|
def free_params
|
28
|
-
params.require(:
|
28
|
+
params.require(:free).permit(:purchased_url, :declined_url)
|
29
29
|
end
|
30
30
|
|
31
31
|
end
|
@@ -7,31 +7,25 @@ module Effective
|
|
7
7
|
@order ||= Order.find(params[:id])
|
8
8
|
|
9
9
|
EffectiveOrders.authorize!(self, :update, @order)
|
10
|
-
EffectiveOrders.authorize!(self, :admin, :effective_orders)
|
11
10
|
|
12
11
|
unless @order.refund?
|
13
|
-
flash[:danger] = 'Unable to process refund with a
|
14
|
-
redirect_to effective_orders.
|
12
|
+
flash[:danger] = 'Unable to process refund order with a positive total'
|
13
|
+
redirect_to effective_orders.order_path(@order)
|
15
14
|
return
|
16
15
|
end
|
17
16
|
|
18
|
-
|
17
|
+
flash[:success] = EffectiveOrders.refund[:success].presence
|
19
18
|
|
20
19
|
order_purchased(
|
21
|
-
payment:
|
22
|
-
provider:
|
23
|
-
|
24
|
-
|
25
|
-
skip_buyer_validations: true,
|
26
|
-
purchased_url: params[:purchased_url].presence || effective_orders.admin_order_path(@order),
|
27
|
-
declined_url: params[:declined_url].presence || effective_orders.admin_order_path(@order)
|
20
|
+
payment: 'refund. no payment required.',
|
21
|
+
provider: 'refund',
|
22
|
+
purchased_url: refund_params[:purchased_url],
|
23
|
+
declined_url: refund_params[:declined_url]
|
28
24
|
)
|
29
25
|
end
|
30
26
|
|
31
27
|
def refund_params
|
32
|
-
params.require(:
|
33
|
-
:payment, :payment_provider, :payment_card, :note_to_buyer, :send_mark_as_paid_email_to_buyer
|
34
|
-
)
|
28
|
+
params.require(:refund).permit(:purchased_url, :declined_url)
|
35
29
|
end
|
36
30
|
|
37
31
|
end
|
@@ -52,6 +52,16 @@ module Effective
|
|
52
52
|
mail(to: @order.user.email, subject: @subject)
|
53
53
|
end
|
54
54
|
|
55
|
+
# This is sent to admin when someone Accepts Refund
|
56
|
+
def refund_notification_to_admin(order_param)
|
57
|
+
@order = (order_param.kind_of?(Effective::Order) ? order_param : Effective::Order.find(order_param))
|
58
|
+
@user = @order.user
|
59
|
+
|
60
|
+
@subject = subject_for(@order, :refund_notification_to_admin, "New Refund: ##{@order.to_param}")
|
61
|
+
|
62
|
+
mail(to: EffectiveOrders.mailer[:admin_email], subject: @subject)
|
63
|
+
end
|
64
|
+
|
55
65
|
# Sent by the invoice.payment_succeeded webhook event
|
56
66
|
def subscription_payment_succeeded(customer_param)
|
57
67
|
return true unless EffectiveOrders.mailer[:send_subscription_payment_succeeded]
|
@@ -76,7 +76,7 @@ module Effective
|
|
76
76
|
validates :total, presence: true, numericality: {
|
77
77
|
greater_than_or_equal_to: EffectiveOrders.minimum_charge.to_i,
|
78
78
|
message: "must be $#{'%0.2f' % (EffectiveOrders.minimum_charge.to_i / 100.0)} or more. Please add additional items."
|
79
|
-
}, unless: -> { (free? && EffectiveOrders.free?) || (refund? && EffectiveOrders.
|
79
|
+
}, unless: -> { (free? && EffectiveOrders.free?) || (refund? && EffectiveOrders.refund?) }
|
80
80
|
end
|
81
81
|
|
82
82
|
# User validations -- An admin skips these when working in the admin/ namespace
|
@@ -343,6 +343,7 @@ module Effective
|
|
343
343
|
|
344
344
|
raise "Failed to purchase order: #{error || errors.full_messages.to_sentence}" unless error.nil?
|
345
345
|
|
346
|
+
send_refund_notification! if email && refund?
|
346
347
|
send_order_receipts! if email
|
347
348
|
|
348
349
|
run_purchasable_callbacks(:after_purchase)
|
@@ -405,6 +406,10 @@ module Effective
|
|
405
406
|
send_email(:pending_order_invoice_to_buyer, to_param) unless purchased?
|
406
407
|
end
|
407
408
|
|
409
|
+
def send_refund_notification!
|
410
|
+
send_email(:refund_notification_to_admin, to_param) if purchased? && refund?
|
411
|
+
end
|
412
|
+
|
408
413
|
def skip_qb_sync!
|
409
414
|
defined?(EffectiveQbSync) ? EffectiveQbSync.skip_order!(self) : true
|
410
415
|
end
|
@@ -10,8 +10,8 @@
|
|
10
10
|
- if EffectiveOrders.free? && order.free?
|
11
11
|
= render partial: '/effective/orders/free/form', locals: provider_locals
|
12
12
|
|
13
|
-
- elsif EffectiveOrders.
|
14
|
-
|
13
|
+
- elsif EffectiveOrders.refund? && order.refund?
|
14
|
+
= render partial: '/effective/orders/refund/form', locals: provider_locals
|
15
15
|
|
16
16
|
- else
|
17
17
|
- if EffectiveOrders.pretend? && EffectiveOrders.pretend_message.present?
|
@@ -33,10 +33,7 @@
|
|
33
33
|
= render partial: '/effective/orders/cheque/form', locals: provider_locals
|
34
34
|
|
35
35
|
- if EffectiveOrders.authorized?(controller, :admin, :effective_orders) && order.user != current_user
|
36
|
-
- if EffectiveOrders.
|
37
|
-
.effective-order-admin-purchase-actions
|
38
|
-
= render partial: '/effective/orders/refund/form', locals: provider_locals
|
39
|
-
- elsif EffectiveOrders.mark_as_paid?
|
36
|
+
- if EffectiveOrders.mark_as_paid?
|
40
37
|
.effective-order-admin-purchase-actions
|
41
38
|
= render partial: '/effective/orders/mark_as_paid/form', locals: provider_locals
|
42
39
|
|
@@ -1,5 +1,5 @@
|
|
1
1
|
= effective_form_with(scope: :free, url: effective_orders.free_order_path(order), method: :post) do |f|
|
2
|
-
=
|
3
|
-
=
|
2
|
+
= f.hidden_field :purchased_url, value: purchased_url
|
3
|
+
= f.hidden_field :declined_url, value: declined_url
|
4
4
|
|
5
|
-
= f.submit order_checkout_label(:free), border: false
|
5
|
+
= f.submit order_checkout_label(:free), center: true, border: false
|
@@ -1,26 +1,5 @@
|
|
1
|
-
.
|
2
|
-
.
|
3
|
-
|
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
|
4
4
|
|
5
|
-
|
6
|
-
= hidden_field_tag(:purchased_url, purchased_url)
|
7
|
-
= hidden_field_tag(:declined_url, declined_url)
|
8
|
-
|
9
|
-
= f.select :payment_provider, EffectiveOrders.payment_providers, required: true
|
10
|
-
|
11
|
-
= f.text_field :payment_card,
|
12
|
-
label: 'Payment card type, cheque or transaction number',
|
13
|
-
placeholder: 'visa',
|
14
|
-
hint: 'Full credit card numbers should not be entered here, or anywhere.'
|
15
|
-
|
16
|
-
= f.text_area :payment,
|
17
|
-
label: 'Additional details',
|
18
|
-
input_html: { value: f.object.payment.kind_of?(Hash) ? f.object.payment[:details] : f.object.payment.presence }
|
19
|
-
|
20
|
-
= f.check_box :send_mark_as_paid_email_to_buyer,
|
21
|
-
label: 'Yes, send an refund receipt email to the buyer.',
|
22
|
-
input_html: { checked: (f.object.send_mark_as_paid_email_to_buyer.nil? ? EffectiveOrders.mailer[:send_order_receipts_when_mark_as_paid] : f.object.send_mark_as_paid_email_to_buyer?) }
|
23
|
-
|
24
|
-
= f.text_area :note_to_buyer, hint: 'This is displayed to the buyer on all order receipts.'
|
25
|
-
|
26
|
-
= f.submit order_checkout_label(:refund)
|
5
|
+
= f.submit order_checkout_label(:refund), center: true, border: false
|
@@ -0,0 +1,15 @@
|
|
1
|
+
%p.effective-orders-receipt-info A new refund has been created!
|
2
|
+
|
3
|
+
%p Please sign in to your payment processor and issue the following refund:
|
4
|
+
|
5
|
+
%p
|
6
|
+
Refund
|
7
|
+
= price_to_currency(@order.total)
|
8
|
+
to
|
9
|
+
= @order.billing_name
|
10
|
+
= @order.user.email
|
11
|
+
|
12
|
+
|
13
|
+
%p Thanks and have a great day!
|
14
|
+
|
15
|
+
= render(@order, no_order_actions: true)
|
data/config/effective_orders.rb
CHANGED
@@ -98,11 +98,6 @@ EffectiveOrders.setup do |config|
|
|
98
98
|
# This is accessed via the admin screens only. Must have can?(:admin, :effective_orders)
|
99
99
|
config.mark_as_paid_enabled = false
|
100
100
|
|
101
|
-
# Refunds
|
102
|
-
# Allow admins to create orders with a negative total
|
103
|
-
# Refunds don't perform any kind of refund action with the payment processor. This just changes the validations.
|
104
|
-
config.refunds_enabled = false
|
105
|
-
|
106
101
|
# Pretend Purchase
|
107
102
|
# Display a 'Purchase order' button on the Checkout screen allowing the user
|
108
103
|
# to purchase an Order without going through the payment processor.
|
@@ -150,6 +145,7 @@ EffectiveOrders.setup do |config|
|
|
150
145
|
subject_for_order_receipt_to_buyer: '',
|
151
146
|
subject_for_payment_request_to_buyer: '',
|
152
147
|
subject_for_pending_order_invoice_to_buyer: '',
|
148
|
+
subject_for_refund_notification_to_admin: '',
|
153
149
|
|
154
150
|
# Procs yield an Effective::Customer object
|
155
151
|
subject_for_subscription_created: '',
|
@@ -165,7 +161,7 @@ EffectiveOrders.setup do |config|
|
|
165
161
|
layout: 'effective_orders_mailer_layout',
|
166
162
|
|
167
163
|
default_from: 'info@example.com',
|
168
|
-
admin_email: 'admin@example.com',
|
164
|
+
admin_email: 'admin@example.com', # Refund notifications will also be sent here
|
169
165
|
|
170
166
|
deliver_method: nil # When nil, will use deliver_later if active_job is configured, otherwise deliver_now
|
171
167
|
}
|
@@ -228,6 +224,17 @@ EffectiveOrders.setup do |config|
|
|
228
224
|
# }
|
229
225
|
# end
|
230
226
|
|
227
|
+
|
228
|
+
# Refunds
|
229
|
+
# This does not issue a refund with the payment processor at all.
|
230
|
+
# Instead, we mark the order as purchased, create a refund object to track it, and
|
231
|
+
# send an email to notify_email with instructions to issue a refund
|
232
|
+
config.refund = false
|
233
|
+
|
234
|
+
# config.refund = {
|
235
|
+
# success: 'Thank you! Your refund will be processed in the next few business days.'
|
236
|
+
# }
|
237
|
+
|
231
238
|
# Stripe
|
232
239
|
config.stripe = false
|
233
240
|
|
data/config/routes.rb
CHANGED
@@ -10,7 +10,7 @@ EffectiveOrders::Engine.routes.draw do
|
|
10
10
|
post :mark_as_paid if EffectiveOrders.mark_as_paid?
|
11
11
|
post :pay_by_cheque if EffectiveOrders.cheque?
|
12
12
|
post :pretend if EffectiveOrders.pretend?
|
13
|
-
post :refund if EffectiveOrders.
|
13
|
+
post :refund if EffectiveOrders.refund?
|
14
14
|
post :stripe if EffectiveOrders.stripe?
|
15
15
|
end
|
16
16
|
|
data/lib/effective_orders.rb
CHANGED
@@ -54,7 +54,6 @@ module EffectiveOrders
|
|
54
54
|
# Features
|
55
55
|
mattr_accessor :free_enabled
|
56
56
|
mattr_accessor :mark_as_paid_enabled
|
57
|
-
mattr_accessor :refunds_enabled
|
58
57
|
mattr_accessor :pretend_enabled
|
59
58
|
mattr_accessor :pretend_message
|
60
59
|
|
@@ -62,6 +61,7 @@ module EffectiveOrders
|
|
62
61
|
mattr_accessor :cheque
|
63
62
|
mattr_accessor :moneris
|
64
63
|
mattr_accessor :paypal
|
64
|
+
mattr_accessor :refund
|
65
65
|
mattr_accessor :stripe
|
66
66
|
mattr_accessor :subscriptions # Stripe subscriptions
|
67
67
|
mattr_accessor :trial # Trial mode
|
@@ -121,8 +121,8 @@ module EffectiveOrders
|
|
121
121
|
pretend_enabled == true
|
122
122
|
end
|
123
123
|
|
124
|
-
def self.
|
125
|
-
|
124
|
+
def self.refund?
|
125
|
+
refund.kind_of?(Hash)
|
126
126
|
end
|
127
127
|
|
128
128
|
def self.stripe?
|
@@ -144,11 +144,12 @@ module EffectiveOrders
|
|
144
144
|
# The Effective::Order.payment_provider value must be in this collection
|
145
145
|
def self.payment_providers
|
146
146
|
[
|
147
|
-
('cheque' if cheque?),
|
147
|
+
('cheque' if cheque? || mark_as_paid?),
|
148
148
|
('free' if free?),
|
149
149
|
('moneris' if moneris?),
|
150
150
|
('paypal' if paypal?),
|
151
151
|
('pretend' if pretend?),
|
152
|
+
('refund' if refund?),
|
152
153
|
('stripe' if stripe?),
|
153
154
|
('credit card' if mark_as_paid?),
|
154
155
|
('other' if mark_as_paid?),
|
@@ -27,6 +27,14 @@ module EffectiveOrders
|
|
27
27
|
Rails.application.config.assets.precompile += ['effective_orders/*']
|
28
28
|
end
|
29
29
|
|
30
|
+
initializer 'effective_orders.refund', after: :load_config_initializers do
|
31
|
+
if EffectiveOrders.refund?
|
32
|
+
unless (EffectiveOrders.mailer[:admin_email].to_s.include?('@') rescue false)
|
33
|
+
raise("config.mailer[:admin_email] must be present when refunds enabled.")
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
30
38
|
initializer 'effective_orders.stripe', after: :load_config_initializers do
|
31
39
|
if EffectiveOrders.stripe?
|
32
40
|
begin
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: effective_orders
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Code and Effect
|
@@ -162,7 +162,6 @@ files:
|
|
162
162
|
- app/models/effective/order.rb
|
163
163
|
- app/models/effective/order_item.rb
|
164
164
|
- app/models/effective/product.rb
|
165
|
-
- app/models/effective/providers/stripe_charge.rb
|
166
165
|
- app/models/effective/sold_out_validator.rb
|
167
166
|
- app/models/effective/subscripter.rb
|
168
167
|
- app/models/effective/subscription.rb
|
@@ -225,6 +224,7 @@ files:
|
|
225
224
|
- app/views/effective/orders_mailer/order_receipt_to_buyer.html.haml
|
226
225
|
- app/views/effective/orders_mailer/payment_request_to_buyer.html.haml
|
227
226
|
- app/views/effective/orders_mailer/pending_order_invoice_to_buyer.html.haml
|
227
|
+
- app/views/effective/orders_mailer/refund_notification_to_admin.html.haml
|
228
228
|
- app/views/effective/orders_mailer/subscription_canceled.html.haml
|
229
229
|
- app/views/effective/orders_mailer/subscription_created.html.haml
|
230
230
|
- app/views/effective/orders_mailer/subscription_event_to_admin.html.haml
|
@@ -1,24 +0,0 @@
|
|
1
|
-
# This is an object for the stripe charge form
|
2
|
-
module Effective::Providers
|
3
|
-
class StripeCharge
|
4
|
-
include ActiveModel::Model
|
5
|
-
|
6
|
-
attr_accessor :effective_order_id, :order, :stripe_token # For our form
|
7
|
-
|
8
|
-
validates :effective_order_id, presence: true
|
9
|
-
validates :stripe_token, presence: true
|
10
|
-
|
11
|
-
def persisted?
|
12
|
-
false
|
13
|
-
end
|
14
|
-
|
15
|
-
def effective_order_id
|
16
|
-
@effective_order_id || (order.to_param if order)
|
17
|
-
end
|
18
|
-
|
19
|
-
def order_items
|
20
|
-
order.order_items if order
|
21
|
-
end
|
22
|
-
|
23
|
-
end
|
24
|
-
end
|