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



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

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



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

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



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

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}.compact)
  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



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

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}.compact)
  end
end

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

This is sent when someone chooses to Pay by Cheque



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

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}.compact)
  end
end

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

This is sent to admin when someone Accepts Refund



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

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



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

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



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

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



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

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



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

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



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

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.



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

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.



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

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



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

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