PHP

In addition to our API being fully RESTful with JSON responses, we offer the convenience you need through our PHP SDK. It is already prepared to do your authentication automatically and has functions to generate your charges among many other features.

Below, check out the procedures for installing the Gerencianet's SDK in PHP:


Installing via Packagist with Composer

composer require gerencianet/gerencianet-sdk-php

Installing Latest Version via GitHub with Git

git clone https://github.com/gerencianet/gn-api-sdk-php.git
cd gn-api-sdk-php/
composer install

It is important to note that the cURL, json, ext-simplexml & openssl extensions must be enabled.

caution

We currently make four versions of the SDK available. Version 1.x and 2.x is compatible with PHP versions higher than version 5.4 and lower than 7.0, also having some outdated components, such as Guzzle. If you have a PHP version higher than 5.5 and lower than 7.0, we suggest using version 3.x of our SDK. For PHP versions greater than or equal to 7.2, we suggest you install SDK version 4.x.



1. Requirements

The following requirements must be considered, depending on the branch used:

Versão da SDKStatusPacote no PackagistCompatibilidade com PHP
1.xSustainedgerencianet/gerencianet-sdk-php:1.0.17>= 5.4 (not compatible with PHP 7.x)
2.xSustainedgerencianet/gerencianet-sdk-php:2.4.1>= 5.5 (not compatible with PHP 7.x)
3.xSustainedgerencianet/gerencianet-sdk-php:3.1.0> = 5.6 (not compatible with PHP 7.x e Guzzle <= 6.5.2)
4.xSustainedgerencianet/gerencianet-sdk-php> = 7.2
note

To use the library in PHP, we recommend installing it through Composer (dependency manager).

If you prefer to proceed without Composer, just follow the procedures described in the title 4. Installing Gerencianet's PHP library without Composer.



2. Installing Composer on Windows

We will install Composer on Windows to download our libraries. If you prefer, you can follow the tutorial on Composer's official website on this link.

a) First, let's download the Composer installer for Windows from this link and once the download is finished, run it;

b) You will need to provide your PHP installation path. If you are using a Wamp server, for example, and during installation you get a message related to the "openssl" file, you will need to inform your PHP *.exe file contained in the Wamp root directory (generally in \wamp\bin\php\ php.7.2\). It should be noted that the php.7.2 folder refers to the PHP version that is being used in the preparation of these instructions, therefore, this directory may have another name, according to your PHP version;

c) During installation, after specifying your PHP directory, click on next. The installation may return an alert message regarding the "openssl" configuration. This is a common message that means "openssl" is disabled, however, let's fix it quickly and easily.


note

If no message about "openssl" is returned, just proceed to the subheading Downloading dependencies, located below.

To enable your "openssl", you will need to change the php.ini.

a) Open your php installation directory and locate the file php.ini;

b) Open the php.ini file in a text editor (eg notepad++, sublime, etc) and press CTRL + F and search for the word “openssl” (without the quotes);

c) The semicolon ( ; ) disables the php_openssl.dll. Clear this sign and it will enable the file:

  • It is like this: ;extension=php_openssl.dll

  • It should look like this: extension=php_openssl.dll

Now save the document (press CTRL + S) and close the file.

d) The extension will be enabled and you will be able to continue with the installation. In order for the installation to update relative to the procedure, it is important that you return to a screen and then proceed with the installation normally.


Downloading dependencies

a) Create a folder called composer in your Wamp directory, inside the www folder, so that it has this structure: \wamp\www\composer

b) Now, let's install the dependencies. Open the Windows Command Prompt (cmd) and navigate to the root directory unde \wamp\www\composer

c) Let's run the dependency installation command (Gerencianet PHP SDK) inside that directory. To do this, run the command below:

composer require gerencianet/gerencianet-sdk-php

d) After running the command, all dependencies will be installed in your directory, including the vendor folder with the autoload.php file.

3. Installing Composer on Linux

You can install Composer in each project (local installation) or have access to it from any part of the system (global installation). If you prefer, you can follow the tutorial on Composer's official website on this link Here, we are going to perform the global installation. To do so, run the following command in Terminal:

$ curl -sS https://getcomposer.org/installer | php
$ sudo mv composer.phar /usr/local/bin/composer

File "composer.json"

One of the main files to work with Composer is composer.json. This is where the instructions about the packages that will be used in the project are contained. This is a common .json file that should be at the root of your project.

The require directive in the composer.json file tells Composer which packages are needed by the project - in this case, the central repository is Packagist.

Now, let's inform Composer that Gerencianet will be part of the dependency management by inserting the content below at the end of the composer.json file (which should be at the root of the project):

{"require":
{
"gerencianet/gerencianet-sdk-php": "^4.*"
}
}

It's time to install the packages. Go to the directory where your project is in Terminal and run:

$ composer install

And ready! Dependencies will download automatically, they will be stored in their respective folders and Composer will continue with the rest of the work by generating the composer.lock file.

It should be noted that, if you need, for example, to delete a package, just delete its reference from the composer.json file and update Composer using the following command:

$ composer update

This way Composer will be updated and since the package is no longer present in the require directive, it will immediately be "uninstalled".

Summary:

  • Install Compose;
  • Inform, in the composer.json file, the Gerencianet SDK that will be installed;;
  • Run the install command in the project directory: $ composer install;
  • Ready!

4. Installing Gerencianet's PHP library without Composer

The use of Composer (dependency manager) is recommended, but not mandatory. If you are interested in proceeding without using it, you can directly download one of our branches, unzip and upload the folder (including the "autoload.php" file) to your project directory.

We currently offer four branches, entitled master, 3.x, 2.x, and 1. x, being:

  • master: uses recent version of guzzle (^7.0.0) and is compatible with recent versions of PHP above 7.2. This is the default version when downloaded from Composer and is suitable for all projects. Access the Packagist.
  • 3.x: uses up to guzzle version (6.0.0) and is compatible with PHP versions (5.5, 5.6, 7.x). Access the Packagist.
  • 2.x: uses up to guzzle version (6.0.0) and is compatible with PHP versions (5.5, 5.6, 7.0 and 7.1). Access the Packagist.
  • 1.x: previous version of the SDK, compatible with PHP 5.4 and 5.5 and uses guzzle 5.3.0. Download at this link.

The master branch is the default branch, however you can install the 1.x branch. Throughout this page you will find guidelines for both versions.

It is important to reinforce that the content present in this .zip is just a requirement for you to start using Gerencianet's PHP SDK. This folder by itself is not a "ready example" of using the Gerencianet's API, but the Gerencianet's PHP SDK that allows the use of the API.


5. Common errors (cURL error 60 or cURL error 77)

The following errors are not from the Gerencianet's API, but related to your server components. Check below the most common errors during the installation of our API and see the solutions:

cURL error 60

cURL error 77


6. Video: Installing Composer (Windows and Linux)

Thinking about offering new ways of transmitting information, Gerencianet makes the following videos available in order to explain, in a clear and objective way, how to install Composer in the Windows and Linux operating system.

Installing Composer on Windows



Installing Composer on Linux



7. Extra: timeout option

This attribute is present in the PHP SDK and allows you to define in the Guzzle request how long you want the response to be returned. For details on how to use, see our Github repository.