Class: Effective::OrdersMailer
- Inherits:
-
Object
- Object
- Effective::OrdersMailer
- Includes:
- EffectiveMailer
- Defined in:
- app/mailers/effective/orders_mailer.rb
Instance Method Summary collapse
-
#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.
-
#order_email_to_admin(resource, opts = {}) ⇒ Object
Same as above but sent to admin.
-
#order_error(order: nil, error: nil, to: nil, from: nil, subject: nil, template: 'order_error') ⇒ Object
This is only called by EffectiveQbSync.
-
#refund_notification_to_admin(resource, opts = {}) ⇒ Object
This is sent to admin when someone Accepts Refund.
-
#subscription_canceled(resource, opts = {}) ⇒ Object
Sent by the invoice.payment_failed webhook event.
-
#subscription_created(resource, opts = {}) ⇒ Object
Sent by the customer.subscription.created webhook event.
- #subscription_event_to_admin(event, resource, opts = {}) ⇒ Object
-
#subscription_payment_failed(resource, opts = {}) ⇒ Object
Sent by the invoice.payment_failed webhook event.
-
#subscription_payment_succeeded(resource, opts = {}) ⇒ Object
Sent by the invoice.payment_succeeded webhook event.
-
#subscription_trial_expired(resource, opts = {}) ⇒ Object
Sent by the effective_orders:notify_trial_users rake task.
-
#subscription_trialing(resource, opts = {}) ⇒ Object
Sent by the effective_orders:notify_trial_users rake task.
-
#subscription_updated(resource, opts = {}) ⇒ Object
Sent by the customer.subscription.updated webhook event.
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 23 24 25 26 27 |
# 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) cc = @order_email.cc if @order_email.event_registrants_cancelled? cc = (Array(mailer_admin) + Array(cc)).map(&:presence).compact end mail(to: @order_email.to, cc: cc, subject: subject, **headers) end |
#order_email_to_admin(resource, opts = {}) ⇒ Object
Same as above but sent to admin
30 31 32 33 34 35 36 37 38 39 40 |
# File 'app/mailers/effective/orders_mailer.rb', line 30 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
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'app/mailers/effective/orders_mailer.rb', line 146 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
43 44 45 46 47 48 49 50 51 |
# File 'app/mailers/effective/orders_mailer.rb', line 43 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
100 101 102 103 104 105 106 107 108 |
# File 'app/mailers/effective/orders_mailer.rb', line 100 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
78 79 80 81 82 83 84 85 86 |
# File 'app/mailers/effective/orders_mailer.rb', line 78 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
132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'app/mailers/effective/orders_mailer.rb', line 132 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
67 68 69 70 71 72 73 74 75 |
# File 'app/mailers/effective/orders_mailer.rb', line 67 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
56 57 58 59 60 61 62 63 64 |
# File 'app/mailers/effective/orders_mailer.rb', line 56 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.
122 123 124 125 126 127 128 129 130 |
# File 'app/mailers/effective/orders_mailer.rb', line 122 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.
111 112 113 114 115 116 117 118 119 |
# File 'app/mailers/effective/orders_mailer.rb', line 111 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
89 90 91 92 93 94 95 96 97 |
# File 'app/mailers/effective/orders_mailer.rb', line 89 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 |