Class: Effective::OrdersMailer

Inherits:
ActionMailer::Base
  • Object
show all
Defined in:
app/mailers/effective/orders_mailer.rb

Instance Method Summary collapse

Instance Method Details

#order_error(order: nil, error: nil, to: nil, from: nil, subject: nil, template: 'order_error') ⇒ Object



195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
# File 'app/mailers/effective/orders_mailer.rb', line 195

def order_error(order: nil, error: nil, to: nil, from: nil, subject: nil, template: 'order_error')
  around_mail_action(:order_error, order, {error: error, to: to, from: from, subject: subject, template: template}) do
    @order = (order.kind_of?(Effective::Order) ? order : Effective::Order.find(order))
    @error = error.to_s

    @subject = subject_for(@order, :error, "An error occurred with order: ##{@order.try(:to_param)}")

    mail(
      to: (to || EffectiveOrders.mailer[:admin_email]),
      from: (from || EffectiveOrders.mailer[:default_from]),
      subject: (subject || @subject)
    ) do |format|
      format.html { render(template) }
    end
  end
end

#order_receipt_to_admin(order_param, atts = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
# File 'app/mailers/effective/orders_mailer.rb', line 8

def order_receipt_to_admin(order_param, atts = {})
  around_mail_action(:order_receipt_to_admin, order_param, atts) do
    return true unless EffectiveOrders.mailer[:send_order_receipt_to_admin]

    @order = (order_param.kind_of?(Effective::Order) ? order_param : Effective::Order.find(order_param))
    @user = @order.user

    @subject = subject_for(@order, :order_receipt_to_admin, "Order Receipt: ##{@order.to_param}")

    mail(to: EffectiveOrders.mailer[:admin_email], subject: @subject)
  end
end

#order_receipt_to_buyer(order_param, atts = {}) ⇒ Object

Buyer



21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/mailers/effective/orders_mailer.rb', line 21

def order_receipt_to_buyer(order_param, atts = {})  # Buyer
  around_mail_action(:order_receipt_to_buyer, order_param, atts) do
    return true unless EffectiveOrders.mailer[:send_order_receipt_to_buyer]

    @order = (order_param.kind_of?(Effective::Order) ? order_param : Effective::Order.find(order_param))
    @user = @order.user

    @subject = subject_for(@order, :order_receipt_to_buyer, "Order Receipt: ##{@order.to_param}")

    mail(to: @order.email, cc: @order.cc, subject: @subject)
  end
end

#payment_request_to_buyer(order_param, atts = {}) ⇒ Object

This is sent when an admin creates a new order or /admin/orders/new Or when Pay by Cheque or Pay by Phone (deferred payments) Or uses the order action Send Payment Request



37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/mailers/effective/orders_mailer.rb', line 37

def payment_request_to_buyer(order_param, atts = {})
  around_mail_action(:payment_request_to_buyer, order_param, atts) do
    return true unless EffectiveOrders.mailer[:send_payment_request_to_buyer]

    @order = (order_param.kind_of?(Effective::Order) ? order_param : Effective::Order.find(order_param))
    @user = @order.user

    @subject = subject_for(@order, :payment_request_to_buyer, "Request for Payment: Invoice ##{@order.to_param}")

    mail(to: @order.email, cc: @order.cc, subject: @subject)
  end
end

#pending_order_invoice_to_buyer(order_param, atts = {}) ⇒ Object

This is sent when someone chooses to Pay by Cheque



52
53
54
55
56
57
58
59
60
61
62
63
# File 'app/mailers/effective/orders_mailer.rb', line 52

def pending_order_invoice_to_buyer(order_param, atts = {})
  around_mail_action(:pending_order_invoice_to_buyer, order_param, atts) do
    return true unless EffectiveOrders.mailer[:send_pending_order_invoice_to_buyer]

    @order = (order_param.kind_of?(Effective::Order) ? order_param : Effective::Order.find(order_param))
    @user = @order.user

    @subject = subject_for(@order, :pending_order_invoice_to_buyer, "Pending Order: ##{@order.to_param}")

    mail(to: @order.email, cc: @order.cc, subject: @subject)
  end
end

#refund_notification_to_admin(order_param, atts = {}) ⇒ Object

This is sent to admin when someone Accepts Refund



66
67
68
69
70
71
72
73
74
75
# File 'app/mailers/effective/orders_mailer.rb', line 66

def refund_notification_to_admin(order_param, atts = {})
  around_mail_action(:refund_notification_to_admin, order_param, atts) do
    @order = (order_param.kind_of?(Effective::Order) ? order_param : Effective::Order.find(order_param))
    @user = @order.user

    @subject = subject_for(@order, :refund_notification_to_admin, "New Refund: ##{@order.to_param}")

    mail(to: EffectiveOrders.mailer[:admin_email], subject: @subject)
  end
end

#subscription_canceled(customer_param, atts = {}) ⇒ Object

Sent by the invoice.payment_failed webhook event



138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'app/mailers/effective/orders_mailer.rb', line 138

def subscription_canceled(customer_param, atts = {})
  around_mail_action(:subscription_canceled, customer_param, atts) do
    return true unless EffectiveOrders.mailer[:send_subscription_canceled]

    @customer = (customer_param.kind_of?(Effective::Customer) ? customer_param : Effective::Customer.find(customer_param))
    @subscriptions = @customer.subscriptions
    @user = @customer.user

    @subject = subject_for(@customer, :subscription_canceled, 'Subscription canceled')

    mail(to: @customer.user.email, subject: @subject)
  end
end

#subscription_created(customer_param, atts = {}) ⇒ Object

Sent by the customer.subscription.created webhook event



108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'app/mailers/effective/orders_mailer.rb', line 108

def subscription_created(customer_param, atts = {})
  around_mail_action(:subscription_created, customer_param, atts) do
    return true unless EffectiveOrders.mailer[:send_subscription_created]

    @customer = (customer_param.kind_of?(Effective::Customer) ? customer_param : Effective::Customer.find(customer_param))
    @subscriptions = @customer.subscriptions
    @user = @customer.user

    @subject = subject_for(@customer, :subscription_created, 'New Subscription')

    mail(to: @customer.user.email, subject: @subject)
  end
end

#subscription_event_to_admin(event, customer_param, atts = {}) ⇒ Object



180
181
182
183
184
185
186
187
188
189
190
191
192
193
# File 'app/mailers/effective/orders_mailer.rb', line 180

def subscription_event_to_admin(event, customer_param, atts = {})
  around_mail_action(:subscription_event_to_admin, event, atts) do
    return true unless EffectiveOrders.mailer[:send_subscription_event_to_admin]

    @customer = (customer_param.kind_of?(Effective::Customer) ? customer_param : Effective::Customer.find(customer_param))
    @subscriptions = @customer.subscriptions
    @user = @customer.user
    @event = event.to_s

    @subject = subject_for(@customer, :subscription_event_to_admin, "Subscription event - @event - @customer").gsub('@event', @event.to_s).gsub('@customer', @customer.to_s)

    mail(to: EffectiveOrders.mailer[:admin_email], subject: @subject)
  end
end

#subscription_payment_failed(customer_param, atts = {}) ⇒ Object

Sent by the invoice.payment_failed webhook event



93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'app/mailers/effective/orders_mailer.rb', line 93

def subscription_payment_failed(customer_param, atts = {})
  around_mail_action(:subscription_payment_failed, customer_param, atts) do
    return true unless EffectiveOrders.mailer[:send_subscription_payment_failed]

    @customer = (customer_param.kind_of?(Effective::Customer) ? customer_param : Effective::Customer.find(customer_param))
    @subscriptions = @customer.subscriptions
    @user = @customer.user

    @subject = subject_for(@customer, :subscription_payment_failed, 'Payment failed - please update your card details')

    mail(to: @customer.user.email, subject: @subject)
  end
end

#subscription_payment_succeeded(customer_param, atts = {}) ⇒ Object

Sent by the invoice.payment_succeeded webhook event



78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'app/mailers/effective/orders_mailer.rb', line 78

def subscription_payment_succeeded(customer_param, atts = {})
  around_mail_action(:subscription_payment_succeeded, customer_param, atts) do
    return true unless EffectiveOrders.mailer[:send_subscription_payment_succeeded]

    @customer = (customer_param.kind_of?(Effective::Customer) ? customer_param : Effective::Customer.find(customer_param))
    @subscriptions = @customer.subscriptions
    @user = @customer.user

    @subject = subject_for(@customer, :subscription_payment_succeeded, 'Thank you for your payment')

    mail(to: @customer.user.email, subject: @subject)
  end
end

#subscription_trial_expired(subscribable, atts = {}) ⇒ Object

Sent by the effective_orders:notify_trial_users rake task.



167
168
169
170
171
172
173
174
175
176
177
178
# File 'app/mailers/effective/orders_mailer.rb', line 167

def subscription_trial_expired(subscribable, atts = {})
  around_mail_action(:subscription_trial_expired, subscribable, atts) do
    return true unless EffectiveOrders.mailer[:send_subscription_trial_expired]

    @subscribable = subscribable
    @user = @subscribable.subscribable_buyer

    @subject = subject_for(@customer, :subscription_trial_expired, 'Trial expired')

    mail(to: @subscribable.subscribable_buyer.email, subject: @subject)
  end
end

#subscription_trialing(subscribable, atts = {}) ⇒ Object

Sent by the effective_orders:notify_trial_users rake task.



153
154
155
156
157
158
159
160
161
162
163
164
# File 'app/mailers/effective/orders_mailer.rb', line 153

def subscription_trialing(subscribable, atts = {})
  around_mail_action(:subscription_trialing, subscribable, atts) do
    return true unless EffectiveOrders.mailer[:send_subscription_trialing]

    @subscribable = subscribable
    @user = @subscribable.subscribable_buyer

    @subject = subject_for(@customer, :subscription_trialing, 'Trial is active')

    mail(to: @subscribable.subscribable_buyer.email, subject: @subject)
  end
end

#subscription_updated(customer_param, atts = {}) ⇒ Object

Sent by the customer.subscription.updated webhook event



123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'app/mailers/effective/orders_mailer.rb', line 123

def subscription_updated(customer_param, atts = {})
  around_mail_action(:subscription_updated, customer_param, atts) do
    return true unless EffectiveOrders.mailer[:send_subscription_updated]

    @customer = (customer_param.kind_of?(Effective::Customer) ? customer_param : Effective::Customer.find(customer_param))
    @subscriptions = @customer.subscriptions
    @user = @customer.user

    @subject = subject_for(@customer, :subscription_updated, 'Subscription Changed')

    mail(to: @customer.user.email, subject: @subject)
  end
end