alt

Important information

The API reference is now available here.
The deprecated API reference is available here.

Unzer

Install PHP SDK

Install the PHP SDK and start integrating with Unzer.

System requirements

Before you begin, make sure that the server fulfils the following requirements to run the SDK:

  • PHP version: PHP || 7.4 || 8.0 || 8.1 || 8.2 (newest SDK-version)
  • ext-json
  • ext-curl: Can be replaced when implementing custom http-Adapter.

The SDK requires UTF-8 encoding because it is using JSON extension for encoding that requires UTF-8.

To set up your UTF-8 encoding, in your Apache configuration set the parameter AddDefaultCharset as follows:

AddDefaultCharset utf-8 

Check the basic integration requirements for additional requirements not related directly to PHP SDK.

PHP configuration

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

; 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

Installation

To install the PHP SDK, use Composer that you can download from the Composer homepage.

What is Composer and how to use it?

Composer is a package dependency manager for PHP, similar to the Linux package managers, such as APT for Ubuntu or Debian.

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.

The installation of Composer depends on your operating system. For more details on the installation instructions, check 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 the composer.json file to your application

icon info
Skip this section if you already use Composer to manage your project.
  1. Open the command line, navigate to the root directory of your project, and type the following command to create the composer.json file:

    composer init
    
  2. When asked, enter the project information, like package name, description, author, minimum stability, packages type, and license.

    • For now all we need is the package name.
  3. Enter no and then press return for both of these questions:

    • Would you like to define your dependencies (require) interactively?
    • Would you like to define your development dependencies (require-dev) interactively?
  4. Enter yes for the Do you confirm generation? question by typing yes and then press return.
    The composer.json file is created, which looks like this:

    {
       "name": "myproject/shop-abc",
       "type": "project",
       "require": {
       }
    }
    

Step 2: Add the Unzer SDK to your application dependencies

Install the SDK using the command line:

composer require unzerdev/php-sdk

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

Step 3: Include the autoloader in your application

The easiest way to make the SDK sources available for your code is to use the Composer autoloader. For example:

require_once(__DIR__ . '/vendor/autoload.php');
icon info
If your framework is already using the autoloader, you don’t need to perform this action.
icon success
Congrats, you have successfully installed the Unzer PHP SDK.