r2soft / r2-sicredi-api
A PHP SDK for the Sicredi API
Requires
- guzzlehttp/guzzle: ^7.0
Requires (Dev)
- ergebnis/composer-normalize: ^2.28
- fakerphp/faker: ^1.21
- phpunit/phpunit: ^9.6.7
- vlucas/phpdotenv: ^5.5
- yoast/phpunit-polyfills: ^1.0
README
This package provides a PHP client for interacting with the Sicredi API. It allows developers to easily integrate Sicredi into their PHP applications. The client supports a wide range of features inside the Charges API, including creating and querying boletos, generating boletos slips, and retrieving payment reports.
The package is built on top of the Guzzle HTTP client and provides a simple, object-oriented API for interacting with the Sicredi API. It also includes comprehensive documentation and examples to help developers get started quickly.
While the package currently only supports the API for Boletos, it is designed with extensibility in mind, and can easily be extended to support additional functionality as needed.
Installation
First, you will need to install Composer following the instructions on their site.
Then, simply run the following command:
composer require BrunoPansani/sicredi-api
Usage
Once you have installed it, you can use the following steps to create a new Boleto:
- Create a new Client instance: Create a new Client instance by passing your SICREDI API key, cooperative number, post number, and beneficiary number as arguments. For example:
$client = new \SicrediAPI\Client( $_ENV['SICREDI_API_KEY'], $_ENV['SICREDI_COOPERATIVE'], $_ENV['SICREDI_POST'], $_ENV['SICREDI_BENEFICIARY'], new \GuzzleHttp\Client(), true);
This example uses environment variables, but feel free to use any method you prefer to pass the parameters.
-
Call the authenticate() method on the Client instance to authenticate with the Sicredi API by passing your Sicredi API username and password as arguments.
-
Get the Boleto resource client from the Client instance by calling the boleto() method. For example:
$client->authenticate($_ENV['SICREDI_USERNAME'], $_ENV['SICREDI_PASSWORD']); $boletoClient = $client->boleto();
- Create a new Boleto instance by passing the necessary parameters, such as beneficiary information, payee information, amount, and due date. For example:
$boleto = new \SicrediAPI\Domain\Boleto\Boleto( (new Beneficiary( 'Jose da Silva', '86049253099', 'person' )), (new Payee( 'Maria de Lurdes', '50581718054', 'person' )), 100.00, 'DM', 12345, 'RECIBO', '999999', new DateTime('2023-12-31') );
- Call the create() method on the Boleto resource client to create the Boleto. For example:
$boletoClient->create($boleto);
- Store and/or do anything else you need to do with the Boleto information returned by the create() method.
Validation and Production
Before using the Cobrança API friom Sicredi, please follow the sequential steps for validation and production contained in the attached manual, available at docs/.
In summary, the process for validation includes the following steps:
- Access the Developer Portal
- Create an APP for Sandbox
- Request the Sandbox API Token
- Test the URLs available in the Homologation environment
- Create an APP for Production
- Request the Production API Token
- Test the URLs available in the Production environment
- Deploy your solution
To create the Sandbox APP, the developer must access the Sicredi Developer Portal, create an account or log in, and create a new application with the prefix "API Cobrança Sandbox".
After creating the Sandbox APP, the developer should request the Sandbox API Token through the menu 'Suporte' > 'Abrir Chamado' in the Developer Portal. Select the appropriate option and fill in the name of the APP created previously. The API Token will be generated within a few days and can be found in the 'Minhas Apps' menu, under the details of the respective application.
The URLs available for testing can be found in the API manual.
For the production process, repeat the same steps for creating the APP, but with a different name, such as "API Cobrança Production". After creating the APP, request the API Token for Production, following the same steps as for Sandbox.
Remember that, in all operations, the authentication token received must be informed in the x-api-key
header of the request. This token is different for each environment.
If you have any doubts, please contact the support channels listed in the attached manual, or visit the Developer Portal.
Contributing
We welcome contributions to this package! If you would like to contribute, please follow these guidelines:
- Fork the repository and make your changes.
- Submit a pull request with a clear explanation of your changes and why they are necessary.
- Be responsive to feedback and open to making changes to your pull request.
Remember you can always check Sicredi's documentation available at docs/.
Thank you for your interest in contributing to this package!
License
This package is released under the MIT License.
Contact
If you have any questions or issues, please contact me at bruno@pansani.dev.