kaio-souza/pix-php

A simple PIX generator

v1.0 2022-10-27 20:36 UTC

This package is auto-updated.

Last update: 2024-12-08 17:28:23 UTC


README

A simple library to generate media / data to Copy and Paste Pix

Avalilable on Composer

composer require kaio-souza/pix-php

Requeriments

  • To generate Images, the ext php-gd needs to be enable

Instatiate Class

Using Constants to Params (more secure, in cases of update)

$pix = new PixGenerator([
    MandatoryConfig::PIX_KEY => 'teste@teste.com',
    MandatoryConfig::MERCHANT_NAME => 'Tester',
]);

Using String

$pix = new PixGenerator([
   'pix_key' => 'teste@teste.com',
   'merchant_name' => 'Tester',
]);

More Params

$pix = new PixGenerator([
    MandatoryConfig::PIX_KEY => 'teste@teste.com',
    MandatoryConfig::MERCHANT_NAME => 'Tester',
    OptionalConfig::MERCHANT_CITY => 'SAO PAULO', // 'SAO PAULO' is the DefaultValue
    OptionalConfig::CURRENCY => '986', // 986 = BRL | is the DefaultValue
    OptionalConfig::COUNTRY_CODE => 'BR', // 'BR' is the default Alpha2 value
]);

Get QRCode Text

echo $pix->getQrCodeText(20, 'Teste Lala');
// returns 00020126510014br.gov.bcb.pix0115teste@teste.com0210Teste Lala520400005303986540520,005802BR5906Tester6002BR62270523bca37b925af47abd511393463041FC2

Get QRCode Image

// returns QRCode PNG output
$code = $pix->getQrCode(20, 'Teste Lala');
// Save the output on file
file_put_contents('qr.png', $code);

or

$code = $pix->getBase64QrCode('14,50', 'Teste Lala');

// show QRCODE on HTML img tag
echo "<img src='data:image/png;base64, {$code}' />";

** The amount accepts a comma or dots to separate the decimal places