qrcode_pix_ruby 0.1.0 → 0.2.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: 85cd010b67a7c288be95c4c58339a7e3cb5eee4883508d599daa22444b42096f
4
- data.tar.gz: 583cc73680d47d0bd52af3dfec9a52315c3727abccbea3acf4ea43a80493832e
3
+ metadata.gz: 35b4d652b206592b48976ae27f1c3e461d53b9b90ba6d7d3845e8578ff38d2d5
4
+ data.tar.gz: 3718c9e90ca609015f5eec3531ff3c35fd0945be24f5e06430e2e3b1278fb4d7
5
5
  SHA512:
6
- metadata.gz: 1b9afb28eaf1d31561a032fa5142a7d45494cadb225a2d6406de2f84209134e33d77339c1d81880b30e13cb7c344675336a878586b39dc35adc7af535e79ebb5
7
- data.tar.gz: 1fa8d7456b625b55da292db7f713ceefa752b8a385f726a32c15bd382ffa88f875d81fb07d6d4509437a676d8cf359c2bf2ae08e08405a2ae38ffa2535b24386
6
+ metadata.gz: bf822ee3996b5d30ad39068e3e20d5b7114556defb15d3265a5e30bb6f076f6b0018fdf4cbc7eafac1d91ceea927a92891ea9649402d4663e713a83fcfe8c441
7
+ data.tar.gz: 7771a3304e461bf393b38841ed4d14c18b83c55e69399245e92502d459fbbe55ff96447383579504a7c765fd7f89c17ccf818b544cce8a4d994429f0dc4d5823
@@ -1,4 +1,4 @@
1
- name: QrCode Pix Ruby - CI
1
+ name: CI
2
2
 
3
3
  on: [push, pull_request]
4
4
 
@@ -0,0 +1,30 @@
1
+ name: Publish to Rubygems
2
+
3
+ on:
4
+ release:
5
+ types: [created]
6
+
7
+ jobs:
8
+ publish-to-rubygems:
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: bundle install
20
+
21
+ - name: Publish to Rubygems
22
+ run: |
23
+ mkdir -p $HOME/.gem
24
+ touch $HOME/.gem/credentials
25
+ chmod 0600 $HOME/.gem/credentials
26
+ printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
27
+ gem build *.gemspec
28
+ gem push *.gem
29
+ env:
30
+ GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
data/.gitignore CHANGED
@@ -1,2 +1,3 @@
1
1
  .rspec_status
2
- Gemfile.lock
2
+ *.lock
3
+ *.gem
data/README.md CHANGED
@@ -1,4 +1,9 @@
1
- # qrcode_pix_ruby
1
+ # QRCode Pix Ruby
2
+
3
+ [![CI](https://github.com/pedrofurtado/qrcode_pix_ruby/actions/workflows/ci.yml/badge.svg)](https://github.com/pedrofurtado/qrcode_pix_ruby/actions/workflows/ci.yml)
4
+ [![Gem Version](https://badge.fury.io/rb/qrcode_pix_ruby.svg)](https://badge.fury.io/rb/qrcode_pix_ruby)
5
+ [![Gem](https://img.shields.io/gem/dt/qrcode_pix_ruby.svg)]()
6
+ [![license](https://img.shields.io/github/license/pedrofurtado/qrcode_pix_ruby.svg)]()
2
7
 
3
8
  Ruby gem for Qrcode generation of Pix (Pagamento Instantâneo Brasileiro - Banco Central do Brasil)
4
9
 
@@ -31,11 +36,24 @@ pix.merchant_name = 'William Costa'
31
36
  pix.merchant_city = 'SAO PAULO'
32
37
  pix.transaction_id = 'WDEV1234'
33
38
  pix.amount = '100.00'
39
+ pix.repeatable = false
34
40
 
35
41
  puts pix.payload
36
42
  puts pix.base64
37
43
  ```
38
44
 
45
+ ## Useful links
46
+
47
+ * https://github.com/joseviniciusnunes/qrcode-pix
48
+ * https://www.gerarpix.com.br
49
+ * https://github.com/fbbergamo/gerador-pix
50
+ * https://pix.ae
51
+ * https://pix.nascent.com.br/tools/pix-qr-decoder
52
+ * https://openpix.com.br/qrcode/scanner
53
+ * https://openpix.com.br/qrcode/debug
54
+ * https://github.com/william-costa/wdev-qrcode-pix-estatico-php
55
+ * https://www.youtube.com/watch?v=eO11iFgrdCA
56
+
39
57
  ## Contributing
40
58
 
41
59
  Bug reports and pull requests are welcome on GitHub at https://github.com/pedrofurtado/qrcode_pix_ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/pedrofurtado/qrcode_pix_ruby/blob/master/CODE_OF_CONDUCT.md).
@@ -1,8 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'rqrcode'
4
+
3
5
  module QrcodePixRuby
4
6
  class Payload
5
7
  ID_PAYLOAD_FORMAT_INDICATOR = '00'.freeze
8
+ ID_POINT_OF_INITIATION_METHOD = '01'.freeze
6
9
  ID_MERCHANT_ACCOUNT_INFORMATION = '26'.freeze
7
10
  ID_MERCHANT_ACCOUNT_INFORMATION_GUI = '00'.freeze
8
11
  ID_MERCHANT_ACCOUNT_INFORMATION_KEY = '01'.freeze
@@ -13,12 +16,17 @@ module QrcodePixRuby
13
16
  ID_COUNTRY_CODE = '58'.freeze
14
17
  ID_MERCHANT_NAME = '59'.freeze
15
18
  ID_MERCHANT_CITY = '60'.freeze
19
+ ID_POSTAL_CODE = '61'.freeze
16
20
  ID_ADDITIONAL_DATA_FIELD_TEMPLATE = '62'.freeze
17
21
  ID_ADDITIONAL_DATA_FIELD_TEMPLATE_TXID = '05'.freeze
18
22
  ID_CRC16 = '63'.freeze
19
23
 
20
24
  attr_accessor :pix_key,
25
+ :repeatable,
26
+ :currency,
27
+ :country_code,
21
28
  :description,
29
+ :postal_code,
22
30
  :merchant_name,
23
31
  :merchant_city,
24
32
  :transaction_id,
@@ -28,20 +36,22 @@ module QrcodePixRuby
28
36
  p = ''
29
37
 
30
38
  p += emv(ID_PAYLOAD_FORMAT_INDICATOR, '01')
39
+ p += emv_repeatable
31
40
  p += emv_merchant
32
41
  p += emv(ID_MERCHANT_CATEGORY_CODE, '0000')
33
- p += emv(ID_TRANSACTION_CURRENCY, '986')
34
- p += emv(ID_TRANSACTION_AMOUNT, amount)
35
- p += emv(ID_COUNTRY_CODE, 'BR')
42
+ p += emv(ID_TRANSACTION_CURRENCY, currency || '986')
43
+ p += emv(ID_TRANSACTION_AMOUNT, amount) if amount
44
+ p += emv(ID_COUNTRY_CODE, country_code || 'BR')
36
45
  p += emv(ID_MERCHANT_NAME, merchant_name)
37
46
  p += emv(ID_MERCHANT_CITY, merchant_city)
47
+ p += emv(ID_POSTAL_CODE, postal_code) if postal_code
38
48
  p += emv_additional_data
39
49
 
40
50
  p + crc16(p)
41
51
  end
42
52
 
43
53
  def base64
44
- ''
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, size: 200).to_data_url
45
55
  end
46
56
 
47
57
  private
@@ -51,16 +61,20 @@ module QrcodePixRuby
51
61
  "#{id}#{size}#{value}"
52
62
  end
53
63
 
64
+ def emv_repeatable
65
+ emv(ID_POINT_OF_INITIATION_METHOD, repeatable ? '12' : '11')
66
+ end
67
+
54
68
  def emv_merchant
55
- merchant_gui = emv ID_MERCHANT_ACCOUNT_INFORMATION_GUI, 'br.gov.bcb.pix'
69
+ merchant_gui = emv ID_MERCHANT_ACCOUNT_INFORMATION_GUI, 'BR.GOV.BCB.PIX'
56
70
  merchant_pix_key = emv ID_MERCHANT_ACCOUNT_INFORMATION_KEY, pix_key
57
- merchant_description = emv ID_MERCHANT_ACCOUNT_INFORMATION_DESCRIPTION, description
71
+ merchant_description = emv(ID_MERCHANT_ACCOUNT_INFORMATION_DESCRIPTION, description) if description
58
72
 
59
73
  emv ID_MERCHANT_ACCOUNT_INFORMATION, "#{merchant_gui}#{merchant_pix_key}#{merchant_description}"
60
74
  end
61
75
 
62
76
  def emv_additional_data
63
- txid = emv(ID_ADDITIONAL_DATA_FIELD_TEMPLATE_TXID, transaction_id)
77
+ txid = emv(ID_ADDITIONAL_DATA_FIELD_TEMPLATE_TXID, transaction_id || '***')
64
78
  emv ID_ADDITIONAL_DATA_FIELD_TEMPLATE, txid
65
79
  end
66
80
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module QrcodePixRuby
4
- VERSION = '0.1.0'.freeze
4
+ VERSION = '0.2.0'.freeze
5
5
  end
@@ -25,4 +25,5 @@ Gem::Specification.new do |spec|
25
25
 
26
26
  spec.add_dependency 'rake', '~> 13.0'
27
27
  spec.add_dependency 'rspec', '~> 3.0'
28
+ spec.add_dependency 'rqrcode', '~> 2.0'
28
29
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qrcode_pix_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pedro Furtado
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-06-23 00:00:00.000000000 Z
11
+ date: 2021-06-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '3.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rqrcode
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.0'
41
55
  description: Ruby gem for Qrcode generation of Pix (Pagamento Instantâneo Brasileiro
42
56
  - Banco Central do Brasil)
43
57
  email:
@@ -47,12 +61,12 @@ extensions: []
47
61
  extra_rdoc_files: []
48
62
  files:
49
63
  - ".github/workflows/ci.yml"
64
+ - ".github/workflows/rubygems.yml"
50
65
  - ".gitignore"
51
66
  - ".rspec"
52
67
  - CHANGELOG.md
53
68
  - CODE_OF_CONDUCT.md
54
69
  - Gemfile
55
- - Gemfile.lock
56
70
  - LICENSE.txt
57
71
  - README.md
58
72
  - Rakefile
@@ -69,7 +83,7 @@ metadata:
69
83
  homepage_uri: https://github.com/pedrofurtado/qrcode_pix_ruby
70
84
  source_code_uri: https://github.com/pedrofurtado/qrcode_pix_ruby
71
85
  changelog_uri: https://github.com/pedrofurtado/qrcode_pix_ruby/CHANGELOG.md
72
- post_install_message:
86
+ post_install_message:
73
87
  rdoc_options: []
74
88
  require_paths:
75
89
  - lib
@@ -85,7 +99,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
85
99
  version: '0'
86
100
  requirements: []
87
101
  rubygems_version: 3.2.15
88
- signing_key:
102
+ signing_key:
89
103
  specification_version: 4
90
104
  summary: Ruby gem for Qrcode generation of Pix (Pagamento Instantâneo Brasileiro -
91
105
  Banco Central do Brasil)