Portuguese | English
PHP SDK for integrating with Efí APIs to issue Pix, boletos, carnês, credit cards, subscriptions, payment links, marketplaces, Pix via Open Finance, boleto payments, and other functionalities. For more technical information and #/fees, visit our website.
Go to:
- Requirements
- Tested With
- Version Guide
- Installation
- Getting Started
- Running Examples
- How to Get Client-Id and Client-Secret Credentials
- How to Generate a Pix Certificate
- How to Register Pix Keys
- Compatible Frameworks
- Additional Documentation
- Discord Community
- Migration Validator
- License
- PHP >= 7.2.5
- Guzzle >= 7.0
- openssl extension enabled in PHP
PHP 7.2, 7.3, 7.4, 8.0, 8.1, 8.2, 8.3, 8.4
Version | Status | Packagist | Repo | PHP Version |
---|---|---|---|---|
1.x | Maintained | /efipay/sdk-php-apis-efi | v1 | >= 7.2.5 |
Clone this repository and run the command to install dependencies
git clone https://github.com/efipay/sdk-php-apis-efi.git
composer install
Or if you already have a project managed with Composer, include the dependency in your composer.json
file:
...
"require": {
"efipay/sdk-php-apis-efi": "^1"
},
...
Or download this package directly with Composer:
composer require efipay/sdk-php-apis-efi
To get started, you must configure the credentials in the /examples/credentials/options.php
file. Instantiate the clientId
, clientSecret
for authentication, and sandbox
as true if your environment is Sandbox, or false if it's Production. Except for the Charges API (Boleto/Carnê/Credit Card), it is mandatory to provide the certificate
attribute with the absolute path to the file in .p12
or .pem
format. In the section below, you can follow how to obtain the credentials and certificate.
See an example of credential configuration in the SDK:
$options = [
"clientId" => "Client_Id...",
"clientSecret" => "Client_Secret...",
"certificate" => realpath(__DIR__ . "/certificateFile.p12"), // Mandatory, except for the Charges API | Absolute path to the certificate in .p12 or .pem format
"pwdCertificate" => "", // Optional | Default = "" | Certificate encryption password
"sandbox" => false, // Optional | Default = false | Sets the development environment between Production and Sandbox
"debug" => false, // Optional | Default = false | Enables/disables Guzzle request logs
"timeout" => 30, // Optional | Default = 30 | Sets the maximum response time for requests
"responseHeaders" => false, // Optional | Default = false || Enables/disables the return of request headers
];
To start the SDK, require the module and namespaces:
require __DIR__ . '/vendor/autoload.php';
use Efi\Exception\EfiException;
use Efi\EfiPay;
Although the responses from the API services are in JSON format, the SDK will convert the API response into an array. The code should be inside a try-catch block and handled as follows:
try {
$api = new EfiPay($options);
/* call the desired function */
} catch(EfiException $e) {
/* API errors will come here */
print_r($e->code . "<br>");
print_r($e->error . "<br>");
print_r($e->errorDescription . "<br>");
} catch(Exception $e) {
/* Other errors will come here */
print_r($e->getMessage());
}
You can run using any web server, such as Apache or nginx, and open any example in your browser or command line. See all examples here.
/examples/charges/billet/createOneStepBillet.php
or /examples/pix/cob/pixCreateCharge.php
.
- Access the Efí digital account dashboard in the API menu.
- In the side menu, click on Applications and then Create Application.
- Enter a name for the application and select which APIs you want to activate:
- Charges API (boletos, carnês, credit cards, payment links, subscriptions);
- Pix API;
- Pix via Open Finance API;
- Bill Payment API;
- Statements API.
- Select the Production and Sandbox scopes you want to enable.
- Click on Create Application.
- Enter your Electronic Signature to confirm the application creation.
All API requests, except for the Charges API, must include a security certificate provided by Efí in your account, in PFX (.p12) format.
- Access the Efí digital account dashboard in the API menu.
- In the side menu, click on My Certificates and choose the desired environment: Production or Sandbox.
- Click on Create Certificate.
- Enter your Electronic Signature or authenticate with the QR Code to confirm the creation.
Pix key registration can be done via the Efí mobile app, web account, or an API endpoint. Below are the steps to register them.
- Access your digital account.
- In the side menu, click on Pix.
- Select My Keys and then click on the Register Key button.
- Choose at least one of the 4 available key options:
- CPF/CNPJ
- Phone
- Random Key
- After registering the desired Pix keys, click on Continue.
- Enter your Electronic Signature to confirm the registration.
The endpoint used to create a random Pix key (EVP) is POST /v2/gn/evp
(Create EVP Key). It's worth noting that this endpoint can only register random Pix keys.
To consume it, simply run the /examples/exclusive/key/pixCreateEvp.php
example from our SDK. The request sent to this endpoint does not require a body.
The response below represents a success example (201), with the Pix key registered:
{
"key": "345e4568-e89b-12d3-a456-006655440001"
}
Framework | Minimum Compatible Version | Notes |
---|---|---|
Laravel | 7.x and higher | PHP >= 7.2.5, Guzzle 7.0, Symfony/Cache >= 5.0 |
CodeIgniter | 4.x and higher | PHP >= 7.2.5 (Guzzle and Symfony/Cache, if used) |
Symfony | 5.0 and higher | PHP >= 7.2.5, Guzzle 7.0, Symfony/Cache >= 5.0 |
The SDK can also be integrated with other PHP frameworks. Ensure you meet the minimum requirements.
The complete documentation with all endpoints and API details is available at https://dev.efipay.com.br/.
If you don't have an Efí Bank digital account yet, open yours now!
If you need to integrate your system or application with a complete payment API, want to exchange experiences, and share your knowledge, connect to the Efí community on Discord.
If you already have an integration with the Gerencianet PHP SDK and are looking to prepare your application for the future innovations of Efí APIs, you can use our validator to assist in migrating to this SDK.
The Efí SDK Migration Validator makes the migration process smoother and more efficient. This tool does not modify your code, it only analyzes the existing code for specific patterns related to classes and methods that have been modified in the new SDK version.
Before making any changes to your application's code, it is highly advisable to make a full backup of your entire project.
- Download the Migration Validator.
- Make sure to place this
migrationChecker.php
file in the root directory of your project. - Modify the
migrationChecker.php
file and ensure you correctly insert the paths to thecomposer.json
andinstalled.json
files on lines 55 and 56. - Run the Migration Checker, which will analyze your files for issues.
- Review the results presented, identifying the code segments that need updating.
- Make the recommended corrections, following the displayed instructions.
The checker helps identify potential migration issues and offers correction suggestions, but it's essential to remember that each application is unique and may have peculiarities that cannot be automatically addressed. After making the suggested corrections, it is highly recommended to perform extensive testing on your application to validate the proper functioning of the SDK.