From 34c9a39ea50e84c8b283469ee1e5526267a8e0f3 Mon Sep 17 00:00:00 2001 From: Charlotte Van Petegem Date: Wed, 19 Apr 2023 20:39:24 +0200 Subject: [PATCH] Add EPC QR code to registration emails --- Gemfile | 3 +- Gemfile.lock | 39 +++++++++--------- app/actions/generate_epc_qr.rb | 40 +++++++++++++++++++ app/mailers/registration_mailer.rb | 3 ++ .../confirm_registration.html.erb | 6 +++ test/mailers/registration_mailer_test.rb | 2 - 6 files changed, 70 insertions(+), 23 deletions(-) create mode 100644 app/actions/generate_epc_qr.rb diff --git a/Gemfile b/Gemfile index b1a8fae8..5851bf3d 100644 --- a/Gemfile +++ b/Gemfile @@ -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' @@ -67,6 +65,7 @@ gem 'iban-tools' # Barcodes gem 'barby' gem 'chunky_png' +gem 'rqrcode' # Pagination gem 'will_paginate', '~> 3.0' diff --git a/Gemfile.lock b/Gemfile.lock index 5ea6bd64..6c1b2b00 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -435,7 +436,6 @@ DEPENDENCIES barby bcrypt_pbkdf (>= 1.0, < 2.0) bootsnap - bundler (= 2.4.8) cancancan capistrano (~> 3.17) capistrano-docker! @@ -466,6 +466,7 @@ DEPENDENCIES rails-erd rails_style! record_tag_helper + rqrcode rubocop-minitest sass-rails sdoc diff --git a/app/actions/generate_epc_qr.rb b/app/actions/generate_epc_qr.rb new file mode 100644 index 00000000..9c38d62e --- /dev/null +++ b/app/actions/generate_epc_qr.rb @@ -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 diff --git a/app/mailers/registration_mailer.rb b/app/mailers/registration_mailer.rb index be0113f1..c8cdf53d 100644 --- a/app/mailers/registration_mailer.rb +++ b/app/mailers/registration_mailer.rb @@ -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 diff --git a/app/views/registration_mailer/confirm_registration.html.erb b/app/views/registration_mailer/confirm_registration.html.erb index 158f4737..88213f72 100644 --- a/app/views/registration_mailer/confirm_registration.html.erb +++ b/app/views/registration_mailer/confirm_registration.html.erb @@ -11,6 +11,9 @@

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.

+

Je kan met de meeste bank-apps ook deze QR-code scannen:

+ <%= image_tag attachments['epc.png'].url %> +

Gelieve ten laatste 3 dagen voor het evenement te betalen. 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.

U kan deze informatie ook altijd herbekijken op deze pagina. @@ -31,6 +34,9 @@

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.

+

You can also use most banking apps to scan this QR code:

+ <%= image_tag attachments['epc.png'].url %> +

Please pay at least 3 days before the event. 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.

You can always view this information on this page. diff --git a/test/mailers/registration_mailer_test.rb b/test/mailers/registration_mailer_test.rb index 31ac6038..cc98dd5a 100644 --- a/test/mailers/registration_mailer_test.rb +++ b/test/mailers/registration_mailer_test.rb @@ -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