Skip to content

Commit

Permalink
FIX: Description
Browse files Browse the repository at this point in the history
  • Loading branch information
kayon-ariel committed Oct 10, 2024
1 parent 15bf164 commit f1f4fee
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# PixPhp

A PHP library for generating QR codes for PIX payments, including optional transaction descriptions.
A PHP library to generate static PIX codes, facilitating online payments with PIX copy and paste.

![PHP Version](https://img.shields.io/badge/php-%3E%3D8.2-brightgreen) ![License](https://img.shields.io/badge/license-MIT-blue)

Expand Down
13 changes: 7 additions & 6 deletions src/StaticPix.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ public static function generatePix($key, $idTx = '', $amount = 0.00, $descriptio
{
$result = "000201";
$result .= self::formatField("26", "0014br.gov.bcb.pix" . self::formatField("01", PixKey::formatKey($key)));

// Description field (if provided)
if (!empty($description)) {
$result .= self::formatField("02", $description);
}

$result .= "52040000"; // Fixed code
$result .= "5303986"; // Currency (Real)
if ($amount > 0) {
Expand All @@ -39,12 +45,7 @@ public static function generatePix($key, $idTx = '', $amount = 0.00, $descriptio
$result .= "5901N"; // Name
$result .= "6001C"; // City

// Description field (if provided)
if (!empty($description)) {
$result .= self::formatField("62", self::formatField("05", $idTx ?: '***') . self::formatField("50", $description));
} else {
$result .= self::formatField("62", self::formatField("05", $idTx ?: '***'));
}
$result .= self::formatField("62", self::formatField("05", $idTx ?: '***'));

$result .= "6304"; // Start of CRC16
$result .= self::calculateCRC16($result); // Add CRC16 at the end
Expand Down

0 comments on commit f1f4fee

Please sign in to comment.