PHP
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).
Prerequisites
To run the Mangopay PHP SDK, you’ll need:
- A
ClientIdand 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
- Install the Mangopay package
- Add the autoloader in your project
Installation without Composer
- 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
- Include the autoloader in your project
2. Initialize and configure the SDK
The configuration object of the SDK supports all the following properties:
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.
In order to retrieve the request made using the idempotency key:
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:
You can also provide your own logger:
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 PHP try…catch block to handle API errors, for example: