PHP
Introduction
The Mangopay PHP SDK makes working with the Mangopay API easier in a PHP environment. This SDK is open-source and available on GitHub.
Mangopay PHP SDK →Prerequisites
To 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
- 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:
Key | Type | Default value | Description |
---|---|---|---|
ClientId | string | None | Your Mangopay ClientId – can be found in the Dashboard. |
ClientPassword | string | None | Your Mangopay API key – can be found in the Dashboard. |
BaseUrl | string | https://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 |
TemporaryFolder | string | None | Path to the folder where the temporary file is created. |
CertificatesFilePath | string | None | Path 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 . |
DebugMode | boolean | true | For internal usage only. Logs all request and response data by default. To disable this mode, set it to false . |
LogClass | string | MangoPay\Libraries\Logs | Set the logging class if DebugMode is enabled. |
CurlConnectionTimeout | integer | 30 | cURL connection timeout in seconds. |
CurlResponseTimeout | integer | 30 | cURL reset timeout in seconds. |
HostProxy | string | None | The HTTP proxy to tunnel requests through. |
UserPasswordProxy | string | None | Username and password formatted as [username]:[password] to use for the connection to the proxy. |
UKHeaderFlag | boolean | false | Platforms that have contracted with Mangopay’s UK entity (MANGOPAY U.K. LIMITED) must include the following header in all requests. If you’re using an SDK, you need to set it to true . |
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.
Report an issue
Found a problem with the SDK? Create an issue on GitHub:
Report an issue →