Learn how to install and configure the Unzer PHP SDK.

What is composer and how to use it?

Composer is a package dependency manager for PHP. You may know Linux package managers like APT for Ubuntu or Debian, composer is the same for your PHP project.

Composer has two main advantages. First it is easy to use and second it has a build-in autoloader, which will be covered later in this section. To download the composer, go to the composer homepage.

Can I use the SDK without composer?

Yes, but you would have to build your own autoloader.

In this case, you can download the latest release directly from GitHub.

Step 1: Add composer.json to your application

Skip this section if you are already using the composer to manage your project.

Depending on your operating system, follow the installation instructions on the composer homepage.

Open your command-line, navigate to the root directory of your project and type the following command to create the composer.json file:

composer init

Specify the project information and details, such as package name, description, author, minimum stability, packages type, and license. All we need for now is the package name.

Next, answer the following questions: Would you like to define your dependencies (require) interactively? Would you like to define your dev dependencies (require-dev) interactively?

You can skip both by typing no and return.

Finally, answer the question Do you confirm generation? by typing yes and return. The composer.json will be created, which looks like this:

   “name”: “myproject/shop-abc”,
   “type”: “project”,
   “require”: { 

Now, install the PHP SDK.

composer require unzerdev/php-sdk

This installs the latest version of the SDK into the vendor folder and adds the dependency to your composer.json.

Step 2: Include the autoloader in your application

If your framework is already using the autoloader, nothing more needs to be done.

The easiest way to make the SDK sources available to your code is to use the composer autoloader like this:

require_once(__DIR__ . '/vendor/autoload.php');

Make sure to use the correct path.

Step 3: Configure the PHP SDK

To avoid rounding errors when transmitting floating point values to the API, we recommend you to set the following value in your php.ini, which will select an enhanced algorithm for rounding such numbers.

// php.ini
; When floats & doubles are serialized store serialize_precision significant
; digits after the floating point. The default value ensures that when floats
; are decoded with unserialize, the data will remain the same.
serialize_precision = -1

For detailed information on this topic, go to float values.