forked from CharlesMendes/brcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpix_validar_brcode_estatico.html
More file actions
468 lines (378 loc) · 21.7 KB
/
pix_validar_brcode_estatico.html
File metadata and controls
468 lines (378 loc) · 21.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
<!DOCTYPE html>
<html>
<title>Pix - Validar BR Code (by Charles Mendes / Daniel Leandro)</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Raleway">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<style>
body,
h1,
h2,
h3,
h4,
h5,
h6 {
font-family: "Raleway", Arial, Helvetica, sans-serif
}
</style>
<body class="w3-border-left w3-border-right">
<!-- !PAGE CONTENT! -->
<div class="w3-sidebar w3-light-grey w3-top">
<div class="w3-container w3-display-container w3-padding-16">
<h2>
<img src="https://www.bcb.gov.br/content/estabilidadefinanceira/piximg/logo_pix.png" width="200px" /> Validar - BR Code</h2>
<hr>
<p><label><i class="fa fa-calendar-check-o"></i> QR Code Estático</label></p>
<textarea class="w3-input w3-border" rows="4" cols="50" placeholder="Pix Copia e Cola" id="qrcode">00020126470014br.gov.bcb.pix0125contato@charlesmendes.com52040000530398654040.075802BR5922CHARLES PEREIRA MENDES6009SAO PAULO62070503***6304DC64</textarea>
<input type="text" id="subqrcode" hidden>
<input type="text" id="subqrcode_payment" hidden>
<p><button class="w3-button w3-green" onclick="validar()">Validar</button> <button class="w3-button w3-amber" onclick="$('#qrcode').text('');">Limpar</button></p>
<center>
<div style="width: 500px" id="reader"></div>
</center>
</div>
<div class="w3-bar-block w3-main w3-white">
<center>versão 19.11.2020.(build 002) - by <a href="mailto:contato@charlesmendes.com">Charles Mendes</a> / <a href="mailto:danielanselmoleandro@gmail.com">Daniel Leandro</a></center>
</div>
<!-- End page content -->
</div>
<!-- Result Modal -->
<div id="result" class="w3-modal">
<div class="w3-modal-content w3-animate-zoom w3-padding-large">
<div class="w3-container w3-white w3-center">
<i onclick='$("#result").css("display","none");' class="fa fa-remove w3-button w3-xlarge w3-right w3-transparent"></i>
<h2 id="resultado_titulo" class="w3-wide">Resultado: <span id="resultado"></span></h2>
<sup><b>(M) = Campo Mandatório / (O) = Campo Opcional</b></sup>
<textarea readonly class="w3-input w3-border" rows="20" cols="50" id="qrcode_validado"></textarea>
<br />
<button type="button" class="w3-button w3-padding-large w3-green w3-margin-bottom" onclick='$("#result").css("display","none");'>Fechar</button>
</div>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://charlesmendes.github.io/brcode/js/html5-qrcode.min.js"></script>
<script>
function onScanSuccess(qrCodeMessage) {
// handle on success condition with the decoded message
}
var html5QrcodeScanner = new Html5QrcodeScanner(
"reader", {
fps: 10,
qrbox: 250
});
function onScanSuccess(qrCodeMessage) {
// handle on success condition with the decoded message
html5QrcodeScanner.clear();
// ^ this will stop the scanner (video feed) and clear the scan area.
}
html5QrcodeScanner.render(onScanSuccess);
function onScanSuccess(qrCodeMessage) {
// handle on success condition with the decoded message
$("#qrcode").text(qrCodeMessage);
}
// DOCUMENTAÇÃO:
// https://www.bcb.gov.br/content/estabilidadefinanceira/SiteAssets/Manual%20do%20BR%20Code.pdf
// https://www.bcb.gov.br/content/estabilidadefinanceira/pix/Regulamento_Pix/II-ManualdePadroesparaIniciacaodoPix-versao2-1.pdf
// CONSTANT
const ID_PAYLOAD_FORMAT_INDICATOR = "00"; // (M) Payload Format Indicator
const DS_PAYLOAD_FORMAT_INDICATOR = "(M) Payload Format Indicator";
const ID_POINT_OF_INITIATION_METHOD = "01"; // (O) Point of Initiation Method
const DS_POINT_OF_INITIATION_METHOD = "(O) Point of Initiation Method";
const ID_MERCHANT_ACCOUNT_INFORMATION = "26"; // (M) 2-51 Merchant Account Information
const DS_MERCHANT_ACCOUNT_INFORMATION = "(M) Merchant Account Information Pix";
//SUB MERCHANT ACCOUNT INFORMATION
const ID_SUBMERCHANT_GUI = "00"; // (M) GUI ARRANJO
const DS_SUBMERCHANT_GUI = "(M) GUI Arranjo";
const ID_SUBMERCHANT_CHAVE = "01"; // (M) Chave Pix
const DS_SUBMERCHANT_CHAVE = "(M) Chave Pix";
const ID_SUBMERCHANT_INFOADICIONAL = "02"; // (O) Info Adicional
const DS_SUBMERCHANT_INFOADICIONAL = "(O) Info Adicional";
const ID_MERCHANT_CATEGORY_CODE = "52"; // (M) Merchant Category Code
const DS_MERCHANT_CATEGORY_CODE = "(M) Merchant Category Code";
const ID_TRANSACTION_CURRENCY = "53"; // (M) Transaction Currency
const DS_TRANSACTION_CURRENCY = "(M) Transaction Currency";
const ID_TRANSACTION_AMOUNT = "54"; // (C) Transaction Amount
const DS_TRANSACTION_AMOUNT = "(C) Transaction Amount";
const ID_TIP_OR_CONVENIENCE_INDICATOR = "55"; // (O) Tip or Convenience Indicator
const DS_TIP_OR_CONVENIENCE_INDICATOR = "(O) Tip or Convenience Indicator";
const ID_VALUE_OF_CONVENIENCE_FEE_FIXED = "56"; // (C) Value of Convenience Fee Fixed
const DS_VALUE_OF_CONVENIENCE_FEE_FIXED = "(C) Value of Convenience Fee Fixed";
const ID_VALUE_OF_CONVENIENCE_FEE_PERCENTAGE = "57"; // (C) Value of Convenience Fee Percentage
const DS_VALUE_OF_CONVENIENCE_FEE_PERCENTAGE = "(C) Value of Convenience Fee Percentage";
const ID_COUNTRY_CODE = "58"; // (M) Country Code
const DS_COUNTRY_CODE = "(M) Country Code";
const ID_MERCHANT_NAME = "59"; // (M) Merchant Name
const DS_MERCHANT_NAME = "(M) Merchant Name";
const ID_MERCHANT_CITY = "60"; // (M) Merchant City
const DS_MERCHANT_CITY = "(M) Merchant City";
const ID_POSTAL_CODE = "61"; // (O) Postal Code
const DS_POSTAL_CODE = "(O) Postal Code";
const ID_ADDITIONAL_DATA_FIELD_TEMPLATE = "62"; // (O) Additional Data Field Template
const DS_ADDITIONAL_DATA_FIELD_TEMPLATE = "(M) Additional Data Field Template";
//SUB ADDITIONAL DATA FIELD TEMPLATE
const ID_SUBADDITIONAL_REFERENCE_LABEL = "05"; // (M) ID DA TRANSAÇÃO TXID
const DS_SUBADDITIONAL_REFERENCE_LABEL = "(M) ID DA TRANSAÇÃO TXID";
const ID_SUBADDITIONAL_SUBREFERENCE_LABEL_PAYMENT_SYSTEM = "50"; // (O) PAYMENT SYSTEM TEMPLATE
const DS_SUBADDITIONAL_SUBREFERENCE_LABEL_PAYMENT_SYSTEM = "(O) PAYMENT SYSTEM TEMPLATE";
const ID_SUBADDITIONAL_SUBREFERENCE_LABEL_PAYMENT_SYSTEM_GUI = "00"; // (O) GUI PAYMENT SYSTEM TEMPLATE
const DS_SUBADDITIONAL_SUBREFERENCE_LABEL_PAYMENT_SYSTEM_GUI = "(O) GUI PAYMENT SYSTEM TEMPLATE";
const ID_SUBADDITIONAL_SUBREFERENCE_LABEL_PAYMENT_SYSTEM_VERSAO = "01"; // (O) VERSAO PAYMENT SYSTEM TEMPLATE
const DS_SUBADDITIONAL_SUBREFERENCE_LABEL_PAYMENT_SYSTEM_VERSAO = "(O) VERSAO PAYMENT SYSTEM TEMPLATE";
const ID_CRC = "63"; // (M) CRC
const DS_CRC = "(M) CRC";
// Decode
var initial_value = 0;
var initial_value_sub = 0;
var initial_value_payment_sub = 0;
var initial_size = 2;
var valor = "";
var tam = "";
var mapConsumers = [];
var mapConsumers_sub = [];
var mapConsumers_payment_sub = [];
var qrcode_valor = "";
var erros = 0;
function clear() {
initial_value = 0;
initial_value_sub = 0;
initial_value_payment_sub = 0;
initial_size = 2;
valor = "";
tam = "";
mapConsumers = [];
mapConsumers_sub = [];
mapConsumers_payment_sub = [];
qrcode_valor = "";
erros = 0;
}
function validar() {
clear();
$("#result").css("display", "block");
$("#qrcode_validado").text(MerchantPresentedMode());
if (erros > 0) {
$("#resultado_titulo").removeClass("w3-green");
$("#resultado_titulo").addClass("w3-red");
$("#resultado").text("INVÁLIDO");
} else {
$("#resultado_titulo").removeClass("w3-red");
$("#resultado_titulo").addClass("w3-green");
$("#resultado").text("SUCESSO");
}
}
function MerchantPresentedMode() {
/* -------------------------------------------------------------- */
consumerMessage(ID_PAYLOAD_FORMAT_INDICATOR, DS_PAYLOAD_FORMAT_INDICATOR, true);
consumerMessage(ID_POINT_OF_INITIATION_METHOD, DS_POINT_OF_INITIATION_METHOD, false);
consumerMessage(ID_MERCHANT_ACCOUNT_INFORMATION, DS_MERCHANT_ACCOUNT_INFORMATION, true);
consumerMessage(ID_MERCHANT_CATEGORY_CODE, DS_MERCHANT_CATEGORY_CODE, true);
consumerMessage(ID_TRANSACTION_CURRENCY, DS_TRANSACTION_CURRENCY, true);
consumerMessage(ID_TRANSACTION_AMOUNT, DS_TRANSACTION_AMOUNT, false);
consumerMessage(ID_COUNTRY_CODE, DS_COUNTRY_CODE, true);
consumerMessage(ID_MERCHANT_NAME, DS_MERCHANT_NAME, true);
consumerMessage(ID_MERCHANT_CITY, DS_MERCHANT_CITY, true);
consumerMessage(ID_POSTAL_CODE, DS_POSTAL_CODE, false);
consumerMessage(ID_ADDITIONAL_DATA_FIELD_TEMPLATE, DS_ADDITIONAL_DATA_FIELD_TEMPLATE, true);
consumerMessage(ID_CRC, DS_CRC, true);
/* -------------------------------------------------------------- */
return JSON.stringify(mapConsumers, null, 4);
}
function consumer(initial, size, sub) {
if (sub == 1) {
return $("#qrcode").val().substr(initial, size);
} else if (sub == 2) {
return $("#subqrcode").val().substr(initial, size);
} else {
return $("#subqrcode_payment").val().substr(initial, size);
}
}
function isEvp(value) {
var regex = /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/i;
var match = regex.exec(value);
return match != null;
}
function isEmail(value) {
var regex = /^([a-z\d!#$%&'*+\-\/=?^_`{|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+(\.[a-z\d!#$%&'*+\-\/=?^_`{|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+)*|"((([ \t]*\r\n)?[ \t]+)?([\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|\\[\x01-\x09\x0b\x0c\x0d-\x7f\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))*(([ \t]*\r\n)?[ \t]+)?")@(([a-z\d\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|[a-z\d\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF][a-z\d\-._~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]*[a-z\d\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])\.)+([a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|[a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF][a-z\d\-._~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]*[a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])\.?$/i;
var match = regex.exec(value);
return match != null;
}
function isCPF(value) {
var regex = /^[0-9]{11}$/i;
var match = regex.exec(value);
return match != null;
}
function isCNPJ(value) {
var regex = /^[0-9]{14}$/i;
var match = regex.exec(value);
return match != null;
}
function isPhone(value) {
var regex = /^\+[1-9][0-9]\d{1,14}$/i;
var match = regex.exec(value);
return match != null;
}
function formatMessage(descricao, valor) {
return descricao + ": [" + valor + "]";
}
function consumerMessage(identificator, description, mandatory) {
var item = {};
valor = consumer(initial_value, initial_size, 1);
if (identificator == valor) {
initial_value += initial_size;
tam = parseFloat(consumer(initial_value, initial_size, 1));
initial_value += initial_size;
valor = consumer(initial_value, tam, 1);
initial_value += tam;
item["_id"] = identificator;
item["descrição"] = description;
if (ID_MERCHANT_ACCOUNT_INFORMATION == identificator) {
$("#subqrcode").val(valor);
consumerSubMessage(ID_SUBMERCHANT_GUI, DS_SUBMERCHANT_GUI, true);
consumerSubMessage(ID_SUBMERCHANT_CHAVE, DS_SUBMERCHANT_CHAVE, true);
consumerSubMessage(ID_SUBMERCHANT_INFOADICIONAL, DS_SUBMERCHANT_INFOADICIONAL, false);
item["valor"] = mapConsumers_sub;
initial_value_sub = 0;
mapConsumers_sub = [];
} else if (ID_ADDITIONAL_DATA_FIELD_TEMPLATE == identificator) {
$("#subqrcode").val(valor);
consumerSubMessage(ID_SUBADDITIONAL_REFERENCE_LABEL, DS_SUBADDITIONAL_REFERENCE_LABEL, true);
consumerSubMessage(ID_SUBADDITIONAL_SUBREFERENCE_LABEL_PAYMENT_SYSTEM, DS_SUBADDITIONAL_SUBREFERENCE_LABEL_PAYMENT_SYSTEM, false);
item["valor"] = mapConsumers_sub;
mapConsumers_sub = [];
} else {
item["valor"] = valor;
}
mapConsumers.push(item);
} else {
if (mandatory == true) {
item["_id"] = identificator;
item["descrição"] = description;
if (ID_PAYLOAD_FORMAT_INDICATOR == identificator) {
item["valor"] = "**** ERRO NESSE CAMPO **** => DEVE SER FIXO '01'";
} else if (ID_MERCHANT_CATEGORY_CODE == identificator) {
item["valor"] = "**** ERRO NESSE CAMPO **** => MCC OBRIGATORIO: '0000' ou MCC ISO-18245";
} else if (ID_TRANSACTION_CURRENCY == identificator) {
item["valor"] = "**** ERRO NESSE CAMPO **** => '986' – BRL: real brasileiro - ISO-4217";
} else if (ID_COUNTRY_CODE == identificator) {
item["valor"] = "**** ERRO NESSE CAMPO **** => 'BR' – Código de país ISO-3166-1 alpha 2";
} else if (ID_MERCHANT_NAME == identificator) {
item["valor"] = "**** ERRO NESSE CAMPO **** => Nome do beneficiário/recebedor";
} else if (ID_MERCHANT_CITY == identificator) {
item["valor"] = "**** ERRO NESSE CAMPO **** => Cidade onde é efetuada a transação, padrão EMV-QRCPS-MPM. Em outros casos (por exemplo em transações online) pode ser utilizada a cidade da agência do recebedor ou a cidade-sede do recebedor";
} else {
item["valor"] = "**** ERRO NESSE CAMPO **** => CAMPO INVÁLIDO OU NÃO INFORMADO ***";
}
erros++;
mapConsumers.push(item);
} else {
item["_id"] = identificator;
item["descrição"] = description;
if (ID_POINT_OF_INITIATION_METHOD == identificator) {
item["valor"] = "**** Campo Opcional => não preechido: Se o valor 12 estiver presente, significa que o BR Code só pode ser utilizado uma vez.";
} else if (ID_TRANSACTION_AMOUNT == identificator) {
item["valor"] = "**** Campo Opcional => não preechido: valor da transação. Ex.: '0', '1.00', '123.99'";
} else if (ID_POSTAL_CODE == identificator) {
item["valor"] = "**** Campo Opcional => não preechido: CEP da localidade onde é efetuada a transação";
} else {
item["valor"] = "**** Campo Opcional => não preechido ****";
}
mapConsumers.push(item);
}
}
}
function consumerSubMessage(identificator, description, mandatory) {
var item = {};
valor = consumer(initial_value_sub, initial_size, 2);
if (identificator == valor) {
initial_value_sub += initial_size;
tam = parseFloat(consumer(initial_value_sub, initial_size, 2));
initial_value_sub += initial_size;
valor = consumer(initial_value_sub, tam, 2);
initial_value_sub += tam;
item["_id"] = identificator;
item["descrição"] = description;
if (ID_SUBADDITIONAL_SUBREFERENCE_LABEL_PAYMENT_SYSTEM == identificator) {
$("#subqrcode_payment").val(valor);
consumerSubPaymentMessage(ID_SUBADDITIONAL_SUBREFERENCE_LABEL_PAYMENT_SYSTEM_GUI, DS_SUBADDITIONAL_SUBREFERENCE_LABEL_PAYMENT_SYSTEM_GUI, false);
consumerSubPaymentMessage(ID_SUBADDITIONAL_SUBREFERENCE_LABEL_PAYMENT_SYSTEM_VERSAO, DS_SUBADDITIONAL_SUBREFERENCE_LABEL_PAYMENT_SYSTEM_VERSAO, false);
item["valor"] = mapConsumers_payment_sub;
initial_value_payment_sub = 0;
mapConsumers_payment_sub = [];
} else {
if (ID_SUBMERCHANT_GUI == identificator && valor.toLowerCase() != "br.gov.bcb.pix") {
item["valor"] = "**** ERRO NESSE CAMPO **** => NÃO INFORMADO ARRANJO 'br.gov.bcb.pix'";
erros++;
} else if (ID_SUBMERCHANT_CHAVE == identificator) {
item["valor"] = valor;
if (!isEmail(valor)) //não é chave e-mail
{
if (!isEvp(valor)) //não é chave evp
{
if (!isCPF(valor)) //não é chave CPF
{
if (!isCNPJ(valor)) //não é chave CNPJ
{
if (!isPhone(valor)) //não é chave Celular
{
item["valor"] = "**** ERRO NESSE CAMPO **** => CHAVE PIX INVÁLIDA: '" + valor + "'";
erros++;
}
}
}
}
}
} else if (ID_SUBADDITIONAL_REFERENCE_LABEL == identificator && valor.trim() == "") {
item["valor"] = "**** ERRO NESSE CAMPO **** => TXID deve ter algum valor ou '***' caso não exista";
erros++;
} else {
item["valor"] = valor;
}
}
mapConsumers_sub.push(item);
} else {
if (mandatory == true) {
item["_id"] = identificator;
item["descrição"] = description;
item["valor"] = "**** ERRO NESSE CAMPO **** => CAMPO INVÁLIDO OU NÃO INFORMADO";
erros++;
mapConsumers_sub.push(item);
} else {
item["_id"] = identificator;
item["descrição"] = description;
item["valor"] = "**** Campo Opcional => não preechido ****";
mapConsumers_sub.push(item);
}
}
}
function consumerSubPaymentMessage(identificator, description, mandatory) {
var item = {};
valor = consumer(initial_value_payment_sub, initial_size, 3);
if (identificator == valor) {
initial_value_payment_sub += initial_size;
tam = parseFloat(consumer(initial_value_payment_sub, initial_size, 3));
initial_value_payment_sub += initial_size;
valor = consumer(initial_value_payment_sub, tam, 3);
initial_value_payment_sub += tam;
item["_id"] = identificator;
item["descrição"] = description;
item["valor"] = valor;
mapConsumers_payment_sub.push(item);
} else {
if (mandatory == true) {
item["_id"] = identificator;
item["descrição"] = description;
item["valor"] = "**** ERRO NESSE CAMPO **** => CAMPO INVÁLIDO OU NÃO INFORMADO";
erros++;
mapConsumers_payment_sub.push(item);
} else {
item["_id"] = identificator;
item["descrição"] = description;
item["valor"] = "**** Campo Opcional => não preechido ****";
mapConsumers_payment_sub.push(item);
}
}
}
</script>
</body>
</html>