Skip to content

Commit 8032a6b

Browse files
committed
🐛 Fixed the pix generated text.
1 parent 9707210 commit 8032a6b

5 files changed

Lines changed: 25 additions & 15 deletions

File tree

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Seja bem vindo ao repositório. Aqui você encontrará como esse framework foi feito, exemplos de uso, dependencias usadas.
44

5-
* Versão Atual: 1.0.0 (Instável).
5+
* Versão Atual: 1.1.0 (Instável).
66

77
## Importe o framework para seu projeto:
88

@@ -20,7 +20,7 @@ Seja bem vindo ao repositório. Aqui você encontrará como esse framework foi f
2020
<dependency>
2121
<groupId>com.github.mattnicee7</groupId>
2222
<artifactId>PixQRCodeGenerator</artifactId>
23-
<version>1.0.0</version>
23+
<version>1.1.0</version>
2424
</dependency>
2525
</dependencies>
2626
```
@@ -32,7 +32,7 @@ repositories {
3232
}
3333
3434
dependencies {
35-
implementation 'com.github.mattnicee7:PixQRCodeGenerator:1.0.0'
35+
implementation 'com.github.mattnicee7:PixQRCodeGenerator:1.1.0'
3636
}
3737
```
3838

build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ plugins {
33
}
44

55
group 'com.github.mattnicee7'
6-
version '1.0.0'
6+
version '1.1.0'
77

88
repositories {
99
mavenCentral()
1010
}
1111

1212
dependencies {
13+
implementation 'org.projectlombok:lombok:1.18.20'
1314
compileOnly('org.projectlombok:lombok:1.18.24')
1415
annotationProcessor("org.projectlombok:lombok:1.18.20")
1516

src/main/java/com/github/mattnicee7/pixqrcode/App.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,8 @@ public static void main(String[] args) {
2626
.build();
2727

2828
System.out.printf("Pix QRCode Example Without Value: %s %n", pixQRCodeExampleWithoutValue.getAsText());
29-
// Output:
30-
// 00020126410014BR.GOV.BCB.PIX0119mypix@tests.com5204000053039865802BR5925Fantasy Name6011Sao Paulo62130509SalaryPayment6304F3E5
3129

3230
System.out.printf("PIX QRCode Example With Value: %s %n", pixQRCodeExampleWithValue.getAsText());
33-
// Output:
34-
// 00020126410014BR.GOV.BCB.PIX0119mypix@tests.com5204000053039865407123.455802BR5925Other Fantasy Name6011Brasilia6213050913thSalaryPayment6304577C
3531
}
3632

3733
}

src/main/java/com/github/mattnicee7/pixqrcode/pixqrcode/PixQRCode.java

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@ public String getAsText() {
2929
stringBuilder.append("");
3030

3131
// Merchant Account Information - PIX:
32-
stringBuilder.append("26410014BR.GOV.BCB.PIX");
33-
stringBuilder.append("0119").append(this.pixKey);
32+
final String merchantAccountInformation = "0014BR.GOV.BCB.PIX" + "01" + pixKey.length() + this.pixKey;
33+
stringBuilder.append("26")
34+
.append(merchantAccountInformation.length())
35+
.append(merchantAccountInformation);
3436

3537
// Merchant Category Code:
3638
stringBuilder.append("52040000");
@@ -40,22 +42,33 @@ public String getAsText() {
4042

4143
// Transaction Amount:
4244
if (withValue)
43-
stringBuilder.append("5407").append(value);
45+
stringBuilder.append("54")
46+
.append(String.valueOf(value).length() < 10 ? "0" + String.valueOf(value).length() : String.valueOf(value).length())
47+
.append(value);
4448

4549
// Country Code:
4650
stringBuilder.append("5802BR");
4751

4852
// Merchant Name:
49-
stringBuilder.append("5925").append(receiverFullName);
53+
stringBuilder.append("59")
54+
.append(receiverFullName.length())
55+
.append(receiverFullName);
5056

5157
// Merchant City:
52-
stringBuilder.append("6011").append(receiverCity);
58+
stringBuilder.append("60")
59+
.append(receiverCity.length() < 10 ? "0" + receiverCity.length() : receiverCity.length())
60+
.append(receiverCity);
5361

5462
// Postal code:
5563
stringBuilder.append("");
5664

5765
// Additional Data Field:
58-
stringBuilder.append("62130509").append(transactionIdentifier);
66+
final String transactionIdentifierFinalString =
67+
"05" + (transactionIdentifier.length() < 10 ? "0" + transactionIdentifier.length() : transactionIdentifier.length()) + transactionIdentifier;
68+
69+
stringBuilder.append("62")
70+
.append(transactionIdentifierFinalString.length() < 10 ? "0" + transactionIdentifierFinalString.length() : transactionIdentifierFinalString.length())
71+
.append(transactionIdentifierFinalString);
5972

6073
// Unreserved Templates:
6174
stringBuilder.append("");

src/main/java/com/github/mattnicee7/pixqrcode/pixqrcode/PixQRCodeBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ public PixQRCodeBuilder pixKey(@NotNull String pixKey) throws InvalidValueFormat
163163
if (pixKey == null || pixKey.trim().equals(""))
164164
throw new InvalidValueFormatException("A chave PIX não pode ser um campo vazio ou nulo");
165165

166-
this.pixQRCode.setPixKey(pixKey);
166+
this.pixQRCode.setPixKey(pixKey.toUpperCase());
167167

168168
return this;
169169
}

0 commit comments

Comments
 (0)