Skip to main content

Introduction

The Mangopay PHP SDK makes working with the Mangopay API easier in a PHP environment. The SDK package is published on Packagist and GitHub: mangopay4-php-sdk
Caution – Use only the mangopay4 package (late Nov 2025)Please ensure you use only the package with mangopay4 in the name (this is the package name and has no connection with the SDK version number).Any other package must not be used. You need to update your package manually.Since November 25, 2025, Mangopay’s official SDKs are no longer accessible on GitHub (with the exception of PHP for publication reasons).
PrerequisitesTo run the Mangopay PHP SDK, you’ll need:
  • A ClientId and an API key – if you don’t have these, contact Sales to get access to the Mangopay Dashboard
  • PHP 5.6 (or higher)
  • cURL
  • OpenSSL
  • psr/log 1.0
  • Composer (optional but recommended for handling dependencies)

Getting started

1. Install the Mangopay package

Installation with Composer

  1. Install the Mangopay package
  1. Add the autoloader in your project

Installation without Composer

  1. Download the Mangopay package
Go to the Releases page and download the SourceCode.zip asset from the most recent release. 2. Uncompress the SourceCode.zip file and move it to your project folder
  1. Include the autoloader in your project

2. Initialize and configure the SDK

The configuration object of the SDK supports all the following properties:
KeyTypeDefault valueDescription
ClientIdstringNoneYour Mangopay ClientId – can be found in the Dashboard.
ClientPasswordstringNoneYour Mangopay API key – can be found in the Dashboard.
BaseUrlstringhttps://api.sandbox.mangopay.com/v2.01/The API sandbox URL. Set to the sandbox environment by default. To enable production environment, set it to https://api.mangopay.com
TemporaryFolderstringNonePath to the folder where the temporary file is created.
CertificatesFilePath stringNonePath to the file holding one or more SSL certificates to verify the peer with. There is no cURL verification of the certificates when it’s set to null.
DebugModebooleantrueFor internal usage only. Logs all request and response data by default. To disable this mode, set it to false.
LogClassstringMangoPay\Libraries\LogsSet the logging class if DebugMode is enabled.
CurlConnectionTimeoutinteger30cURL connection timeout in seconds.
CurlResponseTimeoutinteger30cURL reset timeout in seconds.
HostProxystringNoneThe HTTP proxy to tunnel requests through.
UserPasswordProxystringNoneUsername and password formatted as [username]:[password] to use for the connection to the proxy.

SDK usage

In the Mangopay documentation, you’ll find detailed information of all endpoints paired with its corresponding PHP SDK method implementation example. Be sure to customize the provided code to suit your specific requirements.

Idempotency support

To make a request with idempotency support, add $idempotencyKey parameter to your function. For more information, see the Idempotency article.
Call - Create user with idempotency key
In order to retrieve the request made using the idempotency key:
Call - View API Response
Output

Pagination and filtering

For endpoints that support pagination and filtering, you can use the Pagination() and Sorting() methods to specify these options:

Temporary folder

To ensure smooth authentication processes, it’s important to manage the temporary token file effectively.  The temporary file, typically named MangoPaySdkStorage.tmp.php, stores authentication tokens and related temporary data during system operations.  We recommend creating a dedicated folder to store the generated temporary file within the root directory of your application. When initializing your SDK, include your temporary folder path in the configuration:
If you experience problems with the authentication or the temporary token file, you may need to delete your temporary file that is located in the folder path that you specify with. This allows it to be regenerated correctly the next time it’s needed.

Logging

The Mangopay SDK can integrate the Symfony Logger component. To use this feature, you need to enable debug mode:
In debug mode, you will be able to see the logging response:
Output - View a user
You can also provide your own logger:
Call - View a user
Output

Rate limits status

The Mangopay PHP SDK provides a way of verifying how many API calls were made, how many are left and when the counter will be reset.  There are 4 groups of rate limits available:
  • Last 15 minutes
  • Last 30 minutes
  • Last 60 minutes
  • Last 24 hours
This rate limits status information is available from the MangoPayApi instance. For more information, see the rate limiting article.
In debug mode, you can also see the response header in your output:

Unit tests

All tests are placed under /your-project-path/tests/.  You can also use any of the files in /tests/Cases folder to run a single test case.

Error handling

The SDK provides the ResponseException class to wrap HTTP errors from the API, which extends PHP’s native \Exception class. You can use a standard Java try…catch block to handle API errors, for example: