mirror of
https://github.com/internetee/registry.git
synced 2025-08-14 21:43:50 +02:00
Add invoice mailer
This commit is contained in:
parent
2bc55e423c
commit
49be49ea63
13 changed files with 60 additions and 12 deletions
|
@ -21,6 +21,8 @@ class Registrar::InvoicesController < RegistrarController
|
||||||
@invoice.billing_email = params[:invoice][:billing_email]
|
@invoice.billing_email = params[:invoice][:billing_email]
|
||||||
|
|
||||||
if @invoice.forward
|
if @invoice.forward
|
||||||
|
pdf = @invoice.pdf(render_to_string('pdf', layout: false))
|
||||||
|
InvoiceMailer.invoice_email(@invoice, pdf).deliver_now
|
||||||
flash[:notice] = t('invoice_forwared')
|
flash[:notice] = t('invoice_forwared')
|
||||||
redirect_to([:registrar, @invoice])
|
redirect_to([:registrar, @invoice])
|
||||||
else
|
else
|
||||||
|
@ -31,10 +33,8 @@ class Registrar::InvoicesController < RegistrarController
|
||||||
def download_pdf
|
def download_pdf
|
||||||
# render 'pdf', layout: false
|
# render 'pdf', layout: false
|
||||||
|
|
||||||
kit = PDFKit.new(render_to_string('pdf', layout: false))
|
pdf = @invoice.pdf(render_to_string('pdf', layout: false))
|
||||||
pdf = kit.to_pdf
|
send_data pdf, filename: @invoice.pdf_name
|
||||||
|
|
||||||
send_data pdf, filename: "invoice-#{@invoice.number}.pdf"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
4
app/mailers/application_mailer.rb
Normal file
4
app/mailers/application_mailer.rb
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
class ApplicationMailer < ActionMailer::Base
|
||||||
|
default from: 'noreply@internet.ee'
|
||||||
|
layout 'mailer'
|
||||||
|
end
|
6
app/mailers/invoice_mailer.rb
Normal file
6
app/mailers/invoice_mailer.rb
Normal 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
|
|
@ -22,7 +22,7 @@ class Invoice < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_s
|
def to_s
|
||||||
I18n.t('invoice_no', no: id)
|
I18n.t('invoice_no', no: number)
|
||||||
end
|
end
|
||||||
|
|
||||||
def number
|
def number
|
||||||
|
@ -46,6 +46,15 @@ class Invoice < ActiveRecord::Base
|
||||||
Country.new(buyer_country_code)
|
Country.new(buyer_country_code)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def pdf(html)
|
||||||
|
kit = PDFKit.new(html)
|
||||||
|
kit.to_pdf
|
||||||
|
end
|
||||||
|
|
||||||
|
def pdf_name
|
||||||
|
"invoice-#{number}.pdf"
|
||||||
|
end
|
||||||
|
|
||||||
def forward
|
def forward
|
||||||
return false unless valid?
|
return false unless valid?
|
||||||
return false unless billing_email
|
return false unless billing_email
|
||||||
|
|
1
app/views/invoice_mailer/invoice_email.html.erb
Normal file
1
app/views/invoice_mailer/invoice_email.html.erb
Normal file
|
@ -0,0 +1 @@
|
||||||
|
You have a new invoice html
|
1
app/views/invoice_mailer/invoice_email.text.erb
Normal file
1
app/views/invoice_mailer/invoice_email.text.erb
Normal file
|
@ -0,0 +1 @@
|
||||||
|
You have a new invoice text
|
10
app/views/layouts/mailer.html.erb
Normal file
10
app/views/layouts/mailer.html.erb
Normal 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>
|
2
app/views/layouts/mailer.text.erb
Normal file
2
app/views/layouts/mailer.text.erb
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
this is email text layout
|
||||||
|
<%= yield %>
|
|
@ -35,6 +35,13 @@ key_path: '/home/registry/registry/shared/ca/private/webclient.key.pem'
|
||||||
epp_hostname: 'registry.gitlab.eu'
|
epp_hostname: 'registry.gitlab.eu'
|
||||||
repp_url: 'https://repp.gitlab.eu/repp/v1/'
|
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
|
# autotest config overwrites
|
||||||
test:
|
test:
|
||||||
webclient_ip: '127.0.0.1' # it should match to localhost ip address
|
webclient_ip: '127.0.0.1' # it should match to localhost ip address
|
||||||
|
|
|
@ -53,5 +53,19 @@ module Registry
|
||||||
g.javascripts false
|
g.javascripts false
|
||||||
g.helper false
|
g.helper false
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|
|
@ -80,7 +80,4 @@ Rails.application.configure do
|
||||||
|
|
||||||
# Do not dump schema after migrations.
|
# Do not dump schema after migrations.
|
||||||
config.active_record.dump_schema_after_migration = false
|
config.active_record.dump_schema_after_migration = false
|
||||||
|
|
||||||
# TODO: Change this:
|
|
||||||
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -35,7 +35,7 @@ Rails.application.configure do
|
||||||
# Raises error for missing translations
|
# Raises error for missing translations
|
||||||
# config.action_view.raise_on_missing_translations = true
|
# 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
|
# for finding database optimization
|
||||||
config.after_initialize do
|
config.after_initialize do
|
||||||
|
|
|
@ -80,7 +80,4 @@ Rails.application.configure do
|
||||||
|
|
||||||
# Do not dump schema after migrations.
|
# Do not dump schema after migrations.
|
||||||
config.active_record.dump_schema_after_migration = false
|
config.active_record.dump_schema_after_migration = false
|
||||||
|
|
||||||
# TODO: Change this:
|
|
||||||
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue