effective_orders 4.0.0beta12 → 4.0.0beta13
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/assets/javascripts/effective_orders/subscriptions.js.coffee +3 -0
- data/app/controllers/effective/webhooks_controller.rb +8 -3
- data/app/helpers/effective_subscriptions_helper.rb +0 -2
- data/app/mailers/effective/orders_mailer.rb +78 -170
- data/app/views/effective/orders_mailer/subscription_created.html.haml +13 -0
- data/app/views/effective/orders_mailer/{subscription_trial_expiring.html.haml → subscription_trialing.html.haml} +0 -0
- data/app/views/effective/orders_mailer/subscription_updated.html.haml +13 -0
- data/config/effective_orders.rb +20 -13
- data/lib/effective_orders/version.rb +1 -1
- data/lib/generators/effective_orders/install_generator.rb +13 -0
- data/lib/generators/templates/effective_orders_mailer_preview.rb +24 -19
- data/lib/tasks/effective_orders_tasks.rake +9 -13
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fdea3f4d9f23be9fc167ecab4c4fb9e713f5dace
|
4
|
+
data.tar.gz: 28345325ce45052bd240e048b52eefea6fcd06e4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1b03283f67b8f5f9d3d046b7f4f94e58f4631a6aa0f142ca560fbb829657220c139e949b7737d25f5217817996d55adb286f2ed7578939b579183006c0e581d6
|
7
|
+
data.tar.gz: f32aa391e9dcf39a615c392198ddc997d0f823535931b3a59b253877681d75c3d03a9a8d9000efec46d1561a66cff93905cafe86ae823b427f464deddda57178
|
@@ -40,3 +40,6 @@ $(document).on 'click', ".effective-orders-stripe-token-required[type='submit']"
|
|
40
40
|
description: plan.name
|
41
41
|
amount: plan.amount
|
42
42
|
panelLabel: "{{amount}}/#{plan.interval} Go!"
|
43
|
+
|
44
|
+
$(document).on 'change', "input[name='effective_subscripter[stripe_plan_id]']", (event) ->
|
45
|
+
$(event.currentTarget).closest('form').find(".effective-orders-stripe-token-required[type='submit']").click()
|
@@ -39,21 +39,22 @@ module Effective
|
|
39
39
|
# when 'charge.failed' # Card declined. 4000 0000 0000 0341
|
40
40
|
|
41
41
|
when 'invoice.payment_succeeded'
|
42
|
-
customer = Effective::Customer.where(stripe_customer_id: @event.data.object.customer).first!
|
43
42
|
customer.update_attributes!(status: EffectiveOrders::ACTIVE)
|
44
43
|
|
45
44
|
send_email(:subscription_payment_succeeded, customer)
|
46
45
|
when 'invoice.payment_failed'
|
47
|
-
customer = Effective::Customer.where(stripe_customer_id: @event.data.object.customer).first!
|
48
46
|
customer.update_attributes!(status: EffectiveOrders::PAST_DUE)
|
49
47
|
|
50
48
|
send_email(:subscription_payment_failed, customer)
|
51
49
|
when 'customer.subscription.deleted'
|
52
|
-
customer = Effective::Customer.where(stripe_customer_id: @event.data.object.customer).first!
|
53
50
|
customer.update_attributes!(stripe_subscription_id: nil, status: nil, active_card: nil)
|
54
51
|
customer.subscriptions.delete_all
|
55
52
|
|
56
53
|
send_email(:subscription_canceled, customer)
|
54
|
+
when 'customer.subscription.created'
|
55
|
+
send_email(:subscription_created, customer)
|
56
|
+
when 'customer.subscription.updated'
|
57
|
+
send_email(:subscription_updated, customer)
|
57
58
|
else
|
58
59
|
Rails.logger.info "[STRIPE WEBHOOK] Unhandled event type #{@event.type}"
|
59
60
|
end
|
@@ -64,6 +65,10 @@ module Effective
|
|
64
65
|
|
65
66
|
private
|
66
67
|
|
68
|
+
def customer
|
69
|
+
@customer ||= Effective::Customer.where(stripe_customer_id: @event.data.object.customer).first!
|
70
|
+
end
|
71
|
+
|
67
72
|
def send_email(email, *mailer_args)
|
68
73
|
Effective::OrdersMailer.public_send(email, *mailer_args).public_send(EffectiveOrders.mailer[:deliver_method])
|
69
74
|
end
|
@@ -1,46 +1,30 @@
|
|
1
1
|
module Effective
|
2
2
|
class OrdersMailer < ActionMailer::Base
|
3
|
-
|
3
|
+
default from: EffectiveOrders.mailer[:default_from]
|
4
4
|
|
5
|
+
helper EffectiveOrdersHelper
|
5
6
|
layout EffectiveOrders.mailer[:layout].presence || 'effective_orders_mailer_layout'
|
6
7
|
|
7
8
|
def order_receipt_to_admin(order_param)
|
8
9
|
return true unless EffectiveOrders.mailer[:send_order_receipt_to_admin]
|
9
10
|
|
10
11
|
@order = (order_param.kind_of?(Effective::Order) ? order_param : Effective::Order.find(order_param))
|
12
|
+
@user = @order.user
|
11
13
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
subject: subject_for_order_receipt_to_admin(@order)
|
16
|
-
)
|
14
|
+
@subject = subject_for(@order, :order_receipt_to_admin, "Order Receipt: ##{@order.to_param}")
|
15
|
+
|
16
|
+
mail(to: EffectiveOrders.mailer[:admin_email], from: EffectiveOrders.mailer[:default_from], subject: @subject)
|
17
17
|
end
|
18
18
|
|
19
19
|
def order_receipt_to_buyer(order_param) # Buyer
|
20
20
|
return true unless EffectiveOrders.mailer[:send_order_receipt_to_buyer]
|
21
21
|
|
22
22
|
@order = (order_param.kind_of?(Effective::Order) ? order_param : Effective::Order.find(order_param))
|
23
|
+
@user = @order.user
|
23
24
|
|
24
|
-
|
25
|
-
to: @order.user.email,
|
26
|
-
from: EffectiveOrders.mailer[:default_from],
|
27
|
-
subject: subject_for_order_receipt_to_buyer(@order)
|
28
|
-
)
|
29
|
-
end
|
25
|
+
@subject = subject_for(@order, :order_receipt_to_buyer, "Order Receipt: ##{@order.to_param}")
|
30
26
|
|
31
|
-
|
32
|
-
return true unless EffectiveOrders.mailer[:send_order_receipt_to_seller]
|
33
|
-
|
34
|
-
@order = (order_param.kind_of?(Effective::Order) ? order_param : Effective::Order.find(order_param))
|
35
|
-
@user = seller.user
|
36
|
-
@order_items = order_items
|
37
|
-
@subject = subject_for_order_receipt_to_seller(@order, @order_items, seller.user)
|
38
|
-
|
39
|
-
mail(
|
40
|
-
to: @user.email,
|
41
|
-
from: EffectiveOrders.mailer[:default_from],
|
42
|
-
subject: @subject
|
43
|
-
)
|
27
|
+
mail(to: @order.user.email, subject: @subject)
|
44
28
|
end
|
45
29
|
|
46
30
|
# This is sent when an admin creates a new order or /admin/orders/new
|
@@ -49,12 +33,11 @@ module Effective
|
|
49
33
|
return true unless EffectiveOrders.mailer[:send_payment_request_to_buyer]
|
50
34
|
|
51
35
|
@order = (order_param.kind_of?(Effective::Order) ? order_param : Effective::Order.find(order_param))
|
36
|
+
@user = @order.user
|
52
37
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
subject: subject_for_payment_request_to_buyer(@order)
|
57
|
-
)
|
38
|
+
@subject = subject_for(@order, :payment_request_to_buyer, "Request for Payment: Invoice ##{@order.to_param}")
|
39
|
+
|
40
|
+
mail(to: @order.user.email, subject: @subject)
|
58
41
|
end
|
59
42
|
|
60
43
|
# This is sent when someone chooses to Pay by Cheque
|
@@ -62,12 +45,11 @@ module Effective
|
|
62
45
|
return true unless EffectiveOrders.mailer[:send_pending_order_invoice_to_buyer]
|
63
46
|
|
64
47
|
@order = (order_param.kind_of?(Effective::Order) ? order_param : Effective::Order.find(order_param))
|
48
|
+
@user = @order.user
|
65
49
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
subject: subject_for_pending_order_invoice_to_buyer(@order)
|
70
|
-
)
|
50
|
+
@subject = subject_for(@order, :pending_order_invoice_to_buyer, "Pending Order: ##{@order.to_param}")
|
51
|
+
|
52
|
+
mail(to: @order.user.email, subject: @subject)
|
71
53
|
end
|
72
54
|
|
73
55
|
# Sent by the invoice.payment_succeeded webhook event
|
@@ -75,12 +57,12 @@ module Effective
|
|
75
57
|
return true unless EffectiveOrders.mailer[:send_subscription_payment_succeeded]
|
76
58
|
|
77
59
|
@customer = (customer_param.kind_of?(Effective::Customer) ? customer_param : Effective::Customer.find(customer_param))
|
60
|
+
@subscriptions = @customer.subscriptions
|
61
|
+
@user = @customer.user
|
78
62
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
subject: subject_for_subscription_payment_succeeded(@customer)
|
83
|
-
)
|
63
|
+
@subject = subject_for(@customer, :subscription_payment_succeeded, 'Thank you for your payment')
|
64
|
+
|
65
|
+
mail(to: @customer.user.email, subject: @subject)
|
84
66
|
end
|
85
67
|
|
86
68
|
# Sent by the invoice.payment_failed webhook event
|
@@ -88,12 +70,38 @@ module Effective
|
|
88
70
|
return true unless EffectiveOrders.mailer[:send_subscription_payment_failed]
|
89
71
|
|
90
72
|
@customer = (customer_param.kind_of?(Effective::Customer) ? customer_param : Effective::Customer.find(customer_param))
|
73
|
+
@subscriptions = @customer.subscriptions
|
74
|
+
@user = @customer.user
|
91
75
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
76
|
+
@subject = subject_for(@customer, :subscription_payment_failed, 'Payment failed - please update your card details')
|
77
|
+
|
78
|
+
mail(to: @customer.user.email, subject: @subject)
|
79
|
+
end
|
80
|
+
|
81
|
+
# Sent by the customer.subscription.created webhook event
|
82
|
+
def subscription_created(customer_param)
|
83
|
+
return true unless EffectiveOrders.mailer[:send_subscription_created]
|
84
|
+
|
85
|
+
@customer = (customer_param.kind_of?(Effective::Customer) ? customer_param : Effective::Customer.find(customer_param))
|
86
|
+
@subscriptions = @customer.subscriptions
|
87
|
+
@user = @customer.user
|
88
|
+
|
89
|
+
@subject = subject_for(@customer, :subscription_created, 'New Subscription')
|
90
|
+
|
91
|
+
mail(to: @customer.user.email, subject: @subject)
|
92
|
+
end
|
93
|
+
|
94
|
+
# Sent by the customer.subscription.updated webhook event
|
95
|
+
def subscription_updated(customer_param)
|
96
|
+
return true unless EffectiveOrders.mailer[:send_subscription_updated]
|
97
|
+
|
98
|
+
@customer = (customer_param.kind_of?(Effective::Customer) ? customer_param : Effective::Customer.find(customer_param))
|
99
|
+
@subscriptions = @customer.subscriptions
|
100
|
+
@user = @customer.user
|
101
|
+
|
102
|
+
@subject = subject_for(@customer, :subscription_updated, 'Subscription Changed')
|
103
|
+
|
104
|
+
mail(to: @customer.user.email, subject: @subject)
|
97
105
|
end
|
98
106
|
|
99
107
|
# Sent by the invoice.payment_failed webhook event
|
@@ -101,25 +109,24 @@ module Effective
|
|
101
109
|
return true unless EffectiveOrders.mailer[:send_subscription_canceled]
|
102
110
|
|
103
111
|
@customer = (customer_param.kind_of?(Effective::Customer) ? customer_param : Effective::Customer.find(customer_param))
|
112
|
+
@subscriptions = @customer.subscriptions
|
113
|
+
@user = @customer.user
|
104
114
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
subject: subject_for_subscription_canceled(@customer)
|
109
|
-
)
|
115
|
+
@subject = subject_for(@customer, :subscription_canceled, 'Subscription canceled')
|
116
|
+
|
117
|
+
mail(to: @customer.user.email, subject: @subject)
|
110
118
|
end
|
111
119
|
|
112
120
|
# Sent by the effective_orders:notify_trial_users rake task.
|
113
|
-
def
|
114
|
-
return true unless EffectiveOrders.mailer[:
|
121
|
+
def subscription_trialing(subscribable)
|
122
|
+
return true unless EffectiveOrders.mailer[:send_subscription_trialing]
|
115
123
|
|
116
124
|
@subscribable = subscribable
|
125
|
+
@user = @subscribable.subscribable_buyer
|
117
126
|
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
subject: subject_for_subscription_trial_expiring(@subscribable)
|
122
|
-
)
|
127
|
+
@subject = subject_for(@customer, :subscription_trialing, 'Trial is active')
|
128
|
+
|
129
|
+
mail(to: @subscribable.subscribable_buyer.email, subject: @subject)
|
123
130
|
end
|
124
131
|
|
125
132
|
# Sent by the effective_orders:notify_trial_users rake task.
|
@@ -127,28 +134,23 @@ module Effective
|
|
127
134
|
return true unless EffectiveOrders.mailer[:send_subscription_trial_expired]
|
128
135
|
|
129
136
|
@subscribable = subscribable
|
137
|
+
@user = @subscribable.subscribable_buyer
|
130
138
|
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
subject: subject_for_subscription_trial_expired(@subscribable)
|
135
|
-
)
|
139
|
+
@subject = subject_for(@customer, :subscription_trial_expired, 'Trial expired')
|
140
|
+
|
141
|
+
mail(to: @subscribable.subscribable_buyer.email, subject: @subject)
|
136
142
|
end
|
137
143
|
|
138
144
|
def order_error(order: nil, error: nil, to: nil, from: nil, subject: nil, template: 'order_error')
|
139
|
-
|
140
|
-
@order = (order.kind_of?(Effective::Order) ? order : Effective::Order.find(order))
|
141
|
-
@subject = (subject || "An error occurred with order: ##{@order.try(:to_param)}")
|
142
|
-
else
|
143
|
-
@subject = (subject || "An order error occurred with an unknown order")
|
144
|
-
end
|
145
|
-
|
145
|
+
@order = (order.kind_of?(Effective::Order) ? order : Effective::Order.find(order))
|
146
146
|
@error = error.to_s
|
147
147
|
|
148
|
+
@subject = subject_for(@order, :error, "An error occurred with order: ##{@order.try(:to_param)}")
|
149
|
+
|
148
150
|
mail(
|
149
151
|
to: (to || EffectiveOrders.mailer[:admin_email]),
|
150
152
|
from: (from || EffectiveOrders.mailer[:default_from]),
|
151
|
-
subject:
|
153
|
+
subject: (subject || @subject)
|
152
154
|
) do |format|
|
153
155
|
format.html { render(template) }
|
154
156
|
end
|
@@ -156,109 +158,15 @@ module Effective
|
|
156
158
|
|
157
159
|
private
|
158
160
|
|
159
|
-
def
|
160
|
-
|
161
|
-
|
162
|
-
if string_or_callable.respond_to?(:call) # This is a Proc or a function, not a string
|
163
|
-
string_or_callable = self.instance_exec(order, &string_or_callable)
|
164
|
-
end
|
165
|
-
|
166
|
-
prefix_subject(string_or_callable.presence || "Order Receipt: ##{order.to_param}")
|
167
|
-
end
|
168
|
-
|
169
|
-
def subject_for_order_receipt_to_buyer(order)
|
170
|
-
string_or_callable = EffectiveOrders.mailer[:subject_for_order_receipt_to_buyer]
|
171
|
-
|
172
|
-
if string_or_callable.respond_to?(:call) # This is a Proc or a function, not a string
|
173
|
-
string_or_callable = self.instance_exec(order, &string_or_callable)
|
174
|
-
end
|
175
|
-
|
176
|
-
prefix_subject(string_or_callable.presence || "Order Receipt: ##{order.to_param}")
|
177
|
-
end
|
178
|
-
|
179
|
-
def subject_for_order_receipt_to_seller(order, order_items, seller)
|
180
|
-
string_or_callable = EffectiveOrders.mailer[:subject_for_order_receipt_to_seller]
|
181
|
-
|
182
|
-
if string_or_callable.respond_to?(:call) # This is a Proc or a function, not a string
|
183
|
-
string_or_callable = self.instance_exec(order, order_items, seller, &string_or_callable)
|
184
|
-
end
|
185
|
-
|
186
|
-
prefix_subject(string_or_callable.presence || "#{order_items.length} of your products #{order_items.length > 1 ? 'have' : 'has'} been purchased")
|
187
|
-
end
|
188
|
-
|
189
|
-
def subject_for_payment_request_to_buyer(order)
|
190
|
-
string_or_callable = EffectiveOrders.mailer[:subject_for_payment_request_to_buyer]
|
161
|
+
def subject_for(order, action, fallback)
|
162
|
+
subject = EffectiveOrders.mailer["subject_for_#{action}".to_sym]
|
163
|
+
prefix = EffectiveOrders.mailer[:subject_prefix].to_s
|
191
164
|
|
192
|
-
if
|
193
|
-
|
194
|
-
end
|
195
|
-
|
196
|
-
prefix_subject(string_or_callable.presence || "Request for Payment: Invoice ##{order.to_param}")
|
197
|
-
end
|
198
|
-
|
199
|
-
def subject_for_pending_order_invoice_to_buyer(order)
|
200
|
-
string_or_callable = EffectiveOrders.mailer[:subject_for_pending_order_invoice_to_buyer]
|
201
|
-
|
202
|
-
if string_or_callable.respond_to?(:call) # This is a Proc or a function, not a string
|
203
|
-
string_or_callable = self.instance_exec(order, &string_or_callable)
|
204
|
-
end
|
205
|
-
|
206
|
-
prefix_subject(string_or_callable.presence || "Pending Order: ##{order.to_param}")
|
207
|
-
end
|
208
|
-
|
209
|
-
def subject_for_subscription_payment_succeeded(customer)
|
210
|
-
string_or_callable = EffectiveOrders.mailer[:subject_for_subscription_payment_succeeded]
|
211
|
-
|
212
|
-
if string_or_callable.respond_to?(:call) # This is a Proc or a function, not a string
|
213
|
-
string_or_callable = self.instance_exec(order, &string_or_callable)
|
214
|
-
end
|
165
|
+
subject = self.instance_exec(order, &subject) if subject.respond_to?(:call)
|
166
|
+
subject = subject.presence || fallback
|
215
167
|
|
216
|
-
|
168
|
+
prefix.present? ? (prefix.chomp(' ') + ' ' + subject) : subject
|
217
169
|
end
|
218
170
|
|
219
|
-
def subject_for_subscription_payment_failed(customer)
|
220
|
-
string_or_callable = EffectiveOrders.mailer[:subject_for_subscription_payment_failed]
|
221
|
-
|
222
|
-
if string_or_callable.respond_to?(:call) # This is a Proc or a function, not a string
|
223
|
-
string_or_callable = self.instance_exec(order, &string_or_callable)
|
224
|
-
end
|
225
|
-
|
226
|
-
prefix_subject(string_or_callable.presence || 'Payment failed - please update your card details')
|
227
|
-
end
|
228
|
-
|
229
|
-
def subject_for_subscription_canceled(customer)
|
230
|
-
string_or_callable = EffectiveOrders.mailer[:subject_for_subscription_canceled]
|
231
|
-
|
232
|
-
if string_or_callable.respond_to?(:call) # This is a Proc or a function, not a string
|
233
|
-
string_or_callable = self.instance_exec(order, &string_or_callable)
|
234
|
-
end
|
235
|
-
|
236
|
-
prefix_subject(string_or_callable.presence || 'Subscription canceled')
|
237
|
-
end
|
238
|
-
|
239
|
-
def subject_for_subscription_trial_expiring(customer)
|
240
|
-
string_or_callable = EffectiveOrders.mailer[:subject_for_subscription_trial_expiring]
|
241
|
-
|
242
|
-
if string_or_callable.respond_to?(:call) # This is a Proc or a function, not a string
|
243
|
-
string_or_callable = self.instance_exec(order, &string_or_callable)
|
244
|
-
end
|
245
|
-
|
246
|
-
prefix_subject(string_or_callable.presence || 'Trial expiring soon')
|
247
|
-
end
|
248
|
-
|
249
|
-
def subject_for_subscription_trial_expired(customer)
|
250
|
-
string_or_callable = EffectiveOrders.mailer[:subject_for_subscription_trial_expired]
|
251
|
-
|
252
|
-
if string_or_callable.respond_to?(:call) # This is a Proc or a function, not a string
|
253
|
-
string_or_callable = self.instance_exec(order, &string_or_callable)
|
254
|
-
end
|
255
|
-
|
256
|
-
prefix_subject(string_or_callable.presence || 'Trial expired')
|
257
|
-
end
|
258
|
-
|
259
|
-
def prefix_subject(text)
|
260
|
-
prefix = (EffectiveOrders.mailer[:subject_prefix].to_s rescue '')
|
261
|
-
prefix.present? ? (prefix.chomp(' ') + ' ' + text) : text
|
262
|
-
end
|
263
171
|
end
|
264
172
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
%p.effective-orders-receipt-info Subscription created
|
2
|
+
|
3
|
+
%p Thank you for subscribing!
|
4
|
+
|
5
|
+
%p You are currently subscribed to the following:
|
6
|
+
|
7
|
+
%ul
|
8
|
+
- @subscriptions.each do |subscription|
|
9
|
+
%li #{subscription.subscribable.to_s} - #{subscription}
|
10
|
+
|
11
|
+
%p Please click the following link to view past invoices or update your card settings:
|
12
|
+
|
13
|
+
%p= link_to(effective_orders.customer_settings_url, effective_orders.customer_settings_url)
|
File without changes
|
@@ -0,0 +1,13 @@
|
|
1
|
+
%p.effective-orders-receipt-info Subscription updated
|
2
|
+
|
3
|
+
%p Your subscription has changed
|
4
|
+
|
5
|
+
%p You are currently subscribed to the following:
|
6
|
+
|
7
|
+
%ul
|
8
|
+
- @subscriptions.each do |subscription|
|
9
|
+
%li #{subscription.subscribable.to_s} - #{subscription}
|
10
|
+
|
11
|
+
%p Please click the following link to view past invoices or update your card settings:
|
12
|
+
|
13
|
+
%p= link_to(effective_orders.customer_settings_url, effective_orders.customer_settings_url)
|
data/config/effective_orders.rb
CHANGED
@@ -112,21 +112,19 @@ EffectiveOrders.setup do |config|
|
|
112
112
|
config.pretend_message = '* payment information is not required to process this order at this time.'
|
113
113
|
|
114
114
|
# Mailer Settings
|
115
|
-
# effective_orders
|
115
|
+
# effective_orders sends out receipts to buyers and admins as well as trial and subscription related emails.
|
116
116
|
# For all the emails, the same :subject_prefix will be prefixed. Leave as nil / empty string if you don't want any prefix
|
117
117
|
#
|
118
|
-
#
|
119
|
-
# subject_for_seller_receipt can be one of:
|
118
|
+
# All the subject_* keys below can one of:
|
120
119
|
# - nil / empty string to use the built in defaults
|
121
120
|
# - A string with the full subject line for this email
|
122
121
|
# - A Proc to create the subject line based on the email
|
123
|
-
#
|
122
|
+
# The subject_prefix will then be applied ontop of these.
|
123
|
+
#
|
124
|
+
# send_order_receipt_to_buyer: Proc.new { |order| "Order #{order.to_param} has been purchased"}
|
125
|
+
# subject_for_subscription_payment_succeeded: Proc.new { |order| "Order #{order.to_param} has been purchased"}
|
124
126
|
|
125
|
-
#
|
126
|
-
# subject_for_order_receipt_to_admin: Proc.new { |order| "Order #{order.to_param} has been purchased"}
|
127
|
-
# subject_for_order_receipt_to_buyer: Proc.new { |order| "Order #{order.to_param} has been purchased"}
|
128
|
-
# subject_for_payment_request_to_buyer: Proc.new { |order| "Pending Order #{order.to_param}"}
|
129
|
-
# subject_for_order_receipt_to_seller: Proc.new { |order, order_items, seller| "Order #{order.to_param} has been purchased"}
|
127
|
+
# subject_for_subscription_trialing: Proc.new { |subscribable| "Pending Order #{order.to_param}"}
|
130
128
|
|
131
129
|
config.mailer = {
|
132
130
|
send_order_receipt_to_admin: true,
|
@@ -135,23 +133,32 @@ EffectiveOrders.setup do |config|
|
|
135
133
|
send_pending_order_invoice_to_buyer: true,
|
136
134
|
send_order_receipts_when_mark_as_paid: false,
|
137
135
|
|
136
|
+
send_subscription_created: true,
|
137
|
+
send_subscription_updated: true,
|
138
|
+
send_subscription_canceled: true,
|
138
139
|
send_subscription_payment_succeeded: true,
|
139
140
|
send_subscription_payment_failed: true,
|
140
|
-
|
141
|
-
|
141
|
+
|
142
|
+
send_subscription_trialing: true, # Only if you schedule the rake task to run
|
142
143
|
send_subscription_trial_expired: true, # Only if you schedule the rake task to run
|
143
144
|
|
144
145
|
subject_prefix: '[example]',
|
145
146
|
|
147
|
+
# Procs yield an Effective::Order object
|
146
148
|
subject_for_order_receipt_to_admin: '',
|
147
149
|
subject_for_order_receipt_to_buyer: '',
|
148
150
|
subject_for_payment_request_to_buyer: '',
|
149
151
|
subject_for_pending_order_invoice_to_buyer: '',
|
150
152
|
|
153
|
+
# Procs yield an Effective::Customer object
|
154
|
+
subject_for_subscription_created: '',
|
155
|
+
subject_for_subscription_updated: '',
|
156
|
+
subject_for_subscription_canceled: '',
|
151
157
|
subject_for_subscription_payment_succeeded: '',
|
152
158
|
subject_for_subscription_payment_failed: '',
|
153
|
-
|
154
|
-
|
159
|
+
|
160
|
+
# Procs yield the acts_as_subscribable object
|
161
|
+
subject_for_subscription_trialing: '',
|
155
162
|
subject_for_subscription_trial_expired: '',
|
156
163
|
|
157
164
|
layout: 'effective_orders_mailer_layout',
|
@@ -23,6 +23,19 @@ module EffectiveOrders
|
|
23
23
|
template ('../' * 3) + 'config/effective_orders.rb', 'config/initializers/effective_orders.rb'
|
24
24
|
end
|
25
25
|
|
26
|
+
def copy_mailer_layout
|
27
|
+
layout = 'app/views/layouts/effective_orders_mailer_layout.html.haml'
|
28
|
+
template ('../' * 3) + layout, layout
|
29
|
+
end
|
30
|
+
|
31
|
+
def copy_mailer_templates
|
32
|
+
path = 'app/views/effective/orders_mailer/'
|
33
|
+
|
34
|
+
Dir["#{source_paths.first}/../../../#{path}**"].map { |file| file.split('/').last }.each do |name|
|
35
|
+
template (('../' * 3) + path + name), (path + name)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
26
39
|
def copy_mailer_preview
|
27
40
|
mailer_preview_path = (Rails.application.config.action_mailer.preview_path rescue nil)
|
28
41
|
|
@@ -11,11 +11,6 @@ class EffectiveOrdersMailerPreview < ActionMailer::Preview
|
|
11
11
|
Effective::OrdersMailer.order_receipt_to_buyer(build_preview_order)
|
12
12
|
end
|
13
13
|
|
14
|
-
def order_receipt_to_seller
|
15
|
-
order = build_preview_order
|
16
|
-
Effective::OrdersMailer.order_receipt_to_seller(order, preview_customer, order.order_items)
|
17
|
-
end
|
18
|
-
|
19
14
|
def payment_request_to_buyer
|
20
15
|
Effective::OrdersMailer.payment_request_to_buyer(build_preview_order)
|
21
16
|
end
|
@@ -32,12 +27,20 @@ class EffectiveOrdersMailerPreview < ActionMailer::Preview
|
|
32
27
|
Effective::OrdersMailer.subscription_payment_failed(preview_customer)
|
33
28
|
end
|
34
29
|
|
30
|
+
def subscription_created
|
31
|
+
Effective::OrdersMailer.subscription_created(preview_customer)
|
32
|
+
end
|
33
|
+
|
34
|
+
def subscription_updated
|
35
|
+
Effective::OrdersMailer.subscription_updated(preview_customer)
|
36
|
+
end
|
37
|
+
|
35
38
|
def subscription_canceled
|
36
39
|
Effective::OrdersMailer.subscription_canceled(preview_customer)
|
37
40
|
end
|
38
41
|
|
39
|
-
def
|
40
|
-
Effective::OrdersMailer.
|
42
|
+
def subscription_trialing
|
43
|
+
Effective::OrdersMailer.subscription_trialing(preview_subscribable)
|
41
44
|
end
|
42
45
|
|
43
46
|
def subscription_trial_expired
|
@@ -51,7 +54,7 @@ class EffectiveOrdersMailerPreview < ActionMailer::Preview
|
|
51
54
|
protected
|
52
55
|
|
53
56
|
def build_preview_order
|
54
|
-
order = Effective::Order.new
|
57
|
+
order = Effective::Order.new(id: 1)
|
55
58
|
order.user = preview_user
|
56
59
|
preview_order_items.each { |atts| order.order_items.build(atts) }
|
57
60
|
order.valid?
|
@@ -90,22 +93,24 @@ class EffectiveOrdersMailerPreview < ActionMailer::Preview
|
|
90
93
|
end
|
91
94
|
|
92
95
|
def preview_customer
|
93
|
-
Effective::Customer.new(user: preview_user, active_card: '**** **** **** 1234 Visa 04/20')
|
96
|
+
customer = Effective::Customer.new(user: preview_user, active_card: '**** **** **** 1234 Visa 04/20')
|
97
|
+
|
98
|
+
if preview_subscribable.present?
|
99
|
+
customer.subscriptions.build(subscribable: preview_subscribable, name: 'Bronze Plan')
|
100
|
+
customer.subscriptions.build(subscribable: preview_subscribable, name: 'Silver Plan')
|
101
|
+
end
|
102
|
+
|
103
|
+
customer
|
94
104
|
end
|
95
105
|
|
96
106
|
def preview_subscribable
|
97
|
-
|
98
|
-
include ActiveModel::Model
|
99
|
-
attr_accessor :buyer
|
107
|
+
Rails.application.eager_load!
|
100
108
|
|
101
|
-
|
102
|
-
|
103
|
-
end
|
109
|
+
klasses = Array(ActsAsSubscribable.descendants).compact
|
110
|
+
return unless klasses.present?
|
104
111
|
|
105
|
-
|
106
|
-
|
107
|
-
end
|
108
|
-
end.new(buyer: preview_user)
|
112
|
+
klasses.map { |klass| klass.all.order(Arel.sql('random()')).first }.compact.first ||
|
113
|
+
klasses.first.new(subscribable_buyer: preview_user)
|
109
114
|
end
|
110
115
|
|
111
116
|
end
|
@@ -28,10 +28,9 @@ namespace :effective_orders do
|
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
task send_trial_expiring_emails: :environment do
|
31
|
+
# rake effective_orders:send_trial_emails
|
32
|
+
desc 'Sends subscription_trialing and subscription_trial_expired emails to each subscribable. Schedule me to run once per day.'
|
33
|
+
task send_trial_emails: :environment do
|
35
34
|
trial_remind_at = Array(EffectiveOrders.trial[:remind_at]).compact
|
36
35
|
exit unless trial_remind_at.present? && trial_remind_at.all? { |x| x.present? }
|
37
36
|
|
@@ -43,6 +42,7 @@ namespace :effective_orders do
|
|
43
42
|
begin
|
44
43
|
ActsAsSubscribable.descendants.each do |klass|
|
45
44
|
klass.trialing.find_each do |subscribable|
|
45
|
+
|
46
46
|
if subscribable.trialing_until == today
|
47
47
|
puts "sending trial expired to #{subscribable}"
|
48
48
|
Effective::OrdersMailer.subscription_trial_expired(subscribable).deliver_now
|
@@ -50,25 +50,21 @@ namespace :effective_orders do
|
|
50
50
|
|
51
51
|
next if subscribable.trial_past_due? # We already notified them
|
52
52
|
|
53
|
-
|
54
|
-
date = (subscribable.trialing_until - EffectiveOrders.trial.fetch(:length)) # Should be same as created_at.beginning_of_day
|
53
|
+
date = (subscribable.trialing_until - EffectiveOrders.trial.fetch(:length)) # Should be same as created_at.beginning_of_day
|
55
54
|
|
55
|
+
reminders.each do |remind_at|
|
56
56
|
next unless date == (today + remind_at)
|
57
|
-
|
58
|
-
puts "sending trial expiring to #{subscribable}. expires in #{(subscribable.trialing_until - today) / 1.day.to_i} days."
|
59
|
-
Effective::OrdersMailer.subscription_trial_expiring(subscribable).deliver_now
|
57
|
+
Effective::OrdersMailer.subscription_trialing(subscribable).deliver_now
|
60
58
|
end
|
61
59
|
end
|
62
60
|
end
|
63
61
|
|
64
|
-
puts '
|
65
|
-
EffectiveLogger.success('scheduled task
|
62
|
+
puts 'send_trial_emails completed'
|
63
|
+
EffectiveLogger.success('scheduled task send_trial_emails completed') if defined?(EffectiveLogger)
|
66
64
|
rescue => e
|
67
65
|
ExceptionNotifier.notify_exception(e) if defined?(ExceptionNotifier)
|
68
66
|
raise e
|
69
67
|
end
|
70
|
-
|
71
|
-
true
|
72
68
|
end
|
73
69
|
|
74
70
|
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: 4.0.
|
4
|
+
version: 4.0.0beta13
|
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: 2018-
|
11
|
+
date: 2018-06-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -223,10 +223,12 @@ files:
|
|
223
223
|
- app/views/effective/orders_mailer/payment_request_to_buyer.html.haml
|
224
224
|
- app/views/effective/orders_mailer/pending_order_invoice_to_buyer.html.haml
|
225
225
|
- app/views/effective/orders_mailer/subscription_canceled.html.haml
|
226
|
+
- app/views/effective/orders_mailer/subscription_created.html.haml
|
226
227
|
- app/views/effective/orders_mailer/subscription_payment_failed.html.haml
|
227
228
|
- app/views/effective/orders_mailer/subscription_payment_succeeded.html.haml
|
228
229
|
- app/views/effective/orders_mailer/subscription_trial_expired.html.haml
|
229
|
-
- app/views/effective/orders_mailer/
|
230
|
+
- app/views/effective/orders_mailer/subscription_trialing.html.haml
|
231
|
+
- app/views/effective/orders_mailer/subscription_updated.html.haml
|
230
232
|
- app/views/effective/subscripter/_form.html.haml
|
231
233
|
- app/views/effective/subscriptions/_plan.html.haml
|
232
234
|
- app/views/effective/subscriptions/_subscription.html.haml
|