Skip to content

Commit

Permalink
Merge pull request #694 from ZeusWPI/feat/epc_in_mail
Browse files Browse the repository at this point in the history
Add EPC QR code to registration emails and ticket overview
  • Loading branch information
redfast00 authored Aug 7, 2023
2 parents 8dc91c4 + 0f0f39d commit fdc8269
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 6 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
6 changes: 5 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,10 @@ GEM
actionpack (>= 5.2)
railties (>= 5.2)
rexml (3.2.5)
rqrcode (2.1.2)
chunky_png (~> 1.0)
rqrcode_core (~> 1.0)
rqrcode_core (1.2.0)
rubocop (1.50.2)
json (~> 2.3)
parallel (~> 1.10)
Expand Down Expand Up @@ -435,7 +439,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 +469,7 @@ DEPENDENCIES
rails-erd
rails_style!
record_tag_helper
rqrcode
rubocop-minitest
sass-rails
sdoc
Expand Down
22 changes: 22 additions & 0 deletions app/actions/generate_epc_qr.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# frozen_string_literal: true

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

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

def call
qrcode = Barby::QrCode.new(@epc_data)

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

qrcode_canvas = png_outputter.to_image
qrcode_canvas.to_blob
end
end
1 change: 1 addition & 0 deletions app/controllers/registrations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def show

@event = @registration.event
@barcode = GenerateHtmlBarcodes.new(@registration.barcode_data).call
@qr_code = GenerateEpcQr.new(@registration.epc_data).call
end

def new
Expand Down
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.epc_data).call

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

Expand Down
17 changes: 17 additions & 0 deletions app/models/registration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,23 @@ def generate_barcode
self.save!
end

def epc_data
<<~HEREDOC
BCD
002
1
SCT
#{event.club.name}
#{event.bank_number}
EUR#{format '%.2f', to_pay}
#{payment_code}
HEREDOC
end

def self.find_payment_code_from_csv(csvline)
match = /GAN\d+/.match(csvline)
if match
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
4 changes: 4 additions & 0 deletions app/views/registrations/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@
</tr>
</table>

<div>
<img src="data:image/png;base64,<%= Base64.encode64 @qr_code %>">
</div>

<p>
Om uw ticket te ontvangen via e-mail, schrijft u <strong><%= nice_amount @registration.to_pay %> euro</strong>
over op het rekeningnummer <strong><%= @registration.event.bank_number || "our bank account" %></strong>. Plaats de code
Expand Down
4 changes: 1 addition & 3 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)
assert_match(/Een signatuur/, email.parts.first.parts.first.body.to_s)
end

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

0 comments on commit fdc8269

Please sign in to comment.