effective_orders 5.3.2 → 5.4.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: 0ff21e266d5908efc6a31250b6b265879e0e6c2330f598bd673fee6058f54b3d
4
- data.tar.gz: c20fba9f6371012d5895bf17555ef003d88c57d19ba0a8e0b5e087d69b8eab0e
3
+ metadata.gz: 2781d889611f7bc0c7f5c09002b62ae45ad2ac4d271cd8f641cef63e1692fcc4
4
+ data.tar.gz: 5f8584ed6065c4caecec5b3699e9bbcd0c54c3a50fce1820bd7c10ef41c3cca9
5
5
  SHA512:
6
- metadata.gz: 11dfee0b764d2b93259b0cde740ecc9fcd39b2f80d0c5dc5795ea76919ed27528fbeb69f2a84d99fc27cfe09feeab2d07bc9b809e804ce3e19abba210f51a42b
7
- data.tar.gz: 05a83379f89294bf22f3c6010f944b62a4839e8129e14b6f8a81226a8315e555731afd76963a8cb0bbbe4ac9a3725dd9e46ce3d742fe84eddd993f254947e160
6
+ metadata.gz: f14479b485a00ad66b28544d2123d8fa504c6abef82669df4b91d844cf25163b29e8bc38b3ad9d468c0514833f7b68c9d4b5be9263d3df3b40c3c94ec7b0a376
7
+ data.tar.gz: d88561b37c3ffa64ecc3a79a20084dcbbb08bc0304d7213717fd06d0dcfa7f43bc6b480c3a36e164c45d9c6637e068a1069d7af6eb941f7319d434cf45c6071d
data/README.md CHANGED
@@ -407,9 +407,9 @@ The payment processor handles collecting the Credit Card number, and through one
407
407
 
408
408
  Once the order has been marked purchased, the user is redirected to the `effective_orders.purchased_order_path` screen where they see a 'Thank You!' message, and the Order receipt.
409
409
 
410
- If the configuration option `config.mailer[:send_order_receipt_to_buyer] == true` the order receipt will be emailed to the user.
410
+ If the configuration option `config.send_order_receipt_to_buyer == true` the order receipt will be emailed to the user.
411
411
 
412
- As well, if the configuration option `config.mailer[:send_order_receipt_to_admin] == true` the order receipt will be emailed to the site admin.
412
+ As well, if the configuration option `config.send_order_receipt_to_admin == true` the order receipt will be emailed to the site admin.
413
413
 
414
414
  The Order has now been purchased.
415
415
 
@@ -427,7 +427,7 @@ If you are using effective_orders to roll your own custom payment workflow, you
427
427
 
428
428
  #### Send Order Receipts in the Background
429
429
 
430
- Emails will be sent immediately unless `config.mailer[:deliver_method] == :deliver_later`.
430
+ Emails will be sent immediately unless `config.deliver_method == :deliver_later`.
431
431
 
432
432
  ### Effective::Order Model
433
433
 
@@ -89,18 +89,11 @@ module Effective
89
89
  end
90
90
  end
91
91
 
92
- def send_email(email, *args)
93
- raise('expected args to be an Array') unless args.kind_of?(Array)
92
+ def send_email(email, customer)
93
+ return unless EffectiveOrders.send_subscription_events
94
94
 
95
- if defined?(Tenant)
96
- tenant = Tenant.current || raise('expected a current tenant')
97
- args << { tenant: tenant }
98
- end
99
-
100
- deliver_method = EffectiveOrders.mailer[:deliver_method] || EffectiveResources.deliver_method
101
-
102
- EffectiveOrders.mailer_klass.send(email, *args).send(deliver_method)
103
- EffectiveOrders.mailer_klass.send(:subscription_event_to_admin, email.to_s, *args).send(deliver_method)
95
+ EffectiveOrders.send_email(email, customer)
96
+ EffectiveOrders.send_email(:subscription_event_to_admin, email.to_s, customer)
104
97
  end
105
98
 
106
99
  def run_subscribable_buyer_callbacks!
@@ -1,232 +1,169 @@
1
1
  module Effective
2
- class OrdersMailer < ActionMailer::Base
3
- default from: -> { EffectiveOrders.mailer[:default_from].presence }
4
- default cc: -> { EffectiveOrders.mailer[:default_cc].presence }
5
- default bcc: -> { EffectiveOrders.mailer[:default_bcc].presence }
6
- layout -> { EffectiveOrders.mailer[:layout].presence || 'effective_orders_mailer_layout' }
2
+ class OrdersMailer < EffectiveOrders.parent_mailer_class
3
+ include EffectiveMailer
7
4
 
8
5
  helper EffectiveOrdersHelper
9
6
 
10
- def order_receipt_to_admin(order_param, atts = {})
11
- around_mail_action(:order_receipt_to_admin, order_param, atts) do
12
- return true unless EffectiveOrders.mailer[:send_order_receipt_to_admin]
7
+ def order_receipt_to_admin(resource, opts = {})
8
+ raise('expected an Effective::Order') unless resource.kind_of?(Effective::Order)
13
9
 
14
- @order = (order_param.kind_of?(Effective::Order) ? order_param : Effective::Order.find(order_param))
15
- @user = @order.user
10
+ @order = resource
11
+ subject = subject_for(__method__, "Order Receipt: ##{@order.to_param}", resource, opts)
12
+ headers = headers_for(resource, opts)
16
13
 
17
- @subject = subject_for(@order, :order_receipt_to_admin, "Order Receipt: ##{@order.to_param}")
18
-
19
- mail(to: EffectiveOrders.mailer[:admin_email], subject: @subject)
20
- end
14
+ mail(to: mailer_admin, subject: subject, **headers)
21
15
  end
22
16
 
23
- def order_receipt_to_buyer(order_param, atts = {}) # Buyer
24
- around_mail_action(:order_receipt_to_buyer, order_param, atts) do
25
- return true unless EffectiveOrders.mailer[:send_order_receipt_to_buyer]
26
-
27
- @order = (order_param.kind_of?(Effective::Order) ? order_param : Effective::Order.find(order_param))
28
- @user = @order.user
17
+ def order_receipt_to_buyer(resource, opts = {})
18
+ raise('expected an Effective::Order') unless resource.kind_of?(Effective::Order)
29
19
 
30
- @subject = subject_for(@order, :order_receipt_to_buyer, "Order Receipt: ##{@order.to_param}")
20
+ @order = resource
21
+ subject = subject_for(__method__, "Order Receipt: ##{@order.to_param}", resource, opts)
22
+ headers = headers_for(resource, opts)
31
23
 
32
- mail({to: @order.email, cc: @order.cc, subject: @subject}.compact)
33
- end
24
+ mail(to: @order.email, cc: @order.cc.presence, subject: subject, **headers)
34
25
  end
35
26
 
36
27
  # This is sent when an admin creates a new order or /admin/orders/new
37
28
  # Or when Pay by Cheque or Pay by Phone (deferred payments)
38
29
  # Or uses the order action Send Payment Request
39
- def payment_request_to_buyer(order_param, atts = {})
40
- around_mail_action(:payment_request_to_buyer, order_param, atts) do
41
- return true unless EffectiveOrders.mailer[:send_payment_request_to_buyer]
42
-
43
- @order = (order_param.kind_of?(Effective::Order) ? order_param : Effective::Order.find(order_param))
44
- @user = @order.user
30
+ def payment_request_to_buyer(resource, opts = {})
31
+ raise('expected an Effective::Order') unless resource.kind_of?(Effective::Order)
45
32
 
46
- @subject = subject_for(@order, :payment_request_to_buyer, "Payment request - Order ##{@order.to_param}")
33
+ @order = resource
34
+ subject = subject_for(__method__, "Payment request - Order ##{@order.to_param}", resource, opts)
35
+ headers = headers_for(resource, opts)
47
36
 
48
- mail({to: @order.email, cc: @order.cc, subject: @subject}.compact)
49
- end
37
+ mail(to: @order.email, cc: @order.cc.presence, subject: subject, **headers)
50
38
  end
51
39
 
52
-
53
40
  # This is sent when someone chooses to Pay by Cheque
54
- def pending_order_invoice_to_buyer(order_param, atts = {})
55
- around_mail_action(:pending_order_invoice_to_buyer, order_param, atts) do
56
- return true unless EffectiveOrders.mailer[:send_pending_order_invoice_to_buyer]
41
+ def pending_order_invoice_to_buyer(resource, opts = {})
42
+ raise('expected an Effective::Order') unless resource.kind_of?(Effective::Order)
57
43
 
58
- @order = (order_param.kind_of?(Effective::Order) ? order_param : Effective::Order.find(order_param))
59
- @user = @order.user
44
+ @order = resource
45
+ subject = subject_for(__method__, "Pending Order: ##{@order.to_param}", resource, opts)
46
+ headers = headers_for(resource, opts)
60
47
 
61
- @subject = subject_for(@order, :pending_order_invoice_to_buyer, "Pending Order: ##{@order.to_param}")
62
-
63
- mail({to: @order.email, cc: @order.cc, subject: @subject}.compact)
64
- end
48
+ mail(to: @order.email, cc: @order.cc.presence, subject: subject, **headers)
65
49
  end
66
50
 
67
51
  # This is sent to admin when someone Accepts Refund
68
- def refund_notification_to_admin(order_param, atts = {})
69
- around_mail_action(:refund_notification_to_admin, order_param, atts) do
70
- @order = (order_param.kind_of?(Effective::Order) ? order_param : Effective::Order.find(order_param))
71
- @user = @order.user
52
+ def refund_notification_to_admin(order, opts = {})
53
+ raise('expected an Effective::Order') unless resource.kind_of?(Effective::Order)
72
54
 
73
- @subject = subject_for(@order, :refund_notification_to_admin, "New Refund: ##{@order.to_param}")
55
+ @order = resource
56
+ subject = subject_for(__method__, "New Refund: ##{@order.to_param}", resource, opts)
57
+ headers = headers_for(resource, opts)
74
58
 
75
- mail(to: EffectiveOrders.mailer[:admin_email], subject: @subject)
76
- end
59
+ mail(to: mailer_admin, subject: subject, **headers)
77
60
  end
78
61
 
79
62
  # Sent by the invoice.payment_succeeded webhook event
80
- def subscription_payment_succeeded(customer_param, atts = {})
81
- around_mail_action(:subscription_payment_succeeded, customer_param, atts) do
82
- return true unless EffectiveOrders.mailer[:send_subscription_payment_succeeded]
83
-
84
- @customer = (customer_param.kind_of?(Effective::Customer) ? customer_param : Effective::Customer.find(customer_param))
85
- @subscriptions = @customer.subscriptions
86
- @user = @customer.user
63
+ def subscription_payment_succeeded(resource, opts = {})
64
+ raise('expected an Effective::Customer') unless resource.kind_of?(Effective::Customer)
87
65
 
88
- @subject = subject_for(@customer, :subscription_payment_succeeded, 'Thank you for your payment')
66
+ @customer = resource
67
+ subject = subject_for(__method__, 'Thank you for your payment', resource, opts)
68
+ headers = headers_for(resource, opts)
89
69
 
90
- mail(to: @customer.user.email, subject: @subject)
91
- end
70
+ mail(to: @customer.user.email, subject: subject, **headers)
92
71
  end
93
72
 
94
73
  # Sent by the invoice.payment_failed webhook event
95
- def subscription_payment_failed(customer_param, atts = {})
96
- around_mail_action(:subscription_payment_failed, customer_param, atts) do
97
- return true unless EffectiveOrders.mailer[:send_subscription_payment_failed]
98
-
99
- @customer = (customer_param.kind_of?(Effective::Customer) ? customer_param : Effective::Customer.find(customer_param))
100
- @subscriptions = @customer.subscriptions
101
- @user = @customer.user
74
+ def subscription_payment_failed(resource, opts = {})
75
+ raise('expected an Effective::Customer') unless resource.kind_of?(Effective::Customer)
102
76
 
103
- @subject = subject_for(@customer, :subscription_payment_failed, 'Payment failed - please update your card details')
77
+ @customer = resource
78
+ subject = subject_for(__method__, 'Payment failed - please update your card details', resource, opts)
79
+ headers = headers_for(resource, opts)
104
80
 
105
- mail(to: @customer.user.email, subject: @subject)
106
- end
81
+ mail(to: @customer.user.email, subject: subject, **headers)
107
82
  end
108
83
 
109
84
  # Sent by the customer.subscription.created webhook event
110
- def subscription_created(customer_param, atts = {})
111
- around_mail_action(:subscription_created, customer_param, atts) do
112
- return true unless EffectiveOrders.mailer[:send_subscription_created]
113
-
114
- @customer = (customer_param.kind_of?(Effective::Customer) ? customer_param : Effective::Customer.find(customer_param))
115
- @subscriptions = @customer.subscriptions
116
- @user = @customer.user
85
+ def subscription_created(resource, opts = {})
86
+ raise('expected an Effective::Customer') unless resource.kind_of?(Effective::Customer)
117
87
 
118
- @subject = subject_for(@customer, :subscription_created, 'New Subscription')
88
+ @customer = resource
89
+ subject = subject_for(__method__, 'New Subscription', resource, opts)
90
+ headers = headers_for(resource, opts)
119
91
 
120
- mail(to: @customer.user.email, subject: @subject)
121
- end
92
+ mail(to: @customer.user.email, subject: subject, **headers)
122
93
  end
123
94
 
124
95
  # Sent by the customer.subscription.updated webhook event
125
- def subscription_updated(customer_param, atts = {})
126
- around_mail_action(:subscription_updated, customer_param, atts) do
127
- return true unless EffectiveOrders.mailer[:send_subscription_updated]
128
-
129
- @customer = (customer_param.kind_of?(Effective::Customer) ? customer_param : Effective::Customer.find(customer_param))
130
- @subscriptions = @customer.subscriptions
131
- @user = @customer.user
96
+ def subscription_updated(resource, opts = {})
97
+ raise('expected an Effective::Customer') unless resource.kind_of?(Effective::Customer)
132
98
 
133
- @subject = subject_for(@customer, :subscription_updated, 'Subscription Changed')
99
+ @customer = resource
100
+ subject = subject_for(__method__, 'Subscription Changed', resource, opts)
101
+ headers = headers_for(resource, opts)
134
102
 
135
- mail(to: @customer.user.email, subject: @subject)
136
- end
103
+ mail(to: @customer.user.email, subject: subject, **headers)
137
104
  end
138
105
 
139
- # Sent by the invoice.payment_failed webhook event
140
- def subscription_canceled(customer_param, atts = {})
141
- around_mail_action(:subscription_canceled, customer_param, atts) do
142
- return true unless EffectiveOrders.mailer[:send_subscription_canceled]
143
-
144
- @customer = (customer_param.kind_of?(Effective::Customer) ? customer_param : Effective::Customer.find(customer_param))
145
- @subscriptions = @customer.subscriptions
146
- @user = @customer.user
106
+ # Sent by the invoice.payment_failed webhook event
107
+ def subscription_canceled(resource, opts = {})
108
+ raise('expected an Effective::Customer') unless resource.kind_of?(Effective::Customer)
147
109
 
148
- @subject = subject_for(@customer, :subscription_canceled, 'Subscription canceled')
110
+ @customer = resource
111
+ subject = subject_for(__method__, 'Subscription canceled', resource, opts)
112
+ headers = headers_for(resource, opts)
149
113
 
150
- mail(to: @customer.user.email, subject: @subject)
151
- end
114
+ mail(to: @customer.user.email, subject: subject, **headers)
152
115
  end
153
116
 
154
117
  # Sent by the effective_orders:notify_trial_users rake task.
155
- def subscription_trialing(subscribable, atts = {})
156
- around_mail_action(:subscription_trialing, subscribable, atts) do
157
- return true unless EffectiveOrders.mailer[:send_subscription_trialing]
118
+ def subscription_trialing(resource, opts = {})
119
+ raise('expected a subscribable resource') unless resource.respond_to?(:subscribable_buyer)
158
120
 
159
- @subscribable = subscribable
160
- @user = @subscribable.subscribable_buyer
121
+ @subscribable = resource
122
+ subject = subject_for(__method__, 'Trial is active', resource, opts)
123
+ headers = headers_for(resource, opts)
161
124
 
162
- @subject = subject_for(@customer, :subscription_trialing, 'Trial is active')
163
-
164
- mail(to: @subscribable.subscribable_buyer.email, subject: @subject)
165
- end
125
+ mail(to: @subscribable.subscribable_buyer.email, subject: subject, **headers)
166
126
  end
167
127
 
168
128
  # Sent by the effective_orders:notify_trial_users rake task.
169
- def subscription_trial_expired(subscribable, atts = {})
170
- around_mail_action(:subscription_trial_expired, subscribable, atts) do
171
- return true unless EffectiveOrders.mailer[:send_subscription_trial_expired]
129
+ def subscription_trial_expired(resource, opts = {})
130
+ raise('expected a subscribable resource') unless resource.respond_to?(:subscribable_buyer)
172
131
 
173
- @subscribable = subscribable
174
- @user = @subscribable.subscribable_buyer
132
+ @subscribable = resource
133
+ subject = subject_for(__method__, 'Trial expired', resource, opts)
134
+ headers = headers_for(resource, opts)
175
135
 
176
- @subject = subject_for(@customer, :subscription_trial_expired, 'Trial expired')
177
-
178
- mail(to: @subscribable.subscribable_buyer.email, subject: @subject)
179
- end
136
+ mail(to: @subscribable.subscribable_buyer.email, subject: subject, **headers)
180
137
  end
181
138
 
182
- def subscription_event_to_admin(event, customer_param, atts = {})
183
- around_mail_action(:subscription_event_to_admin, event, atts) do
184
- return true unless EffectiveOrders.mailer[:send_subscription_event_to_admin]
139
+ def subscription_event_to_admin(event, resource, opts = {})
140
+ raise('expected an event') unless event.present?
141
+ raise('expected an Effective::Customer') unless resource.kind_of?(Effective::Customer)
185
142
 
186
- @customer = (customer_param.kind_of?(Effective::Customer) ? customer_param : Effective::Customer.find(customer_param))
187
- @subscriptions = @customer.subscriptions
188
- @user = @customer.user
189
- @event = event.to_s
143
+ @event = event
144
+ @customer = resource
190
145
 
191
- @subject = subject_for(@customer, :subscription_event_to_admin, "Subscription event - @event - @customer").gsub('@event', @event.to_s).gsub('@customer', @customer.to_s)
146
+ subject = subject_for(__method__, "Subscription event - #{@event} - #{@customer}", resource, opts)
147
+ headers = headers_for(resource, opts)
192
148
 
193
- mail(to: EffectiveOrders.mailer[:admin_email], subject: @subject)
194
- end
149
+ mail(to: mailer_admin, subject: subject, **headers)
195
150
  end
196
151
 
152
+ # This is only called by EffectiveQbSync
197
153
  def order_error(order: nil, error: nil, to: nil, from: nil, subject: nil, template: 'order_error')
198
- around_mail_action(:order_error, order, {error: error, to: to, from: from, subject: subject, template: template}) do
199
- @order = (order.kind_of?(Effective::Order) ? order : Effective::Order.find(order))
200
- @error = error.to_s
201
-
202
- @subject = subject_for(@order, :error, "An error occurred with order: ##{@order.try(:to_param)}")
203
-
204
- mail(
205
- to: (to || EffectiveOrders.mailer[:admin_email]),
206
- from: (from || EffectiveOrders.mailer[:default_from]),
207
- subject: (subject || @subject)
208
- ) do |format|
209
- format.html { render(template) }
210
- end
211
- end
212
- end
213
-
214
- protected
154
+ raise('expected an Effective::Order') unless order.kind_of?(Effective::Order)
215
155
 
216
- def around_mail_action(name, param, atts = {}, &block)
217
- yield
218
- end
219
-
220
- private
156
+ @order = order
157
+ @error = error.to_s
221
158
 
222
- def subject_for(order, action, fallback)
223
- subject = EffectiveOrders.mailer["subject_for_#{action}".to_sym]
224
- prefix = EffectiveOrders.mailer[:subject_prefix].to_s
159
+ to ||= EffectiveOrders.mailer_admin
160
+ from ||= EffectiveOrders.mailer_sender
161
+ subject ||= subject_for(__method__,"An error occurred with order: ##{@order.to_param}", resource, opts)
162
+ headers = headers_for(resource, opts)
225
163
 
226
- subject = self.instance_exec(order, &subject) if subject.respond_to?(:call)
227
- subject = subject.presence || fallback
228
-
229
- prefix.present? ? (prefix.chomp(' ') + ' ' + subject) : subject
164
+ mail(to: to, from: from, subject: subject, **headers) do |format|
165
+ format.html { render(template) }
166
+ end
230
167
  end
231
168
 
232
169
  end
@@ -419,17 +419,17 @@ module Effective
419
419
  end
420
420
 
421
421
  def send_order_receipt_to_admin?
422
- return false if free? && !EffectiveOrders.mailer[:send_order_receipts_when_free]
423
- EffectiveOrders.mailer[:send_order_receipt_to_admin]
422
+ return false if free? && !EffectiveOrders.send_order_receipts_when_free
423
+ EffectiveOrders.send_order_receipt_to_admin
424
424
  end
425
425
 
426
426
  def send_order_receipt_to_buyer?
427
- return false if free? && !EffectiveOrders.mailer[:send_order_receipts_when_free]
428
- EffectiveOrders.mailer[:send_order_receipt_to_buyer]
427
+ return false if free? && !EffectiveOrders.send_order_receipts_when_free
428
+ EffectiveOrders.send_order_receipt_to_buyer
429
429
  end
430
430
 
431
431
  def send_payment_request_to_buyer?
432
- return false if free? && !EffectiveOrders.mailer[:send_order_receipts_when_free]
432
+ return false if free? && !EffectiveOrders.send_order_receipts_when_free
433
433
  return false if refund?
434
434
 
435
435
  EffectiveResources.truthy?(send_payment_request_to_buyer)
@@ -587,23 +587,23 @@ module Effective
587
587
  end
588
588
 
589
589
  def send_order_receipt_to_admin!
590
- send_email(:order_receipt_to_admin, to_param) if purchased?
590
+ EffectiveOrders.send_email(:order_receipt_to_admin, self) if purchased?
591
591
  end
592
592
 
593
593
  def send_order_receipt_to_buyer!
594
- send_email(:order_receipt_to_buyer, to_param) if purchased?
594
+ EffectiveOrders.send_email(:order_receipt_to_buyer, self) if purchased?
595
595
  end
596
596
 
597
597
  def send_payment_request_to_buyer!
598
- send_email(:payment_request_to_buyer, to_param) unless purchased?
598
+ EffectiveOrders.send_email(:payment_request_to_buyer, self) unless purchased?
599
599
  end
600
600
 
601
601
  def send_pending_order_invoice_to_buyer!
602
- send_email(:pending_order_invoice_to_buyer, to_param) unless purchased?
602
+ EffectiveOrders.send_email(:pending_order_invoice_to_buyer, self) unless purchased?
603
603
  end
604
604
 
605
605
  def send_refund_notification!
606
- send_email(:refund_notification_to_admin, to_param) if purchased? && refund?
606
+ EffectiveOrders.send_email(:refund_notification_to_admin, self) if purchased? && refund?
607
607
  end
608
608
 
609
609
  def skip_qb_sync!
@@ -707,23 +707,6 @@ module Effective
707
707
  true
708
708
  end
709
709
 
710
- def send_email(email, *args)
711
- raise('expected args to be an Array') unless args.kind_of?(Array)
712
-
713
- if defined?(Tenant)
714
- tenant = Tenant.current || raise('expected a current tenant')
715
- args << { tenant: tenant }
716
- end
717
-
718
- deliver_method = EffectiveOrders.mailer[:deliver_method] || EffectiveResources.deliver_method
719
-
720
- begin
721
- EffectiveOrders.mailer_klass.send(email, *args).send(deliver_method)
722
- rescue => e
723
- raise if Rails.env.development? || Rails.env.test?
724
- end
725
- end
726
-
727
710
  def payment_to_h(payment)
728
711
  if payment.respond_to?(:to_unsafe_h)
729
712
  payment.to_unsafe_h.to_h
@@ -15,7 +15,7 @@
15
15
 
16
16
  = f.check_box :send_payment_request_to_buyer,
17
17
  label: 'Yes, send a payment request email to the buyer and any cc.',
18
- value: (f.object.send_payment_request_to_buyer.nil? ? EffectiveOrders.mailer[:send_payment_request_to_buyer] : f.object.send_payment_request_to_buyer?)
18
+ value: (f.object.send_payment_request_to_buyer.nil? ? EffectiveOrders.send_payment_request_to_buyer : f.object.send_payment_request_to_buyer?)
19
19
 
20
20
  .row
21
21
  .col-md-6.effective-order-note-to-buyer
@@ -19,7 +19,7 @@
19
19
 
20
20
  = f.check_box :send_mark_as_paid_email_to_buyer,
21
21
  label: 'Yes, send a 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?) }
22
+ input_html: { checked: (f.object.send_mark_as_paid_email_to_buyer.nil? ? EffectiveOrders.send_order_receipts_when_mark_as_paid : f.object.send_mark_as_paid_email_to_buyer?) }
23
23
 
24
24
  = f.text_area :note_to_buyer, hint: 'This message will be displayed on the receipt.'
25
25
 
@@ -72,68 +72,37 @@ EffectiveOrders.setup do |config|
72
72
  config.pretend_message = '* payment information is not required to process this order at this time.'
73
73
 
74
74
  # Mailer Settings
75
- # effective_orders sends out receipts to buyers and admins as well as trial and subscription related emails.
76
- # For all the emails, the same :subject_prefix will be prefixed. Leave as nil / empty string if you don't want any prefix
75
+ # Please see config/initializers/effective_resources.rb for default effective_* gem mailer settings
77
76
  #
78
- # All the subject_* keys below can one of:
79
- # - nil / empty string to use the built in defaults
80
- # - A string with the full subject line for this email
81
- # - A Proc to create the subject line based on the email
82
- # The subject_prefix will then be applied ontop of these.
77
+ # Configure the class responsible to send e-mails.
78
+ # config.mailer = 'Effective::OrdersMailer'
83
79
  #
84
- # send_order_receipt_to_buyer: Proc.new { |order| "Order #{order.to_param} has been purchased"}
85
- # subject_for_subscription_payment_succeeded: Proc.new { |order| "Order #{order.to_param} has been purchased"}
86
-
87
- # subject_for_subscription_trialing: Proc.new { |subscribable| "Pending Order #{order.to_param}"}
88
-
89
- # Use this mailer class. You can extend.
90
- config.mailer_class_name = 'Effective::OrdersMailer'
91
-
92
- config.mailer = {
93
- send_order_receipt_to_admin: true,
94
- send_order_receipt_to_buyer: true,
95
- send_payment_request_to_buyer: true,
96
- send_pending_order_invoice_to_buyer: true,
97
- send_order_receipts_when_mark_as_paid: false,
98
- send_order_receipts_when_free: false,
99
-
100
- send_subscription_event_to_admin: true,
101
- send_subscription_created: true,
102
- send_subscription_updated: true,
103
- send_subscription_canceled: true,
104
- send_subscription_payment_succeeded: true,
105
- send_subscription_payment_failed: true,
106
-
107
- send_subscription_trialing: true, # Only if you schedule the rake task to run
108
- send_subscription_trial_expired: true, # Only if you schedule the rake task to run
109
-
110
- subject_prefix: '[example]',
111
-
112
- # Procs yield an Effective::Order object
113
- subject_for_order_receipt_to_admin: '',
114
- subject_for_order_receipt_to_buyer: '',
115
- subject_for_payment_request_to_buyer: '',
116
- subject_for_pending_order_invoice_to_buyer: '',
117
- subject_for_refund_notification_to_admin: '',
80
+ # Override effective_resource mailer defaults
81
+ #
82
+ # config.parent_mailer = nil # The parent class responsible for sending emails
83
+ # config.deliver_method = nil # The deliver method, deliver_later or deliver_now
84
+ # config.mailer_layout = nil # Default mailer layout
85
+ # config.mailer_sender = nil # Default From value
86
+ # config.mailer_admin = nil # Default To value for Admin correspondence
87
+ # config.mailer_subject = nil # Proc.new method used to customize Subject
118
88
 
119
- # Procs yield an Effective::Customer object
120
- subject_for_subscription_created: '',
121
- subject_for_subscription_updated: '',
122
- subject_for_subscription_canceled: '',
123
- subject_for_subscription_payment_succeeded: '',
124
- subject_for_subscription_payment_failed: '',
89
+ config.mailer_layout = 'effective_orders_mailer_layout'
125
90
 
126
- # Procs yield the acts_as_subscribable object
127
- subject_for_subscription_trialing: '',
128
- subject_for_subscription_trial_expired: '',
91
+ # Email settings
92
+ config.send_order_receipt_to_admin = true
93
+ config.send_order_receipt_to_buyer = true
94
+ config.send_payment_request_to_buyer = true
95
+ config.send_pending_order_invoice_to_buyer = true
129
96
 
130
- layout: 'effective_orders_mailer_layout',
97
+ config.send_order_receipts_when_mark_as_paid = true
98
+ config.send_order_receipts_when_free = true
131
99
 
132
- default_from: 'info@example.com',
133
- admin_email: 'admin@example.com', # Refund notifications will also be sent here
100
+ # Stripe Webhooks controller
101
+ config.send_subscription_events = true
134
102
 
135
- deliver_method: nil # When nil, will try deliver_later and fallback to deliver_now
136
- }
103
+ # These two only take affect if you schedule the rake task to run
104
+ config.send_subscription_trialing = true
105
+ config.send_subscription_trial_expired = true
137
106
 
138
107
  #######################################
139
108
  ## Payment Provider specific options ##
@@ -226,7 +195,7 @@ EffectiveOrders.setup do |config|
226
195
  # Refunds
227
196
  # This does not issue a refund with the payment processor at all.
228
197
  # Instead, we mark the order as purchased, create a refund object to track it, and
229
- # send an email to mailer[:admin_email] with instructions to issue a refund
198
+ # send an email to config.mailer_admin with instructions to issue a refund
230
199
  config.refund = false
231
200
 
232
201
  # config.refund = {
@@ -23,8 +23,8 @@ module EffectiveOrders
23
23
 
24
24
  initializer 'effective_orders.refund', after: :load_config_initializers do
25
25
  if EffectiveOrders.refund?
26
- unless (EffectiveOrders.mailer[:admin_email].to_s.include?('@') rescue false)
27
- raise("config.mailer[:admin_email] must be present when refunds enabled.")
26
+ unless (EffectiveOrders.mailer_admin.to_s.include?('@') rescue false)
27
+ raise("config.mailer_admin must be present when refunds enabled.")
28
28
  end
29
29
  end
30
30
  end
@@ -1,3 +1,3 @@
1
1
  module EffectiveOrders
2
- VERSION = '5.3.2'.freeze
2
+ VERSION = '5.4.0'.freeze
3
3
  end
@@ -33,15 +33,25 @@ module EffectiveOrders
33
33
  [
34
34
  :orders_table_name, :order_items_table_name, :carts_table_name, :cart_items_table_name,
35
35
  :customers_table_name, :subscriptions_table_name, :products_table_name,
36
- :layout, :mailer_class_name, :mailer,
36
+ :layout,
37
37
  :orders_collection_scope, :order_tax_rate_method,
38
38
  :obfuscate_order_ids, :use_effective_qb_sync, :use_effective_qb_online,
39
39
  :billing_address, :shipping_address,
40
40
  :collect_note, :collect_note_required, :collect_note_message,
41
41
  :terms_and_conditions, :terms_and_conditions_label, :minimum_charge,
42
42
 
43
+ # Mailer
44
+ :mailer, :parent_mailer, :deliver_method, :mailer_layout, :mailer_sender, :mailer_admin, :mailer_subject,
45
+
46
+ # Emails
47
+ :send_order_receipt_to_admin, :send_order_receipt_to_buyer, :send_payment_request_to_buyer, :send_pending_order_invoice_to_buyer,
48
+ :send_order_receipts_when_mark_as_paid, :send_order_receipts_when_free,
49
+ :send_subscription_events,
50
+ :send_subscription_trialing, :send_subscription_trial_expired,
51
+
43
52
  # Features
44
53
  :free_enabled, :mark_as_paid_enabled, :pretend_enabled, :pretend_message,
54
+
45
55
  # Payment processors. false or Hash
46
56
  :cheque, :moneris, :moneris_checkout, :paypal, :phone, :refund, :stripe, :subscriptions, :trial
47
57
  ]
@@ -144,9 +154,8 @@ module EffectiveOrders
144
154
  use_effective_qb_online && defined?(EffectiveQbOnline)
145
155
  end
146
156
 
147
- def self.mailer_klass
148
- name = mailer_class_name.presence || 'Effective::OrdersMailer'
149
- name.safe_constantize || raise("unable to constantize mailer class. check config.mailer_class_name")
157
+ def self.mailer_class
158
+ mailer&.constantize || Effective::OrdersMailer
150
159
  end
151
160
 
152
161
  def self.can_skip_checkout_step1?
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.3.2
4
+ version: 5.4.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: 2022-03-03 00:00:00.000000000 Z
11
+ date: 2022-03-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails