2017 © Pedro Peláez
 

library php-sdk-v2

SDK PHP for Mangopay api V2

image

mangopay/php-sdk-v2

SDK PHP for Mangopay api V2

  • Friday, June 22, 2018
  • by mangopay
  • Repository
  • 38 Watchers
  • 73 Stars
  • 254,152 Installations
  • PHP
  • 12 Dependents
  • 0 Suggesters
  • 102 Forks
  • 22 Open issues
  • 48 Versions
  • 11 % Grown

The README.md

MANGOPAY PHP SDK mangopay2-php-sdk-cd Latest Stable Version Total Downloads License

MangopaySDK is a PHP client library to work with Mangopay REST API., (*1)

Compatibility Notes

  • Since v2.1 of this SDK, you must be using at least v2.01 of the API (more information about the changes required)
  • If you experience problems with authentification and/or the temporary token file following an SDK update (particularly updating to v2.0 of the SDK), you may need to just delete your temporary file (that you specify with $api->Config->TemporaryFolder) - which allows it to be regenerated correctly the next time it's needed

Requirements

To use this SDK, you will need (as a minimum): * PHP 5.6 or newer * cURL (included and enabled in a standard PHP distribution) * OpenSSL (included and enabled in a standard PHP distribution) * psr/log v1.0 * You do not have to use Composer, but you are strongly advised to (particularly for handling the dependency on the PSR Log library), (*2)

Installation with Composer

You can use Mangopay SDK library as a dependency in your project with Composer (which is the preferred technique). Follow these installation instructions if you do not already have Composer installed. A composer.json file is available in the repository and it has been referenced from Packagist., (*3)

The installation with Composer is easy and reliable:, (*4)

Step 1 - Add the Mangopay SDK as a dependency by executing the following command:, (*5)

you@yourhost:/path/to/your-project$ composer require mangopay/php-sdk-v2

Step 2 - Update your dependencies with Composer, (*6)

you@yourhost:/path/to/your-project$ composer update

Step 3 - Finally, be sure to include the autoloader in your project, (*7)

require_once '/path/to/your-project/vendor/autoload.php';

The Library has been added into your dependencies and is ready to be used., (*8)

Installation without Composer

The project attempts to comply with PSR-4 specification for autoloading classes from file paths. As a namespace prefix is MangoPay\ with base directory /path/to/your-project/., (*9)

If you're not using PSR-4 or Composer, the installation is as easy as downloading the library and storing it under any location that will be available for including in your project (don't forget to include the required library dependencies though):, (*10)

    require_once '/path/to/your-project/MangoPay/Autoloader.php';

Alternatively you can download the package in its entirety (ie with all required dependencies) from the Releases page (look for the mangopay2-php-sdk-[RELEASE_NAME].zip file). Uncompress the zip file you download, and include the autoloader in your project:, (*11)

    require_once '/path/to/your-project/mangopay2-php-sdk/vendor/autoload.php';

License

MangopaySDK is distributed under MIT license, see the LICENSE file., (*12)

Unit Tests

Tests are placed under /path/to/your-project/tests/. The /tests/suites/all.php suite runs ALL tests. You can also use any of /tests/cases/*.php to run a single test case., (*13)

Contacts

Report bugs or suggest features using issue tracker on GitHub., (*14)

Account creation

You can get yourself a free sandbox account or sign up for a production account by registering on the Mangopay site (note that validation of your production account involves several steps, so think about doing it in advance of when you actually want to go live)., (*15)

Configuration

Using the credential info from the signup process above, you should then set $api->Config->ClientId to your Mangopay ClientId and $api->Config->ClientPassword to your Mangopay APIKey., (*16)

You also need to set a folder path in $api->Config->TemporaryFolder that SDK needs to store temporary files. This path should be outside your www folder. It could be /tmp/ or /var/tmp/ or any other location that PHP can write to. You must use different folders for your sandbox and production environments., (*17)

$api->Config->BaseUrl is set to sandbox environment by default. To enable production environment, set it to https://api.mangopay.com., (*18)

require_once '/path/to/your-project/vendor/autoload.php';
$api = new MangoPay\MangoPayApi();

// configuration
$api->Config->ClientId = 'your-client-id';
$api->Config->ClientPassword = 'your-client-password';
$api->Config->TemporaryFolder = '/some/path/';
//$api->Config->BaseUrl = 'https://api.mangopay.com';//uncomment this to use the production environment

//uncomment any of the following to use a custom value (these are all entirely optional)
//$api->Config->CurlResponseTimeout = 20;//The cURL response timeout in seconds (its 30 by default)
//$api->Config->CurlConnectionTimeout = 60;//The cURL connection timeout in seconds (its 80 by default)
//$api->Config->CertificatesFilePath = ''; //Absolute path to file holding one or more certificates to verify the peer with (if empty, there won't be any verification of the peer's certificate)

// call some API methods...
try {
    $users = $api->Users->GetAll();
} catch(MangoPay\Libraries\ResponseException $e) {
    // handle/log the response exception with code $e->GetCode(), message $e->GetMessage() and error(s) $e->GetErrorDetails()
} catch(MangoPay\Libraries\Exception $e) {
    // handle/log the exception $e->GetMessage()
}

Sample usage

require_once '/path/to/your-project/vendor/autoload.php';
$api = new MangoPay\MangoPayApi();

// configuration
$api->Config->ClientId = 'your-client-id';
$api->Config->ClientPassword = 'your-client-password';
$api->Config->TemporaryFolder = '/some/path/';

// get some user by id
try {
    $john = $api->Users->Get($someId);
} catch(MangoPay\Libraries\ResponseException $e) {
    // handle/log the response exception with code $e->GetCode(), message $e->GetMessage() and error(s) $e->GetErrorDetails()
} catch(MangoPay\Libraries\Exception $e) {
    // handle/log the exception $e->GetMessage()
}

// change and update some of his data
$john->LastName .= " - CHANGED";
try {
    $api->Users->Update($john);
} catch(MangoPay\Libraries\ResponseException $e) {
    // handle/log the response exception with code $e->GetCode(), message $e->GetMessage() and error(s) $e->GetErrorDetails()
} catch(MangoPay\Libraries\Exception $e) {
    // handle/log the exception $e->GetMessage()
}

// get all users (with pagination)
$pagination = new MangoPay\Pagination(1, 8); // get 1st page, 8 items per page
try {
    $users = $api->Users->GetAll($pagination);
} catch(MangoPay\Libraries\ResponseException $e) {
    // handle/log the response exception with code $e->GetCode(), message $e->GetMessage() and error(s) $e->GetErrorDetails()
} catch(MangoPay\Libraries\Exception $e) {
    // handle/log the exception $e->GetMessage()
}

// get his bank accounts
$pagination = new MangoPay\Pagination(2, 10); // get 2nd page, 10 items per page
try {
    $accounts = $api->Users->GetBankAccounts($john->Id, $pagination);
} catch(MangoPay\Libraries\ResponseException $e) {
    // handle/log the response exception with code $e->GetCode(), message $e->GetMessage() and error(s) $e->GetErrorDetails()
} catch(MangoPay\Libraries\Exception $e) {
    // handle/log the exception $e->GetMessage()
}

Sample usage with Composer in a Symfony project

You can integrate Mangopay features in a Service in your Symfony project., (*19)

MangoPayService.php :, (*20)


<?php namespace Path\To\Service; use MangoPay; class MangoPayService { private $mangoPayApi; public function __construct() { $this->mangoPayApi = new MangoPay\MangoPayApi(); $this->mangoPayApi->Config->ClientId = 'your-client-id'; $this->mangoPayApi->Config->ClientPassword = 'your-client-password'; $this->mangoPayApi->Config->TemporaryFolder = '/some/path/'; //$this->mangoPayApi->Config->BaseUrl = 'https://api.sandbox.mangopay.com'; } /** * Create Mangopay User * @return MangopPayUser $mangoUser */ public function getMangoUser() { $mangoUser = new \MangoPay\UserNatural(); $mangoUser->PersonType = "NATURAL"; $mangoUser->FirstName = 'John'; $mangoUser->LastName = 'Doe'; $mangoUser->Birthday = 1409735187; $mangoUser->Nationality = "FR"; $mangoUser->CountryOfResidence = "FR"; $mangoUser->Email = 'john.doe@mail.com'; //Send the request $mangoUser = $this->mangoPayApi->Users->Create($mangoUser); return $mangoUser; } }

Logging

MangoPay uses the PSR3 LoggerInterface. You can provide your own logger to the API. Here is a sample showing Monolog integration :, (*21)

use Monolog\Logger;
use Monolog\Handler\StreamHandler;

...

$logger = new Logger('sample-logger');
$logger->pushHandler(new StreamHandler($logConfig['path'], Logger::DEBUG));

$this->mangoPayApi = new MangoPay\MangoPayApi();
$this->mangoPayApi->setLogger($logger);

Verifying rate limits status

According to API docs (https://docs.mangopay.com/guide/rate-limiting), MangoPay is providing a way of verifying how many API calls were made, how many are left and when the counter will be reset. So there are 4 groups of rate limits available: 1. Last 15 minutes: 2. Last 30 minutes 3. Last 60 minutes 4. Last 24 hours, (*22)

This information is available from the MangoPayApi instance, like in the following example:, (*23)

<?php

namespace Path\To\Service;

use MangoPay;


class MangoPayService
{

    /**
    * @var MangoPay\MangoPayApi
    */
    private $mangoPayApi;

    public function __construct()
    {
        $this->mangoPayApi = new MangoPay\MangoPayApi();
        $this->mangoPayApi->Config->ClientId = 'your-client-id';
        $this->mangoPayApi->Config->ClientPassword = 'your-client-password';
        $this->mangoPayApi->Config->TemporaryFolder = '/some/path/';
        //$this->mangoPayApi->Config->BaseUrl = 'https://api.sandbox.mangopay.com';
    }

    public function verifyRateLimits()
    {
        // This is an array of 4 RateLimit objects.
        $rateLimits = $this->mangoPayApi->RateLimits;
        print "\nThere were " . $rateLimits[0]->CallsMade . " calls made in the last 15 minutes";
        print "\nYou can do " . $rateLimits[0]->CallsRemaining . " more calls in the next 15 minutes";
        print "\nThe 60 minutes counter will reset at " . date("Y-m-d\TH:i:s\Z", $rateLimits[0]->ResetTimeTimestamp);
        print "\nThere were " . $rateLimits[2]->CallsMade . " calls made in the last 60 minutes";
        print "\nYou can do " . $rateLimits[2]->CallsRemaining . " more calls in the next 60 minutes";
        print "\nThe 60 minutes counter will reset at " . date("Y-m-d\TH:i:s\Z", $rateLimits[2]->ResetTimeTimestamp);
    }
}

The Versions

22/06 2018

dev-bugfix/#252-unknown-field-type-long

dev-bugfix/#252-unknown-field-type-long

SDK PHP for Mangopay api V2

  Sources   Download

MIT

The Requires

 

The Development Requires

19/06 2018

dev-bugfix/creation-date-comparation-test-fail

dev-bugfix/creation-date-comparation-test-fail

SDK PHP for Mangopay api V2

  Sources   Download

MIT

The Requires

 

The Development Requires

31/05 2018

dev-master

9999999-dev

SDK PHP for Mangopay api V2

  Sources   Download

MIT

The Requires

 

The Development Requires

30/03 2018

2.8.0

2.8.0.0

SDK PHP for Mangopay api V2

  Sources   Download

MIT

The Requires

 

The Development Requires

07/03 2018

v2.7.1

2.7.1.0

SDK PHP for Mangopay api V2

  Sources   Download

MIT

The Requires

 

The Development Requires

23/01 2018

dev-disputereasontype-update

dev-disputereasontype-update

SDK PHP for Mangopay api V2

  Sources   Download

MIT

The Requires

 

The Development Requires

26/12 2017

v2.7.0

2.7.0.0

SDK PHP for Mangopay api V2

  Sources   Download

MIT

The Requires

 

The Development Requires

26/12 2017

dev-feature/MPSDK-199-get-transactions-for-mandate

dev-feature/MPSDK-199-get-transactions-for-mandate

SDK PHP for Mangopay api V2

  Sources   Download

MIT

The Requires

 

The Development Requires

26/12 2017

dev-feature/MPSDK-198-get-transactions-for-card

dev-feature/MPSDK-198-get-transactions-for-card

SDK PHP for Mangopay api V2

  Sources   Download

MIT

The Requires

 

The Development Requires

26/12 2017

dev-feature/MPSDK-197-get-transactions-for-bank-account

dev-feature/MPSDK-197-get-transactions-for-bank-account

SDK PHP for Mangopay api V2

  Sources   Download

MIT

The Requires

 

The Development Requires

26/12 2017

dev-feature/MPSDK-196-get-refunds-for-repudiation

dev-feature/MPSDK-196-get-refunds-for-repudiation

SDK PHP for Mangopay api V2

  Sources   Download

MIT

The Requires

 

The Development Requires

26/12 2017

dev-feature/MPSDK-195-get-refunds-for-transfer

dev-feature/MPSDK-195-get-refunds-for-transfer

SDK PHP for Mangopay api V2

  Sources   Download

MIT

The Requires

 

The Development Requires

26/12 2017

dev-feature/MPSDK-193-get-refunds-for-payin

dev-feature/MPSDK-193-get-refunds-for-payin

SDK PHP for Mangopay api V2

  Sources   Download

MIT

The Requires

 

The Development Requires

26/12 2017

dev-feature/MPSDK-192-get-refunds-for-payout

dev-feature/MPSDK-192-get-refunds-for-payout

SDK PHP for Mangopay api V2

  Sources   Download

MIT

The Requires

 

The Development Requires

19/12 2017

dev-feature/MSPDK-190-implement-get-preauthorizations-for-card

dev-feature/MSPDK-190-implement-get-preauthorizations-for-card

SDK PHP for Mangopay api V2

  Sources   Download

MIT

The Requires

 

The Development Requires

19/12 2017

dev-feature/MPSDK-191-implement-get-preauthorizations-for-user

dev-feature/MPSDK-191-implement-get-preauthorizations-for-user

SDK PHP for Mangopay api V2

  Sources   Download

MIT

The Requires

 

The Development Requires

11/12 2017

dev-feature/MPSDK-189-add-payin-extended-endpoint

dev-feature/MPSDK-189-add-payin-extended-endpoint

SDK PHP for Mangopay api V2

  Sources   Download

MIT

The Requires

 

The Development Requires

30/10 2017

2.6.4

2.6.4.0

SDK PHP for Mangopay api V2

  Sources   Download

MIT

The Requires

 

The Development Requires

30/10 2017

dev-version-bump-264

dev-version-bump-264

SDK PHP for Mangopay api V2

  Sources   Download

MIT

The Requires

 

The Development Requires

28/09 2017

2.6.3

2.6.3.0

SDK PHP for Mangopay api V2

  Sources   Download

MIT

The Requires

 

The Development Requires

28/09 2017

dev-version-bump-263

dev-version-bump-263

SDK PHP for Mangopay api V2

  Sources   Download

MIT

The Requires

 

The Development Requires

05/09 2017

dev-feature/MPSDK-167-add-ubo-declarations

dev-feature/MPSDK-167-add-ubo-declarations

SDK PHP for Mangopay api V2

  Sources   Download

MIT

The Requires

 

The Development Requires

01/09 2017

dev-feature/MPSDK-162-add-processed-date-property

dev-feature/MPSDK-162-add-processed-date-property

SDK PHP for Mangopay api V2

  Sources   Download

MIT

The Requires

 

The Development Requires

01/09 2017

dev-hotfix/add-deactivate-bank-account-test

dev-hotfix/add-deactivate-bank-account-test

SDK PHP for Mangopay api V2

  Sources   Download

MIT

The Requires

 

The Development Requires

30/08 2017

2.6.1

2.6.1.0

SDK PHP for Mangopay api V2

  Sources   Download

MIT

The Requires

 

The Development Requires

28/08 2017

dev-version-bump-2.6.1

dev-version-bump-2.6.1

SDK PHP for Mangopay api V2

  Sources   Download

MIT

The Requires

 

The Development Requires

24/08 2017

2.6.0

2.6.0.0

SDK PHP for Mangopay api V2

  Sources   Download

MIT

The Requires

 

The Development Requires

18/08 2017

dev-wallet-reporting

dev-wallet-reporting

SDK PHP for Mangopay api V2

  Sources   Download

MIT

The Requires

 

The Development Requires

17/08 2017

dev-feature/MPSDK-140-add-shipping-address-paypal-property

dev-feature/MPSDK-140-add-shipping-address-paypal-property

SDK PHP for Mangopay api V2

  Sources   Download

MIT

The Requires

 

The Development Requires

28/07 2017

dev-new-properties

dev-new-properties

SDK PHP for Mangopay api V2

  Sources   Download

MIT

The Requires

 

05/07 2017

2.5.3

2.5.3.0

SDK PHP for Mangopay api V2

  Sources   Download

MIT

The Requires

 

25/04 2017

2.5.2

2.5.2.0

SDK PHP for Mangopay api V2

  Sources   Download

MIT

The Requires

 

25/04 2017

2.5.1

2.5.1.0

SDK PHP for Mangopay api V2

  Sources   Download

MIT

The Requires

 

19/03 2017

dev-emoney

dev-emoney

SDK PHP for Mangopay api V2

  Sources   Download

MIT

The Requires

 

03/03 2017

2.5.0

2.5.0.0

SDK PHP for Mangopay api V2

  Sources   Download

MIT

The Requires

 

27/09 2016

2.4.4

2.4.4.0

SDK PHP for Mangopay api V2

  Sources   Download

MIT

The Requires

 

17/08 2016

2.4.3

2.4.3.0

SDK PHP for Mangopay api V2

  Sources   Download

MIT

The Requires

 

19/05 2016

2.4.2

2.4.2.0

SDK PHP for Mangopay api V2

  Sources   Download

MIT

The Requires

 

18/04 2016

v2.4.1

2.4.1.0

SDK PHP for Mangopay api V2

  Sources   Download

MIT

The Requires

 

12/04 2016

v2.4

2.4.0.0

SDK PHP for Mangopay api V2

  Sources   Download

MIT

The Requires

 

10/02 2016

v2.3

2.3.0.0

SDK PHP for Mangopay api V2

  Sources   Download

MIT

The Requires

 

26/01 2016

v2.2

2.2.0.0

SDK PHP for Mangopay api V2

  Sources   Download

MIT

The Requires

  • php >=5.5.0
  • ext-curl *
  • ext-openssl *

 

30/07 2015

v2.1

2.1.0.0

SDK PHP for Mangopay api V2

  Sources   Download

MIT

The Requires

  • php >=5.5.0
  • ext-curl *
  • ext-openssl *

 

17/04 2015

v2.0

2.0.0.0

SDK PHP for Mangopay api V2

  Sources   Download

MIT

25/03 2015

v1.7

1.7.0.0

SDK PHP for Mangopay api V2

  Sources   Download

MIT

25/11 2014

v1.6

1.6.0.0

SDK PHP for Mangopay api V2

  Sources   Download

MIT

15/09 2014

v1.5

1.5.0.0

SDK PHP for Mangopay api V2

  Sources   Download

MIT

20/08 2014

v1.4.3

1.4.3.0

SDK PHP for Mangopay api V2

  Sources   Download

MIT