Add invoice mailer

This commit is contained in:
Martin Lensment 2015-04-22 12:56:14 +03:00
parent 2bc55e423c
commit 49be49ea63
13 changed files with 60 additions and 12 deletions

View file

@ -21,6 +21,8 @@ class Registrar::InvoicesController < RegistrarController
@invoice.billing_email = params[:invoice][:billing_email]
if @invoice.forward
pdf = @invoice.pdf(render_to_string('pdf', layout: false))
InvoiceMailer.invoice_email(@invoice, pdf).deliver_now
flash[:notice] = t('invoice_forwared')
redirect_to([:registrar, @invoice])
else
@ -31,10 +33,8 @@ class Registrar::InvoicesController < RegistrarController
def download_pdf
# render 'pdf', layout: false
kit = PDFKit.new(render_to_string('pdf', layout: false))
pdf = kit.to_pdf
send_data pdf, filename: "invoice-#{@invoice.number}.pdf"
pdf = @invoice.pdf(render_to_string('pdf', layout: false))
send_data pdf, filename: @invoice.pdf_name
end
private

View file

@ -0,0 +1,4 @@
class ApplicationMailer < ActionMailer::Base
default from: 'noreply@internet.ee'
layout 'mailer'
end

View file

@ -0,0 +1,6 @@
class InvoiceMailer < ApplicationMailer
def invoice_email(invoice, pdf)
attachments[invoice.pdf_name] = pdf
mail(to: invoice.billing_email, subject: invoice)
end
end

View file

@ -22,7 +22,7 @@ class Invoice < ActiveRecord::Base
end
def to_s
I18n.t('invoice_no', no: id)
I18n.t('invoice_no', no: number)
end
def number
@ -46,6 +46,15 @@ class Invoice < ActiveRecord::Base
Country.new(buyer_country_code)
end
def pdf(html)
kit = PDFKit.new(html)
kit.to_pdf
end
def pdf_name
"invoice-#{number}.pdf"
end
def forward
return false unless valid?
return false unless billing_email

View file

@ -0,0 +1 @@
You have a new invoice html

View file

@ -0,0 +1 @@
You have a new invoice text

View file

@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<meta content='text/html; charset=UTF-8' http-equiv='Content-Type' />
</head>
<body>
<h1>EIS</h1>
<%= yield %>
</body>
</html>

View file

@ -0,0 +1,2 @@
this is email text layout
<%= yield %>

View file

@ -35,6 +35,13 @@ key_path: '/home/registry/registry/shared/ca/private/webclient.key.pem'
epp_hostname: 'registry.gitlab.eu'
repp_url: 'https://repp.gitlab.eu/repp/v1/'
# SMTP configuration
address: 'smtp.mandrillapp.com'
port: '587'
user_name: 'domify-test'
password: 'zVGZvd9D5NHYZ4I99h92nw'
domain: 'registry.gitlab.eu'
# autotest config overwrites
test:
webclient_ip: '127.0.0.1' # it should match to localhost ip address

View file

@ -53,5 +53,19 @@ module Registry
g.javascripts false
g.helper false
end
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
config.action_mailer.smtp_settings = {
address: ENV['address'],
port: ENV['port'],
enable_starttls_auto: true,
user_name: ENV['user_name'],
password: ENV['password'],
authentication: 'login',
domain: ENV['domain']
}
end
end

View file

@ -80,7 +80,4 @@ Rails.application.configure do
# Do not dump schema after migrations.
config.active_record.dump_schema_after_migration = false
# TODO: Change this:
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
end

View file

@ -35,7 +35,7 @@ Rails.application.configure do
# Raises error for missing translations
# config.action_view.raise_on_missing_translations = true
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
config.action_mailer.default_url_options = { host: 'localhost:8081' }
# for finding database optimization
config.after_initialize do

View file

@ -80,7 +80,4 @@ Rails.application.configure do
# Do not dump schema after migrations.
config.active_record.dump_schema_after_migration = false
# TODO: Change this:
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
end