A PHP library to generate static PIX codes, facilitating online payments with PIX copy and paste.
You can install the library via Composer. Run the following command:
composer require kayon-ariel/pix-php
Once installed, include the Composer autoloader in your PHP script:
require 'vendor/autoload.php';
Import the PixPhp namespace at the beginning of your PHP file:
use PixPhp\StaticPix;
You can generate a PIX code using the generatePix method. Here's a basic example:
// Generate a PIX code
$pixCode = StaticPix::generatePix('your-pix-key', 'Transaction-ID', 100.00, 'Payment description');
// Display the generated PIX code
echo $pixCode;
In the PixPhp
library, the following types of keys are accepted for generating PIX codes:
-
CPF (Cadastro de Pessoas Físicas)
- Format:
123.456.789-09
- Description: A Brazilian individual taxpayer identification number. The library accepts CPF numbers with or without formatting.
- Format:
-
CNPJ (Cadastro Nacional da Pessoa Jurídica)
- Format:
12.345.678/0001-95
- Description: A Brazilian business taxpayer identification number. The library accepts CNPJ numbers with or without formatting.
- Format:
-
Email
- Format:
[email protected]
- Description: A valid email address. The library accepts well-formed email addresses as PIX keys.
- Format:
-
Phone
- Format:
+55 11 91234-5678
- Description: A Brazilian phone number including the country code. The library accepts phone numbers with various formatting styles, including spaces and dashes, while retaining the
+55
prefix.
- Format:
-
Random Key
- Format:
617ef6be-e18e-427f-919b-6e43bae33400
- Description: The Pix random key is a 32-character alphanumeric code, randomly generated by the Central Bank to be linked to a single account.
- Format:
You can pass any of the accepted key types to the generatePix
method:
// Using CPF
$pixCodeCpf = StaticPix::generatePix("123.456.789-09", "ID123", 100.00);
// Using CNPJ
$pixCodeCnpj = StaticPix::generatePix("12.345.678/0001-95", "ID456", 250.50);
// Using Email
$pixCodeEmail = StaticPix::generatePix("[email protected]", "ID789", 50.00);
// Using Phone
$pixCodePhone = StaticPix::generatePix("+55 11 91234-5678", "ID101", 75.00);
// Using Random Key
$pixCodeRandom = StaticPix::generatePix("617ef6be-e18e-427f-919b-6e43bae33400", "ID102", 30.00);