qrcode_pix_ruby 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a26d6b28fc1c602eb91dde02e301d9aa4fd0b8d96da53346c5055d53048640a2
4
- data.tar.gz: 5d8152a23e400f274cb4ee7028d87a59feaed5f262a86367d00c9dca57fbfc0b
3
+ metadata.gz: 4286f32be5f071b29e6f504834595f8f5dbc0ef1fdced824b76cfef429763c15
4
+ data.tar.gz: 24c12240f5df73f9dff448f1521401e990b0b2f7d3b78b4131a6e5294e14f61e
5
5
  SHA512:
6
- metadata.gz: fff792a1b81f8c20de135593999ddbc4a6fcc1068854eaa39c4df5f7538ebbc98d1535b36782c590be3711ecf24da8274ee4991557b5cee21f50156cc6c26157
7
- data.tar.gz: ce5ca98bf5ee7bf45466dc49096b2dfaa39475681dac2dbae7353ee0b853594efe60eeac912ff53aaf09a448be10c6c358960a0620f28a8e9d8fdd3c2d201142
6
+ metadata.gz: 71a8669277a170358742ffbb6bbfbb7dc6c0a4d6050640050ae793d329e6af5b535756672f27b156bd9dc22c0c1a465e371cdd0393097e09fdb2074101221f5c
7
+ data.tar.gz: 93e4f118bd2df45b4ed2f56a012808a0d63e40e40e9c5283ad34baf4550684997d434694f14b7227b52f0bdfda42933f5e862763a66be2dd355013d3d154d5c7
@@ -3,11 +3,22 @@ name: CI
3
3
  on: [push, pull_request]
4
4
 
5
5
  jobs:
6
- ci:
6
+ dockerfile:
7
+ runs-on: ubuntu-latest
8
+ steps:
9
+ - uses: actions/checkout@v2
10
+
11
+ - name: Build Dockerfile
12
+ run: docker build -t qrcode_pix_ruby_specs .
13
+
14
+ - name: Run tests inside Docker container
15
+ run: docker run -v $(pwd):/app/ -i qrcode_pix_ruby_specs
16
+
17
+ tests:
7
18
  runs-on: ubuntu-latest
8
19
  strategy:
9
20
  matrix:
10
- ruby-version: [2.7, 3.0]
21
+ ruby-version: [2.3, 2.4, 2.5, 2.6, 2.7, 3.0]
11
22
  env:
12
23
  CODECOV_TOKEN: ${{secrets.CODECOV_TOKEN}}
13
24
  steps:
@@ -0,0 +1,50 @@
1
+ name: Publish to Heroku
2
+
3
+ on:
4
+ push:
5
+ branches: [master]
6
+
7
+ jobs:
8
+ deploy:
9
+ runs-on: ubuntu-latest
10
+ steps:
11
+ - uses: actions/checkout@v2
12
+
13
+ - name: Install Ruby
14
+ uses: ruby/setup-ruby@v1
15
+ with:
16
+ ruby-version: 3.0
17
+
18
+ - name: Install dependencies
19
+ run: |
20
+ cd demo/
21
+ bundle install
22
+ bundle update qrcode_pix_ruby
23
+ cd ../
24
+
25
+ - name: Define Heroku credentials
26
+ run: |
27
+ cat > ~/.netrc <<EOF
28
+ machine api.heroku.com
29
+ login $HEROKU_EMAIL
30
+ password $HEROKU_API_KEY
31
+ machine git.heroku.com
32
+ login $HEROKU_EMAIL
33
+ password $HEROKU_API_KEY
34
+ EOF
35
+ env:
36
+ HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }}
37
+ HEROKU_EMAIL: ${{ secrets.HEROKU_EMAIL }}
38
+
39
+ - name: Define Heroku git remote
40
+ run: heroku git:remote --app $HEROKU_APP_NAME
41
+ env:
42
+ HEROKU_APP_NAME: ${{ secrets.HEROKU_APP_NAME }}
43
+
44
+ - name: Publish to Heroku
45
+ run: |
46
+ git config user.name 'Pedro Furtado'
47
+ git config user.email 'pedro.felipe.azevedo.furtado@gmail.com'
48
+ git add --all
49
+ git commit -m 'Publish to Heroku'
50
+ git push heroku `git subtree split --prefix demo master`:master --force
@@ -5,7 +5,7 @@ on:
5
5
  types: [created]
6
6
 
7
7
  jobs:
8
- publish-to-rubygems:
8
+ deploy:
9
9
  runs-on: ubuntu-latest
10
10
  steps:
11
11
  - uses: actions/checkout@v2
data/.gitignore CHANGED
@@ -1,4 +1,5 @@
1
1
  .rspec_status
2
- *.lock
2
+ /Gemfile.lock
3
3
  *.gem
4
4
  coverage/
5
+ *.log
data/.rubocop.yml ADDED
@@ -0,0 +1,38 @@
1
+ AllCops:
2
+ NewCops: enable
3
+ SuggestExtensions: false
4
+ Exclude:
5
+ - spec/*
6
+ - demo/*
7
+
8
+ Style/RegexpLiteral:
9
+ Enabled: false
10
+
11
+ Layout/LineLength:
12
+ Max: 120
13
+ Exclude:
14
+ - qrcode_pix_ruby.gemspec
15
+
16
+ Metrics/MethodLength:
17
+ Max: 20
18
+
19
+ Gemspec/RequiredRubyVersion:
20
+ Enabled: false
21
+
22
+ Style/Documentation:
23
+ Enabled: false
24
+
25
+ Metrics/AbcSize:
26
+ Enabled: false
27
+
28
+ Metrics/BlockNesting:
29
+ Enabled: false
30
+
31
+ Style/IfUnlessModifier:
32
+ Enabled: false
33
+
34
+ Metrics/CyclomaticComplexity:
35
+ Enabled: false
36
+
37
+ Metrics/PerceivedComplexity:
38
+ Enabled: false
data/CHANGELOG.md CHANGED
@@ -1,5 +1,26 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.4.0] - 2021-07-10
4
+
5
+ - Add URL option for PIX, in order to generate dynamic QR Codes
6
+
7
+ ## [0.3.4] - 2021-06-28
8
+
9
+ - Fix behavior of EMV field 'repeatable' (the logic was inversed)
10
+
11
+ ## [0.3.3] - 2021-06-25
12
+
13
+ - Rubocop setup
14
+ - Add rubies 2.3, 2.4, 2.5 and 2.6 to support of gem
15
+
16
+ ## [0.3.2] - 2021-06-24
17
+
18
+ - Setup for run tests/specs locally with Docker
19
+
20
+ ## [0.3.1] - 2021-06-24
21
+
22
+ - More documentation
23
+
3
24
  ## [0.1.0...0.3.0] - 2021-06-24
4
25
 
5
26
  - Initial release
data/Dockerfile ADDED
@@ -0,0 +1,6 @@
1
+ FROM ruby:3.0.0-alpine
2
+ RUN apk update && apk add git
3
+ WORKDIR /app
4
+ COPY . .
5
+ RUN bundle install
6
+ CMD bundle exec rake
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2021 TODO: Write your name
3
+ Copyright (c)
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -7,8 +7,11 @@
7
7
  [![Gem](https://img.shields.io/gem/dt/qrcode_pix_ruby.svg)]()
8
8
  [![license](https://img.shields.io/github/license/pedrofurtado/qrcode_pix_ruby.svg)]()
9
9
  [![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](https://github.com/pedrofurtado/qrcode_pix_ruby)
10
+ [![Ruby Style Guide](https://img.shields.io/badge/code_style-rubocop-brightgreen.svg)](https://github.com/rubocop/rubocop)
10
11
 
11
- Ruby gem for Qrcode generation of Pix (Pagamento Instantâneo Brasileiro - Banco Central do Brasil)
12
+ Ruby gem for Qrcode generation of Pix (Pagamento Instantâneo Brasileiro - Banco Central do Brasil).
13
+
14
+ <img style="max-width: 100%;" src="https://github.com/pedrofurtado/qrcode_pix_ruby/blob/master/pix_logo.png?raw=true" height="100px" />
12
15
 
13
16
  ## Installation
14
17
 
@@ -26,13 +29,14 @@ Or install it yourself as:
26
29
 
27
30
  gem install qrcode_pix_ruby
28
31
 
29
- ## Usage
32
+ ## Usage (examples)
33
+
34
+ ### Static QR Code
30
35
 
31
36
  ```ruby
32
37
  require 'qrcode_pix_ruby'
33
38
 
34
- pix = QrcodePixRuby::Payload.new
35
-
39
+ pix = QrcodePixRuby::Payload.new
36
40
  pix.pix_key = 'minhachavedopix'
37
41
  pix.description = 'Pagamento do pedido 123456'
38
42
  pix.merchant_name = 'Fulano de Tal'
@@ -47,10 +51,55 @@ pix.repeatable = false
47
51
  # QRCode copia-e-cola
48
52
  puts pix.payload
49
53
 
50
- # QRCode estático
54
+ # QRCode para uso em imagens
51
55
  puts pix.base64
52
56
  ```
53
57
 
58
+ ### Dynamic QR Code
59
+
60
+ ```ruby
61
+ require 'qrcode_pix_ruby'
62
+
63
+ pix = QrcodePixRuby::Payload.new
64
+ pix.url = 'https://example.com'
65
+ pix.merchant_name = 'Fulano de Tal'
66
+ pix.merchant_city = 'SAO PAULO'
67
+ pix.amount = '100.00'
68
+ pix.transaction_id = 'TID12345'
69
+ pix.repeatable = false
70
+
71
+ # QRCode copia-e-cola
72
+ puts pix.payload
73
+
74
+ # QRCode para uso em imagens
75
+ puts pix.base64
76
+ ```
77
+
78
+ 🚨 Important note: BACEN (Banco Central do Brasil) sets a variety of rules for each field in QRCode Payload (maximum number of characters, invalid values, mandatory and optional fields, and so on). So, pay attention that a QRCode payload+base64 generated by the gem can be valid, theorically, but may not be accepted in banking apps because of these restrictions (that are out of scope of gem).
79
+
80
+ ## Execute tests/specs
81
+
82
+ To execute gem tests locally, use Docker with the commands below:
83
+
84
+ ```bash
85
+ git clone https://github.com/pedrofurtado/qrcode_pix_ruby
86
+ cd qrcode_pix_ruby/
87
+ docker build -t qrcode_pix_ruby_specs .
88
+
89
+ # Then, run this command how many times you want,
90
+ # after editing local files, and so on, to get
91
+ # feedback from test suite of gem.
92
+ docker run -v $(pwd):/app/ -it qrcode_pix_ruby_specs
93
+ ```
94
+
95
+ ## Demo
96
+
97
+ It's provided a simple demo app, in Heroku, that uses the gem always in latest commit. You can check and test your QRCodes here:
98
+
99
+ https://qrcode-pix-ruby.herokuapp.com
100
+
101
+ 🚨 Important note: The first page load can be slow, because of Heroku free tier. But don't worry, the demo works well 🤓
102
+
54
103
  ## Useful links
55
104
 
56
105
  * https://github.com/joseviniciusnunes/qrcode-pix
@@ -63,10 +112,19 @@ puts pix.base64
63
112
  * https://openpix.com.br/qrcode/scanner
64
113
  * https://openpix.com.br/qrcode/debug
65
114
  * https://github.com/william-costa/wdev-qrcode-pix-estatico-php
115
+ * https://github.com/william-costa/wdev-qrcode-pix-php
66
116
  * https://www.youtube.com/watch?v=eO11iFgrdCA
67
117
  * https://qrcodepix.dinheiro.tech
68
118
  * http://decoder.qrcodepix.dinheiro.tech
69
119
  * https://www.bcb.gov.br/estabilidadefinanceira/pix
120
+ * https://gerencianet.com.br/blog/qr-code-estatico-qr-code-dinamico-no-pix
121
+ * https://blog.juno.com.br/pix-qr-code-estatico-x-qr-code-dinamico
122
+ * https://github.com/entria/awesome-pix
123
+ * https://zxing.org/w/decode.jspx
124
+ * https://github.com/hiagodotme/gpix
125
+ * https://github.com/EnssureIT/faz-um-pix
126
+ * https://github.com/jesobreira/pixkey
127
+ * https://github.com/pedrinholemes/pix-br
70
128
 
71
129
  ## Contributing
72
130
 
data/Rakefile CHANGED
@@ -2,5 +2,7 @@
2
2
 
3
3
  require 'bundler/gem_tasks'
4
4
  require 'rspec/core/rake_task'
5
+ require 'rubocop/rake_task'
5
6
  RSpec::Core::RakeTask.new(:spec)
6
- task default: %i[spec]
7
+ RuboCop::RakeTask.new
8
+ task default: %i[spec rubocop]
data/demo/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+ gem 'qrcode_pix_ruby', github: 'pedrofurtado/qrcode_pix_ruby', branch: 'master'
5
+ gem 'rack'
data/demo/config.ru ADDED
@@ -0,0 +1,152 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'qrcode_pix_ruby'
4
+
5
+ def generate_html_with(env)
6
+ qrcode_data = Rack::Request.new(env).params
7
+ payload = ''
8
+ data_uri = ''
9
+ pix = QrcodePixRuby::Payload.new
10
+
11
+ unless qrcode_data.empty?
12
+ pix.pix_key = qrcode_data['pix_key'] unless qrcode_data['pix_key'].nil?
13
+ pix.url = qrcode_data['url'] unless qrcode_data['url'].nil?
14
+ pix.description = qrcode_data['description'] unless qrcode_data['description'].nil?
15
+ pix.merchant_name = qrcode_data['merchant_name'] unless qrcode_data['merchant_name'].nil?
16
+ pix.merchant_city = qrcode_data['merchant_city'] unless qrcode_data['merchant_city'].nil?
17
+ pix.transaction_id = qrcode_data['transaction_id'] unless qrcode_data['transaction_id'].nil?
18
+ pix.amount = qrcode_data['amount'] unless qrcode_data['amount'].nil?
19
+ pix.currency = qrcode_data['currency'] unless qrcode_data['currency'].nil?
20
+ pix.country_code = qrcode_data['country_code'] unless qrcode_data['country_code'].nil?
21
+ pix.postal_code = qrcode_data['postal_code'] unless qrcode_data['postal_code'].nil?
22
+ pix.repeatable = qrcode_data['repeatable'] == 't' unless qrcode_data['repeatable'].nil?
23
+
24
+ payload = <<-HTML
25
+ <label for='payload'>Payload</label>
26
+ <div class='input-group mb-3'>
27
+ <input class='form-control' id='payload' value='#{pix.payload}'>
28
+ <button class='btn btn-outline-success btn-clipboard' data-clipboard-target='#payload' data-bs-toggle='tooltip' data-bs-placement='top' title='Copied!' data-bs-trigger='click'>Copy</button>
29
+ </div>
30
+ HTML
31
+
32
+ data_uri = "<img style='max-width: 100%;' src='#{pix.base64}'>"
33
+ end
34
+
35
+ StringIO.new <<-HTML
36
+ <!DOCTYPE html>
37
+ <html>
38
+ <head>
39
+ <meta charset='utf-8'>
40
+ <meta name='viewport' content='width=device-width, initial-scale=1'>
41
+ <link href='https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css' rel='stylesheet'>
42
+ <script src='https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js'></script>
43
+ <script src='https://cdn.jsdelivr.net/npm/clipboard@2.0.8/dist/clipboard.min.js'></script>
44
+ <title>QRCode Pix Ruby - Demo App</title>
45
+ </head>
46
+ <body>
47
+ <div class='container' style='margin-top: 50px;'>
48
+ <div class='row'>
49
+ <div class='col-md-12'>
50
+ <h1 class='text-center'>QRCode Pix Ruby - Demo App</h1>
51
+ <br>
52
+ <img style='display: block; margin: 0 auto; max-width: 100%;' src="https://github.com/pedrofurtado/qrcode_pix_ruby/blob/master/pix_logo.png?raw=true" height="100px" />
53
+ <br>
54
+ <p style='word-break: break-all;' class='text-center'>For more details check the official repo: <a href="https://github.com/pedrofurtado/qrcode_pix_ruby">https://github.com/pedrofurtado/qrcode_pix_ruby</a></p>
55
+ <br>
56
+ <br>
57
+ </div>
58
+ </div>
59
+ <div class='row' style='padding-bottom: 50px;'>
60
+ <div class='col-sm-6'>
61
+ <strong>QRCode informations</strong>
62
+ <br>
63
+ <br>
64
+ <form action='https://qrcode-pix-ruby.herokuapp.com' method='post'>
65
+ <div class='mb-3'>
66
+ <label for='pix_key'>Pix key</label>
67
+ <input type='text' class='form-control' id='pix_key' value='#{qrcode_data["pix_key"]}' name='pix_key'>
68
+ </div>
69
+ <div class='mb-3'>
70
+ <label for='url'>URL</label>
71
+ <input type='text' class='form-control' id='url' value='#{qrcode_data["url"]}' name='url'>
72
+ </div>
73
+ <div class='mb-3'>
74
+ <label for='description'>Description</label>
75
+ <input required type='text' class='form-control' id='description' value='#{qrcode_data["description"]}' name='description'>
76
+ </div>
77
+ <div class='mb-3'>
78
+ <label for='merchant_name'>Merchant name</label>
79
+ <input required type='text' class='form-control' id='merchant_name' value='#{qrcode_data["merchant_name"]}' name='merchant_name'>
80
+ </div>
81
+ <div class='mb-3'>
82
+ <label for='merchant_city'>Merchant city</label>
83
+ <input required type='text' class='form-control' id='merchant_city' value='#{qrcode_data["merchant_city"]}' name='merchant_city'>
84
+ </div>
85
+ <div class='mb-3'>
86
+ <label for='transaction_id'>Transaction ID</label>
87
+ <input required type='text' class='form-control' id='transaction_id' value='#{qrcode_data["transaction_id"]}' name='transaction_id'>
88
+ </div>
89
+ <div class='mb-3'>
90
+ <label for='amount'>Amount</label>
91
+ <input required type='text' class='form-control' id='amount' value='#{qrcode_data["amount"]}' name='amount'>
92
+ </div>
93
+ <div class='mb-3'>
94
+ <label for='currency'>Currency</label>
95
+ <select required id='currency' name='currency' class='form-select'>
96
+ <option value='986' selected>Brazilian Real (R$)</option>
97
+ </select>
98
+ </div>
99
+ <div class='mb-3'>
100
+ <label for='country_code'>Country</label>
101
+ <select required id='country_code' name='country_code' class='form-select'>
102
+ <option value='BR' selected>Brazil</option>
103
+ </select>
104
+ </div>
105
+ <div class='mb-3'>
106
+ <label for='postal_code'>Postal code</label>
107
+ <input type='text' class='form-control' id='postal_code' value='#{qrcode_data["postal_code"]}' name='postal_code'>
108
+ </div>
109
+ <div class='mb-3'>
110
+ <label for='repeatable'>Repeatable?</label>
111
+ <select required id='repeatable' name='repeatable' class='form-select'>
112
+ <option selected></option>
113
+ <option value='t'>Yes</option>
114
+ <option value='f'>No</option>
115
+ </select>
116
+ </div>
117
+ <div class='d-grid gap-2'>
118
+ <button type='submit' class='btn btn-lg btn-primary'>Generate</button>
119
+ </div>
120
+ </form>
121
+ </div>
122
+ <div class='col-sm-6'>
123
+ <strong>Preview</strong>
124
+ <br>
125
+ <br>
126
+ #{payload}
127
+ <br>
128
+ <br>
129
+ #{data_uri}
130
+ </div>
131
+ </div>
132
+ </div>
133
+ <script>
134
+ new ClipboardJS('.btn-clipboard');
135
+ Array.from(document.querySelectorAll('[data-bs-toggle="tooltip"]')).forEach(function(tooltipTriggerEl) {
136
+ new bootstrap.Tooltip(tooltipTriggerEl);
137
+ });
138
+ </script>
139
+ </body>
140
+ </html>
141
+ HTML
142
+ end
143
+
144
+ run lambda { |env|
145
+ [
146
+ 200,
147
+ {
148
+ 'Content-Type' => 'text/html'
149
+ },
150
+ generate_html_with(env)
151
+ ]
152
+ }
@@ -4,24 +4,26 @@ require 'rqrcode'
4
4
 
5
5
  module QrcodePixRuby
6
6
  class Payload
7
- ID_PAYLOAD_FORMAT_INDICATOR = '00'.freeze
8
- ID_POINT_OF_INITIATION_METHOD = '01'.freeze
9
- ID_MERCHANT_ACCOUNT_INFORMATION = '26'.freeze
10
- ID_MERCHANT_ACCOUNT_INFORMATION_GUI = '00'.freeze
11
- ID_MERCHANT_ACCOUNT_INFORMATION_KEY = '01'.freeze
12
- ID_MERCHANT_ACCOUNT_INFORMATION_DESCRIPTION = '02'.freeze
13
- ID_MERCHANT_CATEGORY_CODE = '52'.freeze
14
- ID_TRANSACTION_CURRENCY = '53'.freeze
15
- ID_TRANSACTION_AMOUNT = '54'.freeze
16
- ID_COUNTRY_CODE = '58'.freeze
17
- ID_MERCHANT_NAME = '59'.freeze
18
- ID_MERCHANT_CITY = '60'.freeze
19
- ID_POSTAL_CODE = '61'.freeze
20
- ID_ADDITIONAL_DATA_FIELD_TEMPLATE = '62'.freeze
21
- ID_ADDITIONAL_DATA_FIELD_TEMPLATE_TXID = '05'.freeze
22
- ID_CRC16 = '63'.freeze
7
+ ID_PAYLOAD_FORMAT_INDICATOR = '00'
8
+ ID_POINT_OF_INITIATION_METHOD = '01'
9
+ ID_MERCHANT_ACCOUNT_INFORMATION = '26'
10
+ ID_MERCHANT_ACCOUNT_INFORMATION_GUI = '00'
11
+ ID_MERCHANT_ACCOUNT_INFORMATION_KEY = '01'
12
+ ID_MERCHANT_ACCOUNT_INFORMATION_DESCRIPTION = '02'
13
+ ID_MERCHANT_ACCOUNT_INFORMATION_URL = '25'
14
+ ID_MERCHANT_CATEGORY_CODE = '52'
15
+ ID_TRANSACTION_CURRENCY = '53'
16
+ ID_TRANSACTION_AMOUNT = '54'
17
+ ID_COUNTRY_CODE = '58'
18
+ ID_MERCHANT_NAME = '59'
19
+ ID_MERCHANT_CITY = '60'
20
+ ID_POSTAL_CODE = '61'
21
+ ID_ADDITIONAL_DATA_FIELD_TEMPLATE = '62'
22
+ ID_ADDITIONAL_DATA_FIELD_TEMPLATE_TXID = '05'
23
+ ID_CRC16 = '63'
23
24
 
24
25
  attr_accessor :pix_key,
26
+ :url,
25
27
  :repeatable,
26
28
  :currency,
27
29
  :country_code,
@@ -33,7 +35,7 @@ module QrcodePixRuby
33
35
  :amount
34
36
 
35
37
  def payload
36
- p = ''
38
+ p = ''
37
39
 
38
40
  p += emv(ID_PAYLOAD_FORMAT_INDICATOR, '01')
39
41
  p += emv_repeatable
@@ -51,7 +53,17 @@ module QrcodePixRuby
51
53
  end
52
54
 
53
55
  def base64
54
- ::RQRCode::QRCode.new(payload).as_png(bit_depth: 1, border_modules: 0, color_mode: 0, color: 'black', file: nil, fill: 'white', module_px_size: 6, resize_exactly_to: false, resize_gte_to: false).to_data_url
56
+ ::RQRCode::QRCode.new(payload).as_png(
57
+ bit_depth: 1,
58
+ border_modules: 0,
59
+ color_mode: 0,
60
+ color: 'black',
61
+ file: nil,
62
+ fill: 'white',
63
+ module_px_size: 6,
64
+ resize_exactly_to: false,
65
+ resize_gte_to: false
66
+ ).to_data_url
55
67
  end
56
68
 
57
69
  private
@@ -62,45 +74,39 @@ module QrcodePixRuby
62
74
  end
63
75
 
64
76
  def emv_repeatable
65
- emv(ID_POINT_OF_INITIATION_METHOD, repeatable ? '12' : '11')
77
+ emv(ID_POINT_OF_INITIATION_METHOD, repeatable ? '11' : '12')
66
78
  end
67
79
 
68
80
  def emv_merchant
69
- merchant_gui = emv ID_MERCHANT_ACCOUNT_INFORMATION_GUI, 'BR.GOV.BCB.PIX'
70
- merchant_pix_key = emv ID_MERCHANT_ACCOUNT_INFORMATION_KEY, pix_key
81
+ merchant_gui = emv(ID_MERCHANT_ACCOUNT_INFORMATION_GUI, 'BR.GOV.BCB.PIX')
82
+ merchant_pix_key = emv(ID_MERCHANT_ACCOUNT_INFORMATION_KEY, pix_key) if pix_key
71
83
  merchant_description = emv(ID_MERCHANT_ACCOUNT_INFORMATION_DESCRIPTION, description) if description
72
-
73
- emv ID_MERCHANT_ACCOUNT_INFORMATION, "#{merchant_gui}#{merchant_pix_key}#{merchant_description}"
84
+ merchant_url = emv(ID_MERCHANT_ACCOUNT_INFORMATION_URL, url.gsub(/https?:\/\//, '')) if url
85
+ emv(ID_MERCHANT_ACCOUNT_INFORMATION, "#{merchant_gui}#{merchant_pix_key}#{merchant_description}#{merchant_url}")
74
86
  end
75
87
 
76
88
  def emv_additional_data
77
89
  txid = emv(ID_ADDITIONAL_DATA_FIELD_TEMPLATE_TXID, transaction_id || '***')
78
- emv ID_ADDITIONAL_DATA_FIELD_TEMPLATE, txid
90
+ emv(ID_ADDITIONAL_DATA_FIELD_TEMPLATE, txid)
79
91
  end
80
92
 
81
- def crc16(t)
82
- extended_payload = "#{t}#{ID_CRC16}04"
93
+ def crc16(text)
94
+ extended_payload = "#{text}#{ID_CRC16}04"
83
95
  extended_payload_length = extended_payload.length
84
96
  polynomial = 0x1021
85
97
  result = 0xFFFF
86
98
 
87
- if extended_payload_length > 0
99
+ if extended_payload_length.positive?
88
100
  offset = 0
89
101
 
90
102
  while offset < extended_payload_length
91
- result = result ^ (extended_payload[offset].bytes[0] << 8)
92
-
103
+ result ^= extended_payload[offset].bytes[0] << 8
93
104
  bitwise = 0
94
105
 
95
106
  while bitwise < 8
96
- result = result << 1
97
-
98
- if result & 0x10000 != 0
99
- result = result ^ polynomial
100
- end
101
-
102
- result = result & 0xFFFF
103
-
107
+ result <<= 1
108
+ result ^= polynomial if result & 0x10000 != 0
109
+ result &= 0xFFFF
104
110
  bitwise += 1
105
111
  end
106
112
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module QrcodePixRuby
4
- VERSION = '0.3.0'.freeze
4
+ VERSION = '0.4.0'
5
5
  end
data/pix_logo.png ADDED
Binary file
@@ -5,15 +5,16 @@ require_relative 'lib/qrcode_pix_ruby/version'
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = 'qrcode_pix_ruby'
7
7
  spec.version = QrcodePixRuby::VERSION
8
- spec.authors = ["Pedro Furtado", "Marcio de Jesus"]
9
- spec.email = ["pedro.felipe.azevedo.furtado@gmail.com", "marciodejesusrj@gmail.com"]
10
- spec.summary = "Ruby gem for Qrcode generation of Pix (Pagamento Instantâneo Brasileiro - Banco Central do Brasil)"
11
- spec.description = "Ruby gem for Qrcode generation of Pix (Pagamento Instantâneo Brasileiro - Banco Central do Brasil)"
12
- spec.homepage = "https://github.com/pedrofurtado/qrcode_pix_ruby"
13
- spec.license = "MIT"
14
- spec.metadata["homepage_uri"] = spec.homepage
15
- spec.metadata["source_code_uri"] = spec.homepage
16
- spec.metadata["changelog_uri"] = "#{spec.homepage}/CHANGELOG.md"
8
+ spec.authors = ['Pedro Furtado', 'Marcio de Jesus', 'William Radi', 'Leonardo Comar']
9
+ spec.email = ['pedro.felipe.azevedo.furtado@gmail.com', 'marciodejesusrj@gmail.com', 'williamw@lbv.org.br', 'lfcomar@lbv.org.br']
10
+ spec.summary = 'Ruby gem for Qrcode generation of Pix (Pagamento Instantâneo Brasileiro - Banco Central do Brasil)'
11
+ spec.description = 'Ruby gem for Qrcode generation of Pix (Pagamento Instantâneo Brasileiro - Banco Central do Brasil)'
12
+ spec.homepage = 'https://github.com/pedrofurtado/qrcode_pix_ruby'
13
+ spec.license = 'MIT'
14
+ spec.metadata['homepage_uri'] = spec.homepage
15
+ spec.metadata['source_code_uri'] = spec.homepage
16
+ spec.metadata['changelog_uri'] = "#{spec.homepage}/CHANGELOG.md"
17
+ spec.required_ruby_version = '>= 2.3.0'
17
18
 
18
19
  spec.files = Dir.chdir(File.expand_path(__dir__)) do
19
20
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
@@ -23,7 +24,8 @@ Gem::Specification.new do |spec|
23
24
  spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
24
25
  spec.require_paths = ['lib']
25
26
 
26
- spec.add_dependency 'rake', '~> 13.0'
27
- spec.add_dependency 'rspec', '~> 3.0'
28
- spec.add_dependency 'rqrcode', '~> 2.0'
27
+ spec.add_dependency 'rqrcode'
28
+ spec.add_development_dependency 'rake'
29
+ spec.add_development_dependency 'rspec'
30
+ spec.add_development_dependency 'rubocop'
29
31
  end
metadata CHANGED
@@ -1,82 +1,106 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qrcode_pix_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pedro Furtado
8
8
  - Marcio de Jesus
9
+ - William Radi
10
+ - Leonardo Comar
9
11
  autorequire:
10
12
  bindir: exe
11
13
  cert_chain: []
12
- date: 2021-06-24 00:00:00.000000000 Z
14
+ date: 2021-07-10 00:00:00.000000000 Z
13
15
  dependencies:
14
16
  - !ruby/object:Gem::Dependency
15
- name: rake
17
+ name: rqrcode
16
18
  requirement: !ruby/object:Gem::Requirement
17
19
  requirements:
18
- - - "~>"
20
+ - - ">="
19
21
  - !ruby/object:Gem::Version
20
- version: '13.0'
22
+ version: '0'
21
23
  type: :runtime
22
24
  prerelease: false
23
25
  version_requirements: !ruby/object:Gem::Requirement
24
26
  requirements:
25
- - - "~>"
27
+ - - ">="
26
28
  - !ruby/object:Gem::Version
27
- version: '13.0'
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: '0'
37
+ type: :development
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
28
44
  - !ruby/object:Gem::Dependency
29
45
  name: rspec
30
46
  requirement: !ruby/object:Gem::Requirement
31
47
  requirements:
32
- - - "~>"
48
+ - - ">="
33
49
  - !ruby/object:Gem::Version
34
- version: '3.0'
35
- type: :runtime
50
+ version: '0'
51
+ type: :development
36
52
  prerelease: false
37
53
  version_requirements: !ruby/object:Gem::Requirement
38
54
  requirements:
39
- - - "~>"
55
+ - - ">="
40
56
  - !ruby/object:Gem::Version
41
- version: '3.0'
57
+ version: '0'
42
58
  - !ruby/object:Gem::Dependency
43
- name: rqrcode
59
+ name: rubocop
44
60
  requirement: !ruby/object:Gem::Requirement
45
61
  requirements:
46
- - - "~>"
62
+ - - ">="
47
63
  - !ruby/object:Gem::Version
48
- version: '2.0'
49
- type: :runtime
64
+ version: '0'
65
+ type: :development
50
66
  prerelease: false
51
67
  version_requirements: !ruby/object:Gem::Requirement
52
68
  requirements:
53
- - - "~>"
69
+ - - ">="
54
70
  - !ruby/object:Gem::Version
55
- version: '2.0'
71
+ version: '0'
56
72
  description: Ruby gem for Qrcode generation of Pix (Pagamento Instantâneo Brasileiro
57
73
  - Banco Central do Brasil)
58
74
  email:
59
75
  - pedro.felipe.azevedo.furtado@gmail.com
60
76
  - marciodejesusrj@gmail.com
77
+ - williamw@lbv.org.br
78
+ - lfcomar@lbv.org.br
61
79
  executables: []
62
80
  extensions: []
63
81
  extra_rdoc_files: []
64
82
  files:
65
83
  - ".github/workflows/ci.yml"
84
+ - ".github/workflows/heroku.yml"
66
85
  - ".github/workflows/rubygems.yml"
67
86
  - ".gitignore"
68
87
  - ".rspec"
88
+ - ".rubocop.yml"
69
89
  - CHANGELOG.md
70
90
  - CODE_OF_CONDUCT.md
91
+ - Dockerfile
71
92
  - Gemfile
72
93
  - LICENSE.txt
73
94
  - README.md
74
95
  - Rakefile
75
96
  - bin/console
76
97
  - bin/setup
98
+ - demo/Gemfile
99
+ - demo/config.ru
77
100
  - lib/qrcode_pix_ruby.rb
78
101
  - lib/qrcode_pix_ruby/payload.rb
79
102
  - lib/qrcode_pix_ruby/version.rb
103
+ - pix_logo.png
80
104
  - qrcode_pix_ruby.gemspec
81
105
  homepage: https://github.com/pedrofurtado/qrcode_pix_ruby
82
106
  licenses:
@@ -93,14 +117,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
93
117
  requirements:
94
118
  - - ">="
95
119
  - !ruby/object:Gem::Version
96
- version: '0'
120
+ version: 2.3.0
97
121
  required_rubygems_version: !ruby/object:Gem::Requirement
98
122
  requirements:
99
123
  - - ">="
100
124
  - !ruby/object:Gem::Version
101
125
  version: '0'
102
126
  requirements: []
103
- rubygems_version: 3.2.15
127
+ rubygems_version: 3.2.22
104
128
  signing_key:
105
129
  specification_version: 4
106
130
  summary: Ruby gem for Qrcode generation of Pix (Pagamento Instantâneo Brasileiro -