Class: Effective::OrdersMailer

Inherits:
Object
  • Object
show all
Includes:
EffectiveMailer
Defined in:
app/mailers/effective/orders_mailer.rb

Instance Method Summary collapse

Instance Method Details

#order_email(resource, opts = {}) ⇒ Object

This is the new order email It’s sent from like 15 different places in 15 different ways Has to be aware of events and registrations, applicants, renewals, etc Has to be aware of deferred payments, delayed payments, requests for payment, purchased, declined etc



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

def order_email(resource, opts = {})
  raise('expected an Effective::Order') unless resource.kind_of?(Effective::Order)

  @order = resource
  @order_email = Effective::OrderEmail.new(resource, opts)

  subject = subject_for(__method__, @order_email.subject, @order, opts)
  headers = headers_for(@order, opts)

  mail(to: @order_email.to, cc: @order_email.cc, subject: subject, **headers)
end

#order_email_to_admin(resource, opts = {}) ⇒ Object

Same as above but sent to admin



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

def order_email_to_admin(resource, opts = {})
  raise('expected an Effective::Order') unless resource.kind_of?(Effective::Order)

  @order = resource
  @order_email = Effective::OrderEmail.new(resource, opts)

  subject = subject_for(__method__, @order_email.subject, @order, opts)
  headers = headers_for(@order, opts)

  mail(to: mailer_admin, subject: subject, **headers)
end

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

This is only called by EffectiveQbSync



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

def order_error(order: nil, error: nil, to: nil, from: nil, subject: nil, template: 'order_error')
  raise('expected an Effective::Order') unless order.kind_of?(Effective::Order)

  @order = order
  @error = error.to_s
  opts = {}

  to ||= EffectiveOrders.mailer_admin
  from ||= EffectiveOrders.mailer_sender
  subject ||= subject_for(__method__,"An error occurred with order: ##{@order.to_param}", @order, opts)
  headers = headers_for(@order, opts)

  mail(to: to, from: from, subject: subject, **headers) do |format|
    format.html { render(template) }
  end
end

#refund_notification_to_admin(resource, opts = {}) ⇒ Object

This is sent to admin when someone Accepts Refund



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

def refund_notification_to_admin(resource, opts = {})
  raise('expected an Effective::Order') unless resource.kind_of?(Effective::Order)

  @order = resource
  subject = subject_for(__method__, "New Refund: ##{@order.to_param}", resource, opts)
  headers = headers_for(resource, opts)

  mail(to: mailer_admin, subject: subject, **headers)
end

#subscription_canceled(resource, opts = {}) ⇒ Object

Sent by the invoice.payment_failed webhook event



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

def subscription_canceled(resource, opts = {})
  raise('expected an Effective::Customer') unless resource.kind_of?(Effective::Customer)

  @customer = resource
  subject = subject_for(__method__, 'Subscription canceled', resource, opts)
  headers = headers_for(resource, opts)

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

#subscription_created(resource, opts = {}) ⇒ Object

Sent by the customer.subscription.created webhook event



73
74
75
76
77
78
79
80
81
# File 'app/mailers/effective/orders_mailer.rb', line 73

def subscription_created(resource, opts = {})
  raise('expected an Effective::Customer') unless resource.kind_of?(Effective::Customer)

  @customer = resource
  subject = subject_for(__method__, 'New Subscription', resource, opts)
  headers = headers_for(resource, opts)

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

#subscription_event_to_admin(event, resource, opts = {}) ⇒ Object



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

def subscription_event_to_admin(event, resource, opts = {})
  raise('expected an event') unless event.present?
  raise('expected an Effective::Customer') unless resource.kind_of?(Effective::Customer)

  @event = event
  @customer = resource

  subject = subject_for(__method__, "Subscription event - #{@event} - #{@customer}", resource, opts)
  headers = headers_for(resource, opts)

  mail(to: mailer_admin, subject: subject, **headers)
end

#subscription_payment_failed(resource, opts = {}) ⇒ Object

Sent by the invoice.payment_failed webhook event



62
63
64
65
66
67
68
69
70
# File 'app/mailers/effective/orders_mailer.rb', line 62

def subscription_payment_failed(resource, opts = {})
  raise('expected an Effective::Customer') unless resource.kind_of?(Effective::Customer)

  @customer = resource
  subject = subject_for(__method__, 'Payment failed - please update your card details', resource, opts)
  headers = headers_for(resource, opts)

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

#subscription_payment_succeeded(resource, opts = {}) ⇒ Object

Sent by the invoice.payment_succeeded webhook event



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

def subscription_payment_succeeded(resource, opts = {})
  raise('expected an Effective::Customer') unless resource.kind_of?(Effective::Customer)

  @customer = resource
  subject = subject_for(__method__, 'Thank you for your payment', resource, opts)
  headers = headers_for(resource, opts)

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

#subscription_trial_expired(resource, opts = {}) ⇒ Object

Sent by the effective_orders:notify_trial_users rake task.



117
118
119
120
121
122
123
124
125
# File 'app/mailers/effective/orders_mailer.rb', line 117

def subscription_trial_expired(resource, opts = {})
  raise('expected a subscribable resource') unless resource.respond_to?(:subscribable_buyer)

  @subscribable = resource
  subject = subject_for(__method__, 'Trial expired', resource, opts)
  headers = headers_for(resource, opts)

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

#subscription_trialing(resource, opts = {}) ⇒ Object

Sent by the effective_orders:notify_trial_users rake task.



106
107
108
109
110
111
112
113
114
# File 'app/mailers/effective/orders_mailer.rb', line 106

def subscription_trialing(resource, opts = {})
  raise('expected a subscribable resource') unless resource.respond_to?(:subscribable_buyer)

  @subscribable = resource
  subject = subject_for(__method__, 'Trial is active', resource, opts)
  headers = headers_for(resource, opts)

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

#subscription_updated(resource, opts = {}) ⇒ Object

Sent by the customer.subscription.updated webhook event



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

def subscription_updated(resource, opts = {})
  raise('expected an Effective::Customer') unless resource.kind_of?(Effective::Customer)

  @customer = resource
  subject = subject_for(__method__, 'Subscription Changed', resource, opts)
  headers = headers_for(resource, opts)

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