PHPackages                             mangopay/php-sdk-v2 - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. mangopay/php-sdk-v2

Abandoned → [mangopay4/php-sdk](/?search=mangopay4%2Fphp-sdk)Library[API Development](/categories/api)

mangopay/php-sdk-v2
===================

PHP SDK for MANGOPAY

3.51.0(2mo ago)22.9M↓17.7%1[9 issues](https://github.com/Mangopay/mangopay4-php-sdk/issues)[3 PRs](https://github.com/Mangopay/mangopay4-php-sdk/pulls)12MITPHPPHP &gt;=5.6CI passing

Since Aug 20Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/Mangopay/mangopay4-php-sdk)[ Packagist](https://packagist.org/packages/mangopay/php-sdk-v2)[ RSS](/packages/mangopay-php-sdk-v2/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (6)Versions (212)Used By (12)

MANGOPAY PHP SDK [![mangopay2-php-sdk-cd](https://github.com/Mangopay/mangopay2-php-sdk/actions/workflows/build.yaml/badge.svg)](https://github.com/Mangopay/mangopay2-php-sdk/actions/workflows/build.yaml) [![Latest Stable Version](https://camo.githubusercontent.com/0ad52b72d2591e61ba540b5a4fc6e8eae5e0e8d0db62860b8f4967d383cc3536/68747470733a2f2f706f7365722e707567782e6f72672f6d616e676f706179342f7068702d73646b2f762f737461626c65)](https://packagist.org/packages/mangopay4/php-sdk) [![Total Downloads](https://camo.githubusercontent.com/ea5f789fb2b257633f41ef524ca9f8ec7360178d46d11fa5ac648c79888fa5fa/68747470733a2f2f706f7365722e707567782e6f72672f6d616e676f706179342f7068702d73646b2f646f776e6c6f616473)](https://packagist.org/packages/mangopay4/php-sdk) [![License](https://camo.githubusercontent.com/4a10511e81ec084f4e79221b988ff3ac769eb1e9a0711ce9ce491d438e68e000/68747470733a2f2f706f7365722e707567782e6f72672f6d616e676f706179342f7068702d73646b2f6c6963656e7365)](https://packagist.org/packages/mangopay4/php-sdk)
=======================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

[](#mangopay-php-sdk-----)

MangopaySDK is a PHP client library to work with [Mangopay REST API](https://docs.mangopay.com/endpoints/v2.01).

Compatibility Notes
-------------------

[](#compatibility-notes)

- Since v2.1 of this SDK, you must be using at least v2.01 of the API ([more information about the changes required](https://docs.mangopay.com/api-v2-01-overview/))
- If you experience problems with authentification and/or the temporary token file following an SDK update (particularly updating to v2.0 of the SDK), you may need to just delete your temporary file (that you specify with `$api->Config->TemporaryFolder`) - which allows it to be regenerated correctly the next time it's needed

Requirements
------------

[](#requirements)

To use this SDK, you will need (as a minimum):

- PHP 5.6 or newer
- cURL (included and enabled in a standard PHP distribution)
- OpenSSL (included and enabled in a standard PHP distribution)
- [psr/log](https://github.com/php-fig/log) v1.0
- You do not have to use [Composer](https://getcomposer.org/), but you are strongly advised to (particularly for handling the dependency on the PSR Log library)

Installation with Composer
--------------------------

[](#installation-with-composer)

You can use Mangopay SDK library as a dependency in your project with [Composer](https://getcomposer.org/) (which is the preferred technique). Follow [these installation instructions](https://getcomposer.org/doc/00-intro.md) if you do not already have Composer installed. A composer.json file is available in the repository, and it has been referenced from [Packagist](https://packagist.org/packages/mangopay4/php-sdk).

The installation with Composer is easy and reliable:

Step 1 - Add the Mangopay SDK as a dependency by executing the following command:

```
you@yourhost:/path/to/your-project$ composer require mangopay4/php-sdk

```

Step 2 - Update your dependencies with Composer

```
you@yourhost:/path/to/your-project$ composer update

```

Step 3 - Finally, be sure to include the autoloader in your project

```
require_once '/path/to/your-project/vendor/autoload.php';

```

The Library has been added into your dependencies and is ready to be used.

Installation without Composer
-----------------------------

[](#installation-without-composer)

The project attempts to comply with PSR-4 specification for autoloading classes from file paths. As a namespace prefix is `MangoPay\` with base directory `/path/to/your-project/`.

If you're not using PSR-4 or Composer, the installation is as easy as downloading the library and storing it under any location that will be available for including in your project (**don't forget to include the required library dependencies though**):

```
    require_once '/path/to/your-project/MangoPay/Autoloader.php';
```

Alternatively you can download the package in its entirety (ie with all required dependencies) from the [Releases page](https://github.com/Mangopay/mangopay2-php-sdk/releases) (look for the `mangopay2-php-sdk-[RELEASE_NAME].zip` file). Uncompress the zip file you download, and include the autoloader in your project:

```
    require_once '/path/to/your-project/mangopay2-php-sdk/vendor/autoload.php';
```

License
-------

[](#license)

MangopaySDK is distributed under MIT license, see the [LICENSE file](https://github.com/Mangopay/mangopay2-php-sdk/blob/master/LICENSE).

Unit Tests
----------

[](#unit-tests)

Tests are placed under `/path/to/your-project/tests/`. The `/tests/suites/all.php` suite runs ALL tests. You can also use any of `/tests/cases/*.php` to run a single test case.

Contacts
--------

[](#contacts)

Report bugs or suggest features using [issue tracker on GitHub](https://github.com/Mangopay/mangopay2-php-sdk/issues).

Account creation
----------------

[](#account-creation)

You can get yourself a free sandbox account or sign up for a production account by [registering on the Mangopay site](https://www.mangopay.com/start/) (note that validation of your production account involves several steps, so think about doing it in advance of when you actually want to go live).

Configuration
-------------

[](#configuration)

Using the credential info from the signup process above, you should then set `$api->Config->ClientId` to your Mangopay ClientId and `$api->Config->ClientPassword` to your Mangopay APIKey.

You also need to set a folder path in `$api->Config->TemporaryFolder` that SDK needs to store temporary files. This path should be outside your www folder. It could be `/tmp/` or `/var/tmp/` or any other location that PHP can write to. **You must use different folders for your sandbox and production environments.**

`$api->Config->BaseUrl` is set to sandbox environment by default. To enable production environment, set it to `https://api.mangopay.com`.

```
require_once '/path/to/your-project/vendor/autoload.php';
$api = new MangoPay\MangoPayApi();

// configuration
$api->Config->ClientId = 'your-client-id';
$api->Config->ClientPassword = 'your-client-password';
$api->Config->TemporaryFolder = '/some/path/';
//$api->Config->BaseUrl = 'https://api.mangopay.com';//uncomment this to use the production environment

//uncomment any of the following to use a custom value (these are all entirely optional)
//$api->Config->CurlResponseTimeout = 20;//The cURL response timeout in seconds (its 30 by default)
//$api->Config->CurlConnectionTimeout = 60;//The cURL connection timeout in seconds (its 80 by default)
//$api->Config->CertificatesFilePath = ''; //Absolute path to file holding one or more certificates to verify the peer with (if empty, there won't be any verification of the peer's certificate)

// call some API methods...
try {
    $users = $api->Users->GetAll();
} catch(MangoPay\Libraries\ResponseException $e) {
    // handle/log the response exception with code $e->GetCode(), message $e->GetMessage() and error(s) $e->GetErrorDetails()
} catch(MangoPay\Libraries\Exception $e) {
    // handle/log the exception $e->GetMessage()
}
```

mTLS configuration
------------------

[](#mtls-configuration)

### Set the base URL for mTLS

[](#set-the-base-url-for-mtls)

Using mTLS authentication requires your integration to call a base URL with a different hostname from the standard API:

- Sandbox: `https://api-mtls.sandbox.mangopay.com`
- Production: `https://api-mtls.mangopay.com`

If using mTLS, your integration should use the `api-mtls` URLs for all API calls, including OAuth token generation.

**Caution:** Ensure you set the mTLS base URL, as shown in the configuration examples below. If you don’t, the mTLS certificate will not be transferred to Mangopay. When mTLS is enforced, your integration will result in an error.

### Configure the SDK’s mTLS properties

[](#configure-the-sdks-mtls-properties)

The PHP SDK allows you to load Base64-encoded strings from your environment variables. You can also load locally stored file paths, which may be useful during testing.

**Caution:** The file path properties take precedence if both are set.

#### Base64-encoded strings

[](#base64-encoded-strings)

When your `.pem` certificate and private `.key` are stored as encoded strings in a secrets manager, you can load them using the following configuration properties.

**Prerequisite:** The Base64-encoded string properties require PHP ≥ 8.1 compiled against libcurl ≥ 7.71.0.

If this prerequisite is not met, the SDK will throw an exception at runtime because of the `CURLOPT_SSLCERT_BLOB` and `CURLOPT_SSLKEY_BLOB` used under the hood.

PropertyTypeDescription`ClientCertificateString`stringBase64-encoded string of the certificate `.pem` file content.`ClientCertificateKeyString`stringBase64-encoded string of the private `.key` file content.`ClientCertificateKeyPassword`string (optional)String of the passphrase for an encrypted private key.```
$api = new MangoPay\\MangoPayApi();
$api->Config->ClientId = 'your-mangopay-client-id';
$api->Config->ClientPassword = 'your-mangopay-api-key';
// mTLS base URL
$api->Config->BaseUrl = 'https://api-mtls.sandbox.mangopay.com';

// Base64-encoded .pem certificate content
$api->Config->ClientCertificateString = 'MANGOPAY_PEM_B64'

// Base64-encoded private .key content
$api->Config->ClientCertificateKeyString = 'MANGOPAY_KEY_B64'

// Optional: passphrase if the private key is password-protected
$api->Config->ClientCertificateKeyPassword = 'YOUR_CERT_PASSWORD';
```

Typical example with a secrets manager:

```
$cert = $secretsManager->getSecret('MANGOPAY_PEM_B64');
$key  = $secretsManager->getSecret('MANGOPAY_KEY_B64');

$api->Config->ClientCertificateString    = $cert;
$api->Config->ClientCertificateKeyString = $key;
```

#### File paths

[](#file-paths)

If your `.pem` certificate and private `.key` are stored locally, for example during testing, you can load them using the following properties.

**Caution:** If the file path properties are set, they take precedence and the Base64-encoded equivalents are ignored.

PropertyTypeDescription`ClientCertificatePath`stringPath to the certificate `.pem` file.`ClientCertificateKeyPath`stringPath to the private `.key` file.`ClientCertificateKeyPassword`string (optional)String of the passphrase for an encrypted private key.```
$api = new MangoPay\\MangoPayApi();
$api->Config->ClientId = 'your-mangopay-client-id';
$api->Config->ClientPassword = 'your-mangopay-api-key';

// Path to the .pem certificate file
$api->Config->ClientCertificatePath = '/path/to/certificate.pem';

// Path to the private .key file
$api->Config->ClientCertificateKeyPath = '/path/to/private.key';

// Optional: passphrase if the private key is password-protected
$api->Config->ClientCertificateKeyPassword = 'your-cert-password';
```

Sample usage
------------

[](#sample-usage)

```
require_once '/path/to/your-project/vendor/autoload.php';
$api = new MangoPay\MangoPayApi();

// configuration
$api->Config->ClientId = 'your-client-id';
$api->Config->ClientPassword = 'your-client-password';
$api->Config->TemporaryFolder = '/some/path/';

// get some user by id
try {
    $john = $api->Users->Get($someId);
} catch(MangoPay\Libraries\ResponseException $e) {
    // handle/log the response exception with code $e->GetCode(), message $e->GetMessage() and error(s) $e->GetErrorDetails()
} catch(MangoPay\Libraries\Exception $e) {
    // handle/log the exception $e->GetMessage()
}

// change and update some of his data
$john->LastName .= " - CHANGED";
try {
    $api->Users->Update($john);
} catch(MangoPay\Libraries\ResponseException $e) {
    // handle/log the response exception with code $e->GetCode(), message $e->GetMessage() and error(s) $e->GetErrorDetails()
} catch(MangoPay\Libraries\Exception $e) {
    // handle/log the exception $e->GetMessage()
}

// get all users (with pagination)
$pagination = new MangoPay\Pagination(1, 8); // get 1st page, 8 items per page
try {
    $users = $api->Users->GetAll($pagination);
} catch(MangoPay\Libraries\ResponseException $e) {
    // handle/log the response exception with code $e->GetCode(), message $e->GetMessage() and error(s) $e->GetErrorDetails()
} catch(MangoPay\Libraries\Exception $e) {
    // handle/log the exception $e->GetMessage()
}

// get his bank accounts
$pagination = new MangoPay\Pagination(2, 10); // get 2nd page, 10 items per page
try {
    $accounts = $api->Users->GetBankAccounts($john->Id, $pagination);
} catch(MangoPay\Libraries\ResponseException $e) {
    // handle/log the response exception with code $e->GetCode(), message $e->GetMessage() and error(s) $e->GetErrorDetails()
} catch(MangoPay\Libraries\Exception $e) {
    // handle/log the exception $e->GetMessage()
}
```

Sample usage with Composer in a Symfony project
-----------------------------------------------

[](#sample-usage-with-composer-in-a-symfony-project)

You can integrate Mangopay features in a Service in your Symfony project.

MangoPayService.php :

```
