Welcome to the documentation for the MangoPay SDK, an open-source framework that allows developers to easily integrate with MangoPay’s API. This documentation will walk you through the necessary steps to get started with utilizing MangoPay’s features and building powerful applications.
Prerequisites
Before you begin, please ensure that you have completed the following prerequisites:
- A valid MangoPay account
- An understanding of RESTful APIs
- Basic knowledge of PHP
If you haven’t already, sign up for a MangoPay account on the official website.
Installation
To install the MangoPay SDK, follow the steps below:
- Open your Terminal or Command Prompt
- Change the working directory to your project folder
- Run the command:
composer require mangopay/mangopay2-php-sdk
Quick Start Guide
Follow the steps below to quickly integrate MangoPay into your project:
Step 1: Setup
First, you need to set up the MangoPay client by configuring the API credentials:
// Include the MangoPay SDK
require_once 'vendor/autoload.php';
use MangoPay\MangoPayApi;
// Create an instance of the MangoPay API
$api = new MangoPayApi();
$api->Config->ClientId = 'YOUR_CLIENT_ID';
$api->Config->ClientPassword = 'YOUR_CLIENT_PASSWORD';
$api->Config->BaseUrl = 'https://api.sandbox.mangopay.com';
Step 2: Authentication
Authenticate your client application using the API credentials:
// Authenticate your client
$authentication = $api->Authentication->Create();
// Authorize your client
$api->OAuthTokenManager->StoreToken($authentication->AccessToken);
Step 3: Create a User
Create a new user account using the MangoPay API:
// Create user details
$user = new \MangoPay\UserNatural();
$user->FirstName = 'John';
$user->LastName = 'Doe';
// Create a MangoPay user
$userResult = $api->Users->Create($user);
Step 4: Create a Wallet
Create a wallet to hold funds for the user:
// Create wallet details
$wallet = new \MangoPay\Wallet();
// Set wallet parameters
$wallet->Owners = array($userResult->Id);
$wallet->Currency = 'EUR';
$wallet->Description = 'User Wallet';
// Create a MangoPay wallet
$walletResult = $api->Wallets->Create($wallet);
Step 5: Perform Transactions
Now you can perform various transactions within your application:
// Make a transfer from a wallet to another
$transfer = new \MangoPay\Transfer();
$transfer->AuthorId = $userResult->Id;
$transfer->DebitedWalletId = $walletResult->Id;
$transfer->CreditedWalletId = 'OTHER_WALLET_ID';
$transfer->Amount = 1000; // Amount in cents
$transfer->Tag = 'Transfer Example';
$transferResult = $api->Transfers->Create($transfer);
Supported Endpoints
The MangoPay SDK supports the following API endpoints:
/users
: Manage users and user accounts/wallets
: Create and manage user wallets/transfers
: Perform transfers between wallets/payins
: Handle user deposits/payouts
: Manage user withdrawals
For more details and the complete list of available endpoints, refer to the official MangoPay API documentation.
Conclusion
Congratulations! You have successfully integrated MangoPay into your project and learned how to utilize its key features. You can now explore the various endpoints and functionalities provided by the MangoPay API to build seamless payment experiences for your users.