qrcode_pix_ruby 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +29 -19
- data/Rakefile +2 -2
- data/demo/config.ru +63 -44
- data/lib/qrcode_pix_ruby.rb +1 -2
- data/lib/qrcode_pix_ruby/payload.rb +21 -11
- data/lib/qrcode_pix_ruby/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a7d931df9ece2ebd9af528f72a1dda1efefda84c10524b3896194d0d34d96c22
|
4
|
+
data.tar.gz: dfb9495a14d4a1607f8451465bb009e8bff5a12816cb79f314e4b7572c60023b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5b58df6d23aa1f1c884218da52bacf1c0450e7534eef254522f32d021fda4be283b4d001b5a0b04488f208de62512e1e60ea1baccb54e13f98171f97825eae11
|
7
|
+
data.tar.gz: 7608914b8ef248a0f6705bc4d14483ffbb5a716009de911302fef9822136b5f51f5213999922df89a8053ba1cb32745887243f6c8f11df2ef5c84c9a8b1f1ed0
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -36,22 +36,27 @@ Or install it yourself as:
|
|
36
36
|
```ruby
|
37
37
|
require 'qrcode_pix_ruby'
|
38
38
|
|
39
|
-
pix
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
39
|
+
pix = QrcodePixRuby::Payload.new(
|
40
|
+
pix_key: 'minhachavedopix',
|
41
|
+
description: 'Pagamento do pedido 123456',
|
42
|
+
merchant_name: 'Fulano de Tal',
|
43
|
+
merchant_city: 'SAO PAULO',
|
44
|
+
transaction_id: 'TID12345',
|
45
|
+
amount: '100.00',
|
46
|
+
currency: '986',
|
47
|
+
country_code: 'BR',
|
48
|
+
postal_code: '01131010',
|
49
|
+
repeatable: false
|
50
|
+
)
|
51
|
+
|
52
|
+
# If needed, change the attributes value later
|
53
|
+
pix.pix_key = 'minhaoutrachavepix'
|
54
|
+
pix.merchant_city = 'BRASILIA'
|
50
55
|
|
51
56
|
# QRCode copia-e-cola
|
52
57
|
puts pix.payload
|
53
58
|
|
54
|
-
# QRCode
|
59
|
+
# QRCode for images
|
55
60
|
puts pix.base64
|
56
61
|
```
|
57
62
|
|
@@ -60,13 +65,18 @@ puts pix.base64
|
|
60
65
|
```ruby
|
61
66
|
require 'qrcode_pix_ruby'
|
62
67
|
|
63
|
-
pix
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
68
|
+
pix = QrcodePixRuby::Payload.new(
|
69
|
+
url: 'https://example.com',
|
70
|
+
merchant_name: 'Fulano de Tal',
|
71
|
+
merchant_city: 'SAO PAULO',
|
72
|
+
amount: '100.00',
|
73
|
+
transaction_id: 'TID12345',
|
74
|
+
repeatable: false
|
75
|
+
)
|
76
|
+
|
77
|
+
# If needed, change the attributes value later
|
78
|
+
pix.url = 'https://another-example.com'
|
79
|
+
pix.amount = 1.50
|
70
80
|
|
71
81
|
# QRCode copia-e-cola
|
72
82
|
puts pix.payload
|
data/Rakefile
CHANGED
data/demo/config.ru
CHANGED
@@ -4,22 +4,22 @@ require 'qrcode_pix_ruby'
|
|
4
4
|
|
5
5
|
def generate_html_with(env)
|
6
6
|
qrcode_data = Rack::Request.new(env).params
|
7
|
-
payload
|
8
|
-
data_uri
|
9
|
-
pix
|
7
|
+
payload = ''
|
8
|
+
data_uri = ''
|
9
|
+
pix = QrcodePixRuby::Payload.new
|
10
10
|
|
11
11
|
unless qrcode_data.empty?
|
12
|
-
pix.pix_key = qrcode_data['pix_key']
|
13
|
-
pix.url = qrcode_data['url']
|
14
|
-
pix.description = qrcode_data['description']
|
15
|
-
pix.merchant_name = qrcode_data['merchant_name']
|
16
|
-
pix.merchant_city = qrcode_data['merchant_city']
|
17
|
-
pix.transaction_id = qrcode_data['transaction_id']
|
18
|
-
pix.amount = qrcode_data['amount']
|
19
|
-
pix.currency = qrcode_data['currency']
|
20
|
-
pix.country_code = qrcode_data['country_code']
|
21
|
-
pix.postal_code = qrcode_data['postal_code']
|
22
|
-
pix.repeatable = qrcode_data['repeatable'] == 't'
|
12
|
+
pix.pix_key = qrcode_data['pix_key'] if !qrcode_data['pix_key'].nil? && !qrcode_data['pix_key'].empty?
|
13
|
+
pix.url = qrcode_data['url'] if !qrcode_data['url'].nil? && !qrcode_data['url'].empty?
|
14
|
+
pix.description = qrcode_data['description'] if !qrcode_data['description'].nil? && !qrcode_data['description'].empty?
|
15
|
+
pix.merchant_name = qrcode_data['merchant_name'] if !qrcode_data['merchant_name'].nil? && !qrcode_data['merchant_name'].empty?
|
16
|
+
pix.merchant_city = qrcode_data['merchant_city'] if !qrcode_data['merchant_city'].nil? && !qrcode_data['merchant_city'].empty?
|
17
|
+
pix.transaction_id = qrcode_data['transaction_id'] if !qrcode_data['transaction_id'].nil? && !qrcode_data['transaction_id'].empty?
|
18
|
+
pix.amount = qrcode_data['amount'] if !qrcode_data['amount'].nil? && !qrcode_data['amount'].empty?
|
19
|
+
pix.currency = qrcode_data['currency'] if !qrcode_data['currency'].nil? && !qrcode_data['currency'].empty?
|
20
|
+
pix.country_code = qrcode_data['country_code'] if !qrcode_data['country_code'].nil? && !qrcode_data['country_code'].empty?
|
21
|
+
pix.postal_code = qrcode_data['postal_code'] if !qrcode_data['postal_code'].nil? && !qrcode_data['postal_code'].empty?
|
22
|
+
pix.repeatable = qrcode_data['repeatable'] == 't' if !qrcode_data['repeatable'].nil? && !qrcode_data['repeatable'].empty?
|
23
23
|
|
24
24
|
payload = <<-HTML
|
25
25
|
<label for='payload'>Payload</label>
|
@@ -29,7 +29,7 @@ def generate_html_with(env)
|
|
29
29
|
</div>
|
30
30
|
HTML
|
31
31
|
|
32
|
-
data_uri = "<img style='max-width: 100%;' src='#{pix.base64}'>"
|
32
|
+
data_uri = "<img style='max-width: 100%; display: block; margin: 0 auto;' src='#{pix.base64}'>"
|
33
33
|
end
|
34
34
|
|
35
35
|
StringIO.new <<-HTML
|
@@ -63,58 +63,79 @@ def generate_html_with(env)
|
|
63
63
|
<br>
|
64
64
|
<form action='https://qrcode-pix-ruby.herokuapp.com' method='post'>
|
65
65
|
<div class='mb-3'>
|
66
|
-
<
|
66
|
+
<div class='form-text'>
|
67
|
+
For static Pix, please fill the 'Pix key' field.<br>
|
68
|
+
For dynamic Pix, fill the 'URL' field.<br>
|
69
|
+
Do not fill both fields.
|
70
|
+
</div>
|
71
|
+
</div>
|
72
|
+
<div class='mb-3'>
|
73
|
+
<label for='pix_key'>* Pix key</label>
|
67
74
|
<input type='text' class='form-control' id='pix_key' value='#{qrcode_data["pix_key"]}' name='pix_key'>
|
75
|
+
<div class='form-text'>
|
76
|
+
Formats of Pix keys:<br>
|
77
|
+
CPF: 12345678910 (only numbers)<br>
|
78
|
+
Phone: +5511912345678 (+55 + DDD + phone, only numbers)<br>
|
79
|
+
Email: example@mail.com<br>
|
80
|
+
Random: a6hf7jdk3nc8iK (generated by bank)
|
81
|
+
</div>
|
68
82
|
</div>
|
83
|
+
<div class='mb-3 text-center'> or</div>
|
69
84
|
<div class='mb-3'>
|
70
|
-
<label for='url'
|
71
|
-
<input type='
|
85
|
+
<label for='url'>* URL</label>
|
86
|
+
<input type='url' pattern='https?:\/\/.+' class='form-control' id='url' value='#{qrcode_data["url"]}' name='url'>
|
72
87
|
</div>
|
88
|
+
<hr>
|
73
89
|
<div class='mb-3'>
|
74
|
-
<label for='
|
75
|
-
<input required type='text' class='form-control' id='
|
90
|
+
<label for='merchant_name'>* Merchant name</label>
|
91
|
+
<input required maxlength='10' type='text' class='form-control' id='merchant_name' value='#{qrcode_data["merchant_name"]}' name='merchant_name'>
|
76
92
|
</div>
|
77
93
|
<div class='mb-3'>
|
78
|
-
<label for='
|
79
|
-
<input required type='text' class='form-control' id='
|
94
|
+
<label for='merchant_city'>* Merchant city</label>
|
95
|
+
<input required maxlength='10' type='text' class='form-control' id='merchant_city' value='#{qrcode_data["merchant_city"]}' name='merchant_city'>
|
80
96
|
</div>
|
81
97
|
<div class='mb-3'>
|
82
|
-
<label for='
|
83
|
-
<
|
98
|
+
<label for='country_code'>* Country</label>
|
99
|
+
<select required id='country_code' name='country_code' class='form-select'>
|
100
|
+
<option></option>
|
101
|
+
<option value='BR' #{qrcode_data['country_code'] == 'BR' ? 'selected' : ''}>Brazil</option>
|
102
|
+
</select>
|
84
103
|
</div>
|
85
104
|
<div class='mb-3'>
|
86
|
-
<label for='
|
87
|
-
<
|
105
|
+
<label for='currency'>* Currency</label>
|
106
|
+
<select required id='currency' name='currency' class='form-select'>
|
107
|
+
<option></option>
|
108
|
+
<option value='986' #{qrcode_data['currency'] == '986' ? 'selected' : ''}>Brazilian Real (R$)</option>
|
109
|
+
</select>
|
88
110
|
</div>
|
89
111
|
<div class='mb-3'>
|
90
|
-
<label for='
|
91
|
-
<input
|
112
|
+
<label for='description'>Description</label>
|
113
|
+
<input maxlength='10' type='text' class='form-control' id='description' value='#{qrcode_data["description"]}' name='description'>
|
92
114
|
</div>
|
93
115
|
<div class='mb-3'>
|
94
|
-
<label for='
|
95
|
-
<
|
96
|
-
|
97
|
-
</select>
|
116
|
+
<label for='transaction_id'>Transaction ID</label>
|
117
|
+
<input maxlength='10' pattern='[a-zA-z0-9]*' type='text' class='form-control' id='transaction_id' value='#{qrcode_data["transaction_id"]}' name='transaction_id'>
|
118
|
+
<div class='form-text'>Only numbers and simple characters, without whitespaces.</div>
|
98
119
|
</div>
|
99
120
|
<div class='mb-3'>
|
100
|
-
<label for='
|
101
|
-
<
|
102
|
-
|
103
|
-
</select>
|
121
|
+
<label for='amount'>Amount</label>
|
122
|
+
<input type='number' step='0.01' pattern='[0-9]{1,}\.[0-9][0-9]' class='form-control' id='amount' value='#{qrcode_data["amount"]}' name='amount'>
|
123
|
+
<div class='form-text'>Only numbers with 2 decimal places.</div>
|
104
124
|
</div>
|
105
125
|
<div class='mb-3'>
|
106
126
|
<label for='postal_code'>Postal code</label>
|
107
|
-
<input type='
|
127
|
+
<input maxlength='8' pattern='[0-9]{8}' type='tel' class='form-control' id='postal_code' value='#{qrcode_data["postal_code"]}' name='postal_code'>
|
128
|
+
<div class='form-text'>Only numbers.</div>
|
108
129
|
</div>
|
109
130
|
<div class='mb-3'>
|
110
|
-
<label for='repeatable'>
|
131
|
+
<label for='repeatable'>Can be paid multiple times?</label>
|
111
132
|
<select required id='repeatable' name='repeatable' class='form-select'>
|
112
|
-
<option
|
113
|
-
<option value='t'>Yes</option>
|
114
|
-
<option value='f'>No</option>
|
133
|
+
<option></option>
|
134
|
+
<option value='t' #{qrcode_data['repeatable'] == 't' ? 'selected' : ''}>Yes</option>
|
135
|
+
<option value='f' #{qrcode_data['repeatable'] == 'f' ? 'selected' : ''}>No</option>
|
115
136
|
</select>
|
116
137
|
</div>
|
117
|
-
<div class='d-grid gap-2'>
|
138
|
+
<div class='d-grid gap-2' style='padding-bottom: 20px;'>
|
118
139
|
<button type='submit' class='btn btn-lg btn-primary'>Generate</button>
|
119
140
|
</div>
|
120
141
|
</form>
|
@@ -124,8 +145,6 @@ def generate_html_with(env)
|
|
124
145
|
<br>
|
125
146
|
<br>
|
126
147
|
#{payload}
|
127
|
-
<br>
|
128
|
-
<br>
|
129
148
|
#{data_uri}
|
130
149
|
</div>
|
131
150
|
</div>
|
data/lib/qrcode_pix_ruby.rb
CHANGED
@@ -3,6 +3,8 @@
|
|
3
3
|
require 'rqrcode'
|
4
4
|
|
5
5
|
module QrcodePixRuby
|
6
|
+
class PayloadArgumentError < ArgumentError; end
|
7
|
+
|
6
8
|
class Payload
|
7
9
|
ID_PAYLOAD_FORMAT_INDICATOR = '00'
|
8
10
|
ID_POINT_OF_INITIATION_METHOD = '01'
|
@@ -22,17 +24,17 @@ module QrcodePixRuby
|
|
22
24
|
ID_ADDITIONAL_DATA_FIELD_TEMPLATE_TXID = '05'
|
23
25
|
ID_CRC16 = '63'
|
24
26
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
27
|
+
ATTRIBUTES = %i[pix_key url repeatable currency country_code description postal_code
|
28
|
+
merchant_name merchant_city transaction_id amount].freeze
|
29
|
+
|
30
|
+
def initialize(**kwargs)
|
31
|
+
verify_kwargs(kwargs.keys)
|
32
|
+
|
33
|
+
ATTRIBUTES.each do |attribute|
|
34
|
+
singleton_class.class_eval { attr_accessor attribute }
|
35
|
+
instance_variable_set("@#{attribute}", kwargs[attribute])
|
36
|
+
end
|
37
|
+
end
|
36
38
|
|
37
39
|
def payload
|
38
40
|
p = ''
|
@@ -68,6 +70,14 @@ module QrcodePixRuby
|
|
68
70
|
|
69
71
|
private
|
70
72
|
|
73
|
+
def verify_kwargs(keys)
|
74
|
+
unknowns = keys - ATTRIBUTES
|
75
|
+
|
76
|
+
return unless unknowns.any?
|
77
|
+
|
78
|
+
raise QrcodePixRuby::PayloadArgumentError, "Unknown attributes: #{unknowns.join(', ')}"
|
79
|
+
end
|
80
|
+
|
71
81
|
def emv(id, value)
|
72
82
|
size = value.to_s.length.to_s.rjust(2, '0')
|
73
83
|
"#{id}#{size}#{value}"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: qrcode_pix_ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pedro Furtado
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: exe
|
13
13
|
cert_chain: []
|
14
|
-
date: 2021-07-
|
14
|
+
date: 2021-07-13 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: rqrcode
|