cviebrock/laravel-mangopay

Laravel/Lumen wrapper for the office Mangopay SDK library

9.0.0 2022-08-05 20:05 UTC

This package is auto-updated.

Last update: 2024-12-06 01:01:35 UTC


README

This package makes it easier (hopefully!) to integrate the official Mangopay SDK into your Laravel and Lumen applications.

⚠️ This Package Will Be Abandoned

Due to several factors, including the fact that I no longer use Mangopay, I will be ceasing development on this package. If you are interested in taking over this project, please reach out to me here in the Issues board.

Build Status Total Downloads Latest Stable Version Latest Unstable Version License

Installation

Depending on your version of Laravel, you should install a different version of the package. NOTE: As of version 6.0, the package's version should match the Laravel version.

Laravel

  1. Install the package via composer:

    composer require cviebrock/laravel-mangopay

    After updating composer, the package will automatically register its service provider.

  2. Publish the configuration file:

    php artisan vendor:publish --provider="Cviebrock\LaravelMangopay\ServiceProvider"
  3. Finally, generate the required temporary directories:

    php artisan mangopay:mkdir  

Lumen

  1. Install the package via composer:

    composer require cviebrock/laravel-mangopay:^6.0
  2. Copy the configuration file to your config folder and enable everything in bootstrap/app.php:

    $app->configure('mangopay');
    
    $app->register(Cviebrock\LaravelMangopay\ServiceProvider::class);
  3. Generate the required temporary directories:

    php artisan mangopay:mkdir  

Configuration

This package supports authentication configuration through the services configuration file located in config/services.php. Add the following block to that file, and set the appropriate values in your .env file:

'mangopay' => [
    'env'    => env('MANGOPAY_ENV', 'sandbox'),  // or "production"
    'key'    => env('MANGOPAY_KEY'),             // your Mangopay client ID
    'secret' => env('MANGOPAY_SECRET'),          // your Mangopay client password
],

The configuration file you can publish to config/mangopay.php provides additional properties that can be passed to the MangopayAPI object when it is instantiated. In most cases, you won't need to change anything here, so you can choose to not publish this configuration, or have it simply return an empty array.

If you do use this file, see the SDK documentation for the various properties that can be set (basically any public property on the MangoPay\Libraries\Configuration class).

Usage

All this package really does is make instantiating the MangopayAPI easy by putting the configuration into Laravel/Lumen's config system.

Using it is now as easy as injecting Mangopay into your controller, and then using it the same way you would use the MangopayAPI class:

class MyController extends Illuminate\Routing\Controller
{

    /**
     * @var \MangoPay\MangoPayApi
     */
    private $mangopay;
    
    public function __construct(\MangoPay\MangoPayApi $mangopay) {
        $this->mangopay = $mangopay;
    }

    public function doStuff($someId)
    {
        // get some user by id
        $john = $this->mangopay->Users->Get($someId);

        // change and update some of his data
        $john->LastName .= " - CHANGED";
        $this->mangopay->Users->Update($john);

        // get his bank accounts
        $pagination = new MangoPay\Pagination(1, 10); // get 1st page, 10 items per page
        $accounts = $this->mangopay->Users->GetBankAccounts($john->Id, $pagination);

        // etc.
    }
}

Bugs, Suggestions and Contributions

Thanks to everyone who has contributed to this project! Special thanks to JetBrains for their Open Source License Program ... and the excellent PHPStorm IDE, of course!

JetBrains

Please use Github for reporting bugs, and making comments or suggestions.

See CONTRIBUTING.md for how to contribute changes.

Copyright and License

laravel-mangopay was written by Colin Viebrock and released under the MIT License. See LICENSE.md file for details.

Copyright (c) 2016 Colin Viebrock