Skip to content

Commit

Permalink
Add EPC QR code to ticket show page
Browse files Browse the repository at this point in the history
  • Loading branch information
chvp committed Apr 19, 2023
1 parent 34c9a39 commit 0f0f39d
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 40 deletions.
33 changes: 18 additions & 15 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: 7101522ddc0f7e4cf13235a6e7a7318f04253443
revision: 33ea5008e49be142ad490c5b572ef4b3f6436f23
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.2)
json (2.6.3)
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.22.1)
parser (3.1.2.1)
parallel (1.23.0)
parser (3.2.2.0)
ast (~> 2.4.1)
poltergeist (1.18.1)
capybara (>= 2.1, < 4)
Expand Down Expand Up @@ -300,7 +300,7 @@ GEM
actionview (>= 5)
redis-client (0.14.1)
connection_pool
regexp_parser (2.6.0)
regexp_parser (2.8.0)
request_store (1.5.1)
rack (>= 1.4)
responders (3.1.0)
Expand All @@ -311,30 +311,33 @@ GEM
chunky_png (~> 1.0)
rqrcode_core (~> 1.0)
rqrcode_core (1.2.0)
rubocop (1.36.0)
rubocop (1.50.2)
json (~> 2.3)
parallel (~> 1.10)
parser (>= 3.1.2.1)
parser (>= 3.2.0.0)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.20.1, < 2.0)
rubocop-ast (>= 1.28.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 3.0)
rubocop-ast (1.21.0)
parser (>= 3.1.1.0)
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)
rubocop-minitest (0.22.2)
rubocop (>= 0.90, < 2.0)
rubocop-rails (2.16.1)
rubocop-rails (2.19.1)
activesupport (>= 4.2.0)
rack (>= 1.1)
rubocop (>= 1.33.0, < 2.0)
rubocop-rspec (2.13.2)
rubocop-rspec (2.20.0)
rubocop (~> 1.33)
rubocop-capybara (~> 2.17)
ruby-graphviz (1.2.5)
rexml
ruby-ole (1.2.12.2)
ruby-progressbar (1.11.0)
ruby-progressbar (1.13.0)
ruby2_keywords (0.0.5)
sass-rails (6.0.0)
sassc-rails (~> 2.1, >= 2.1.1)
Expand Down Expand Up @@ -398,7 +401,7 @@ GEM
concurrent-ruby (~> 1.0)
uglifier (4.2.0)
execjs (>= 0.3.0, < 3)
unicode-display_width (2.3.0)
unicode-display_width (2.4.2)
validates_timeliness (6.0.0)
activemodel (>= 6.0.0, < 7)
timeliness (>= 0.3.10, < 1)
Expand Down
28 changes: 5 additions & 23 deletions app/actions/generate_epc_qr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,18 @@
require 'chunky_png'

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

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

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
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
2 changes: 1 addition & 1 deletion app/mailers/registration_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class RegistrationMailer < ApplicationMailer
def confirm_registration(registration)
@registration = registration

attachments.inline['epc.png'] = GenerateEpcQr.new(@registration).call
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
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
2 changes: 1 addition & 1 deletion test/mailers/registration_mailer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class RegistrationMailerTest < ActionMailer::TestCase

email = ActionMailer::Base.deliveries.last
assert_match(/Registration for/, email.subject)
assert_match(/Een signatuur/, email.parts.first.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 0f0f39d

Please sign in to comment.