diff --git a/Gemfile b/Gemfile index 2634317f..382999d1 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 a3c1e1a3..b81ef18b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) @@ -435,7 +439,6 @@ DEPENDENCIES barby bcrypt_pbkdf (>= 1.0, < 2.0) bootsnap - bundler (= 2.4.8) cancancan capistrano (~> 3.17) capistrano-docker! @@ -466,6 +469,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..73c40935 --- /dev/null +++ b/app/actions/generate_epc_qr.rb @@ -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 diff --git a/app/controllers/registrations_controller.rb b/app/controllers/registrations_controller.rb index c8e7e756..7b5e6599 100644 --- a/app/controllers/registrations_controller.rb +++ b/app/controllers/registrations_controller.rb @@ -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 diff --git a/app/mailers/registration_mailer.rb b/app/mailers/registration_mailer.rb index be0113f1..1a5430dc 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.epc_data).call + mail to: "#{registration.name} <#{registration.email}>", subject: "Registration for #{registration.event.name}" end diff --git a/app/models/registration.rb b/app/models/registration.rb index 3bb650be..dea16531 100644 --- a/app/models/registration.rb +++ b/app/models/registration.rb @@ -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 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/app/views/registrations/show.html.erb b/app/views/registrations/show.html.erb index f6ed03f2..feec6a75 100644 --- a/app/views/registrations/show.html.erb +++ b/app/views/registrations/show.html.erb @@ -49,6 +49,10 @@ +

+ +
+

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 diff --git a/test/mailers/registration_mailer_test.rb b/test/mailers/registration_mailer_test.rb index 31ac6038..5baa38db 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) + assert_match(/Een signatuur/, email.parts.first.parts.first.body.to_s) end test "signature of ticket emails can be branded" do