Skip to content

Commit

Permalink
Add EPC QR code to registration emails
Browse files Browse the repository at this point in the history
  • Loading branch information
chvp committed Apr 19, 2023
1 parent 2f33c6b commit 34c9a39
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 23 deletions.
3 changes: 1 addition & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ source 'https://rubygems.org'

gem 'dotenv-rails'

gem 'bundler', '= 2.4.8'

gem 'bcrypt_pbkdf', '>= 1.0', '< 2.0'

gem 'ed25519', '>= 1.2', '< 2.0'
Expand Down Expand Up @@ -67,6 +65,7 @@ gem 'iban-tools'
# Barcodes
gem 'barby'
gem 'chunky_png'
gem 'rqrcode'

# Pagination
gem 'will_paginate', '~> 3.0'
Expand Down
39 changes: 20 additions & 19 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ GIT

GIT
remote: https://github.com/ZeusWPI/rails_style.git
revision: 33ea5008e49be142ad490c5b572ef4b3f6436f23
revision: 7101522ddc0f7e4cf13235a6e7a7318f04253443
specs:
rails_style (0.0.1)
bundler (>= 2.1.4)
Expand Down Expand Up @@ -161,7 +161,7 @@ GEM
rails-dom-testing (>= 1, < 3)
railties (>= 4.2.0)
thor (>= 0.14, < 2.0)
json (2.6.3)
json (2.6.2)
jwt (2.3.0)
launchy (2.5.0)
addressable (~> 2.7)
Expand Down Expand Up @@ -232,8 +232,8 @@ GEM
paper_trail (14.0.0)
activerecord (>= 6.0)
request_store (~> 1.4)
parallel (1.23.0)
parser (3.2.2.0)
parallel (1.22.1)
parser (3.1.2.1)
ast (~> 2.4.1)
poltergeist (1.18.1)
capybara (>= 2.1, < 4)
Expand Down Expand Up @@ -300,40 +300,41 @@ GEM
actionview (>= 5)
redis-client (0.14.1)
connection_pool
regexp_parser (2.8.0)
regexp_parser (2.6.0)
request_store (1.5.1)
rack (>= 1.4)
responders (3.1.0)
actionpack (>= 5.2)
railties (>= 5.2)
rexml (3.2.5)
rubocop (1.50.2)
rqrcode (2.1.2)
chunky_png (~> 1.0)
rqrcode_core (~> 1.0)
rqrcode_core (1.2.0)
rubocop (1.36.0)
json (~> 2.3)
parallel (~> 1.10)
parser (>= 3.2.0.0)
parser (>= 3.1.2.1)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.28.0, < 2.0)
rubocop-ast (>= 1.20.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.28.0)
parser (>= 3.2.1.0)
rubocop-capybara (2.17.1)
rubocop (~> 1.41)
unicode-display_width (>= 1.4.0, < 3.0)
rubocop-ast (1.21.0)
parser (>= 3.1.1.0)
rubocop-minitest (0.22.2)
rubocop (>= 0.90, < 2.0)
rubocop-rails (2.19.1)
rubocop-rails (2.16.1)
activesupport (>= 4.2.0)
rack (>= 1.1)
rubocop (>= 1.33.0, < 2.0)
rubocop-rspec (2.20.0)
rubocop-rspec (2.13.2)
rubocop (~> 1.33)
rubocop-capybara (~> 2.17)
ruby-graphviz (1.2.5)
rexml
ruby-ole (1.2.12.2)
ruby-progressbar (1.13.0)
ruby-progressbar (1.11.0)
ruby2_keywords (0.0.5)
sass-rails (6.0.0)
sassc-rails (~> 2.1, >= 2.1.1)
Expand Down Expand Up @@ -397,7 +398,7 @@ GEM
concurrent-ruby (~> 1.0)
uglifier (4.2.0)
execjs (>= 0.3.0, < 3)
unicode-display_width (2.4.2)
unicode-display_width (2.3.0)
validates_timeliness (6.0.0)
activemodel (>= 6.0.0, < 7)
timeliness (>= 0.3.10, < 1)
Expand Down Expand Up @@ -435,7 +436,6 @@ DEPENDENCIES
barby
bcrypt_pbkdf (>= 1.0, < 2.0)
bootsnap
bundler (= 2.4.8)
cancancan
capistrano (~> 3.17)
capistrano-docker!
Expand Down Expand Up @@ -466,6 +466,7 @@ DEPENDENCIES
rails-erd
rails_style!
record_tag_helper
rqrcode
rubocop-minitest
sass-rails
sdoc
Expand Down
40 changes: 40 additions & 0 deletions app/actions/generate_epc_qr.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# frozen_string_literal: true

require 'barby/barcode/qr_code'
require 'barby/outputter/png_outputter'
require 'chunky_png'

class GenerateEpcQr
def initialize(registration)
@registration = registration
end

def call
qrcode = Barby::QrCode.new(epc_from_registration)

png_outputter = Barby::PngOutputter.new(qrcode)
png_outputter.xdim = 4
png_outputter.ydim = 4

barcode_canvas = png_outputter.to_image

barcode_canvas.to_blob
end

def epc_from_registration
<<~HEREDOC
BCD
002
1
SCT
#{@registration.event.club.name}
#{@registration.event.bank_number}
EUR#{format '%.2f', @registration.to_pay}
#{@registration.payment_code}
HEREDOC
end
end
3 changes: 3 additions & 0 deletions app/mailers/registration_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ class RegistrationMailer < ApplicationMailer

def confirm_registration(registration)
@registration = registration

attachments.inline['epc.png'] = GenerateEpcQr.new(@registration).call

mail to: "#{registration.name} <#{registration.email}>", subject: "Registration for #{registration.event.name}"
end

Expand Down
6 changes: 6 additions & 0 deletions app/views/registration_mailer/confirm_registration.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

<p>Om uw ticket te ontvangen via e-mail, schrijft u <%= nice_amount @registration.to_pay %> euro over op het rekeningnummer <%= @registration.event.bank_number || "our bank account" %>. Plaats de code "<%= @registration.payment_code %>" in de mededeling van de overschrijving (zonder aanhalingstekens). Als u de code vergeet mee te geven of niet correct vermeldt in de beschrijving, dan kunnen wij uw betaling niet verwerken en zal u uw ticket niet ontvangen. U mag maximaal één code ingeven per overschrijving.</p>

<p>Je kan met de meeste bank-apps ook deze QR-code scannen:</p>
<%= image_tag attachments['epc.png'].url %>

<p><strong>Gelieve ten laatste 3 dagen voor het evenement te betalen.</strong> Indien dit niet meer lukt, gelieve ons te contacteren via <%= mail_to @registration.event.contact_email, @registration.event.contact_email %> om een andere betalingswijze af te spreken. Eens we uw betaling verwerkt hebben, zal u uw ticket via e-mail ontvangen.</p>

<p>U kan deze informatie ook altijd herbekijken op <a href="<%= event_registration_url(@registration.event, @registration.token) %>">deze pagina</a>.
Expand All @@ -31,6 +34,9 @@

<p>To receive your ticket by mail, please transfer <%= nice_amount @registration.to_pay %> euro to <%= @registration.event.bank_number || "our bank account" %>. Place "<%= @registration.payment_code %>" in the description of your transfer (without the quotation marks). If you forget this code or you do not copy it correctly, we cannot process your payment and you will not receive your ticket. You are only allowed to enter one code per transfer.</p>

<p>You can also use most banking apps to scan this QR code:</p>
<%= image_tag attachments['epc.png'].url %>

<p><strong>Please pay at least 3 days before the event.</strong> If this is no longer possible, please contact us via <%= mail_to @registration.event.contact_email, @registration.event.contact_email %> to agree upon a different payment method. You will receive your ticket by mail once we processed your payment.</p>

<p>You can always view this information on <a href="<%= event_registration_url(@registration.event, @registration.token) %>">this page</a>.
Expand Down
2 changes: 0 additions & 2 deletions test/mailers/registration_mailer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ class RegistrationMailerTest < ActionMailer::TestCase

email = ActionMailer::Base.deliveries.last
assert_match(/Registration for/, email.subject)
# Both html and plaintext mail should contain the signature
assert_match(/Een signatuur/, email.parts.first.body.to_s)
assert_match(/Een signatuur/, email.parts.second.body.to_s)
end

test "signature of ticket emails can be branded" do
Expand Down

0 comments on commit 34c9a39

Please sign in to comment.