# frozen_string_literal: true require 'qrcode_pix_ruby' def generate_html_with(env) qrcode_data = Rack::Request.new(env).params payload = '' data_uri = '' pix = QrcodePixRuby::Payload.new unless qrcode_data.empty? pix.pix_key = qrcode_data['pix_key'] if !qrcode_data['pix_key'].nil? && !qrcode_data['pix_key'].empty? pix.url = qrcode_data['url'] if !qrcode_data['url'].nil? && !qrcode_data['url'].empty? pix.description = qrcode_data['description'] if !qrcode_data['description'].nil? && !qrcode_data['description'].empty? pix.merchant_name = qrcode_data['merchant_name'] if !qrcode_data['merchant_name'].nil? && !qrcode_data['merchant_name'].empty? pix.merchant_city = qrcode_data['merchant_city'] if !qrcode_data['merchant_city'].nil? && !qrcode_data['merchant_city'].empty? pix.transaction_id = qrcode_data['transaction_id'] if !qrcode_data['transaction_id'].nil? && !qrcode_data['transaction_id'].empty? pix.amount = qrcode_data['amount'] if !qrcode_data['amount'].nil? && !qrcode_data['amount'].empty? pix.currency = qrcode_data['currency'] if !qrcode_data['currency'].nil? && !qrcode_data['currency'].empty? pix.country_code = qrcode_data['country_code'] if !qrcode_data['country_code'].nil? && !qrcode_data['country_code'].empty? pix.postal_code = qrcode_data['postal_code'] if !qrcode_data['postal_code'].nil? && !qrcode_data['postal_code'].empty? pix.repeatable = qrcode_data['repeatable'] == 't' if !qrcode_data['repeatable'].nil? && !qrcode_data['repeatable'].empty? payload = <<-HTML
HTML data_uri = "" end StringIO.new <<-HTML QRCode Pix Ruby - Demo App

QRCode Pix Ruby - Demo App



For more details check the official repo: https://github.com/pedrofurtado/qrcode_pix_ruby



QRCode informations

For static Pix, please fill the 'Pix key' field.
For dynamic Pix, fill the 'URL' field.
Do not fill both fields.
Formats of Pix keys:
CPF: 12345678910 (only numbers)
Phone: +5511912345678 (+55 + DDD + phone, only numbers)
Email: example@mail.com
Random: a6hf7jdk3nc8iK (generated by bank)
or

Only numbers and simple characters, without whitespaces.
Only numbers with 2 decimal places.
Only numbers.
Preview

#{payload} #{data_uri}
HTML end run lambda { |env| [ 200, { 'Content-Type' => 'text/html' }, generate_html_with(env) ] }