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 →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
- Install the Mangopay package
- Add the autoloader in your project
Installation without Composer
- Download the Mangopay package
- Include the autoloader in your project
2. Initialize and configure the SDK
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.
Call - Create user with idempotency key
Call - View API Response
Output
Pagination and filtering
For endpoints that support pagination and filtering, you can use thePagination()
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:Logging
The Mangopay SDK can integrate the Symfony Logger component. To use this feature, you need to enable debug mode:Output - View a user
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
MangoPayApi
instance.
For more information, see the rate limiting article.