im getting this error
config.action_mailer.delivery_method = :mailjet_stmp
whenever I open the view where mailjet is supposed to send an email, I set it up usinf mailjet gem and the mailer initializer, i will add the controller and initializer as well as the route and actual view. Please if there is anything missing let me know so i can provide any extra info to yall. routes.rb:
Rails.application.routes.draw do
unrelated routes
post '/send_invoice', to: "invoices#new"
end
controller:
class InvoicesController < ApplicationController
before_action :current_biz
skip_before_action :verify_authenticity_token
def index
if !current_user
redirect_to new_user_session_path
else
@invoices = current_biz.invoices
end
end
def new
invoice = Invoice.new(invoice_params)
build_invoice
send_invoice(invoice)
end
def create
build_invoice
save_invoice or render :new
end
def update
@invoice = Invoice.find_by(id: params[:id])
if @invoice.update(invoice_params)
redirect_to request.referrer
else
render request.referrer
end
end
private
def current_biz
@biz = Business.find_by(id: params[:business_id])
end
def invoice_params
invoice_params = params[:invoice]
invoice_params ? invoice_params.permit(:title, :services, :payer_name, :payer_email, :paid, :price, :business_id, :biller_name,:business_name, :biller_email, :reference, :paypal_username) : {}
end
def build_invoice
@invoice ||= invoice_scope.build
@invoice.attributes = invoice_params
end
def save_invoice
if @invoice.save
redirect_to business_invoices_path(@biz)
end
end
def invoice_scope
@biz.invoices
end
def send_invoice(invoice, error = false)
mail = Mailjet::Send.create(messages: [{
'From'=> {
'Email'=> '[email protected]',
'Name'=> 'my name'
},
'To'=> [
{
'Email'=> "#{invoice.payer_email}",
'Name'=> "#{invoice.payer_name}"
}
],
'Subject'=> "Invoice from #{invoice.business_name}",
'HTMLPart'=> template(invoice),
}]
)
p mail.attributes['Messages']
end
def template(invoice)
"
<h3>Hey #{invoice.payer_name}!</h3>
<p> #{invoice.business_name} has send you an invoice with the title: '#{invoice.title}' for a total of #{invoice.price}</p>
<p>You can pay the outstanding bill with the link below:</p>
<a href='https://www.paypal.me/#{invoice.paypal_username}/#{invoice.price}' target='_blank' rel='noopener'><button type='button'>Pay!</button></a>
<p>If this button does not work, you can copy and paste this link in the browser:
https://www.paypal.me/#{invoice.paypal_username}/#{invoice.price}<br>
</p>
"
end
end
the initilizer:
Mailjet.configure do |config|
config.api_key = ENV["MAILJET_PUBLIC"]
config.secret_key = ENV["MAILJET_PRIVATE"]
config.default_from = '[email protected]'
config.api_version = 'v3.1'
end
and the view:
<div class="w-50 m-auto m-top">
<button onClick='addServices()'>Add Services</button>
<%= form_for [@biz, @invoice], url: send_invoice_path do |f| %>
<%= f.hidden_field :reference, value: reference_generator %>
<div class='form-group'>
<%= f.label :bill_title %>
<%= f.text_field :title, class: 'form-control', required: true %>
</div>
<div class='form-group'>
<%= f.label :biller_name %>
<%= f.text_field :biller_name, class: 'form-control', required: true %>
</div>
<div class='form-group'>
<%= f.label :biller_email %>
<%= f.text_field :biller_email, class: 'form-control', required: true %>
</div>
<div class='form-group'>
<%= f.label :business_name %>
<%= f.select(:business_name, user_businesses ,class: 'form-control', required: true) %>
</div>
<div class='row services-row'>
<div class='col-8'>
<%= f.label :services %>
<%= f.text_field :services, class: 'form-control' %>
</div>
<div class='col-4'>
<%= f.label :amount %>
<%= f.number_field :price, class: 'form-control service-price', onblur: 'addValues()', placeholder: "$", required: true %>
</div>
</div>
<div class='form-group'>
<%= f.label :payer_name %>
<%= f.text_field :payer_name, class: 'form-control', required: true %>
</div>
<div class='form-group'>
<%= f.label :payer_email %>
<%= f.text_field :payer_email, class: 'form-control', required: true %>
</div>
<div class='form-group'>
<%= f.label :paypal_username %>
<%= f.text_field :paypal_username, class: 'form-control', required: true %>
</div>
<div class="form-check">
<%= f.check_box :paid, { class: 'form-check-input' } %>
<%= f.label :paid %>
</div>
<div class='row'>
Total:
<span class='total'>
</span>
</div>
<%= f.submit class: 'btn btn-primary' %>
<% end %>
</div>