PHPackages                             finller/laravel-mangopay - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. finller/laravel-mangopay

AbandonedArchivedLibrary

finller/laravel-mangopay
========================

mangopay as service provider

v2.5.3(3y ago)22.7k1[1 PRs](https://github.com/finller/laravel-mangopay/pulls)MITPHPPHP ^7.4|^8.0

Since Oct 24Pushed 2y agoCompare

[ Source](https://github.com/finller/laravel-mangopay)[ Packagist](https://packagist.org/packages/finller/laravel-mangopay)[ Docs](https://github.com/finller/laravel-mangopay)[ RSS](/packages/finller-laravel-mangopay/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (10)Dependencies (10)Versions (40)Used By (0)

Mangopay package for Laravel
============================

[](#mangopay-package-for-laravel)

[![Latest Version on Packagist](https://camo.githubusercontent.com/bcd40e2b28d7ddb4ba5f3717b1fed5196702e848b3675a763194c39da3d6151e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f66696e6c6c65722f6c61726176656c2d6d616e676f7061792e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/finller/laravel-mangopay)[![GitHub Tests Action Status](https://camo.githubusercontent.com/b09eb00938ebd71ad4689f66fc48fc9db38828fbd44ae87f776f205e8bf9a407/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f66696e6c6c65722f6c61726176656c2d6d616e676f7061792f72756e2d74657374733f6c6162656c3d7465737473)](https://github.com/finller/laravel-mangopay/actions?query=workflow%3Arun-tests+branch%3Amaster)[![Total Downloads](https://camo.githubusercontent.com/ab1c452eff04d1aeea54b066ccb30e9a0f5852c3fc02215569e21eb3da50f041/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f66696e6c6c65722f6c61726176656c2d6d616e676f7061792e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/finller/laravel-mangopay)

This package allow you to use mangopay api with your Model. The goal is to makes the api more natural and user friendly to use. Under the hood, it uses the mangopay official php sdk.

**IMPORTANT: This package only provide Direct Debit PayIn with SEPA mandate for the moment. If you want to do credit card PayIn you can to use the service provider which is the php mangopay sdk**

Just had a trait to your model

```
class User extends Authenticatable
{
    use HasMangopayUser;
}
```

And then, you have plenty of functions to work easily with mangopay.

```
$user->updateOrCreateMangopayUser();
$user->createMangopayBankAccount();
$user->createMangopayTransfer();
```

It also provide a Service : MangopayServiceProvider, so you can have access to the mangopay sdk if you need.

Installation
------------

[](#installation)

Install the package via composer:

```
composer require finller/laravel-mangopay
```

You have to publish and run the migrations with:

```
php artisan vendor:publish --provider="Finller\Mangopay\MangopayServiceProvider" --tag="migrations"
php artisan migrate
```

You have to publish the config file with:

```
php artisan vendor:publish --provider="Finller\Mangopay\MangopayServiceProvider" --tag="config"
```

This is the content of the published config file: A temporary folder has to be specified as well as api credentials.

```
return [
    'api' => [
        'id' => '',
        'secret' => '',
    ],
    'folder' => storage_path('mangopay'),
    'defaultCurrency' => 'EUR',
];
```

Usage
-----

[](#usage)

### Setup your Model

[](#setup-your-model)

This package works with a Trait, the trait gives you plenty of functions and most of all it makes a link between your database and the mangopay data.

You can use the trait on any Model, not just User.

```
use Finller\Mangopay\Traits\HasMangopayUser;

class User extends Authenticatable
{
    use HasMangopayUser;
}
// or
class Company extends Model
{
    use HasMangopayUser;
}
```

By default, the mangopay user is LEGAL. You can define if your user is NATURAL (a person) or LEGAL (a company or an organization) like that:

```
class Company extends Model
{
    use HasMangopayUser;

    protected function mangopayUserIsLegal(){
        return true; //or use some logic to determine the value
    };
}
```

If you already store the data of your users in your database and you want to sync it with mangopay, just add:

```
use Finller\Mangopay\Traits\HasMangopayUser;

class User extends Authenticatable
{
    use HasMangopayUser;

    public function buildMangopayUserData(): array
    {
        return [
            'Name' => $this->company_name,
            'Email' => $this->email,
            'HeadquartersAddress' => [
                'AddressLine1' => $this->address->street,
                'AddressLine2' => null,
                'City' => $this->address->city,
                'Region' => null,
                'PostalCode' => $this->address->postal_code,
                'Country' => $this->address->country_code,
            ],
            "LegalRepresentativeEmail" => $this->representative->email,
            "LegalRepresentativeBirthday" => $this->representative->birthdate->getTimestamp(),
            "LegalRepresentativeCountryOfResidence" => $this->representative->country_code,
            "LegalRepresentativeNationality" => $this->representative->nationality_code,
            "LegalRepresentativeFirstName" => $this->representative->first_name,
            "LegalRepresentativeLastName" => $this->representative->last_name,
        ];
    }
}
```

These data will be used when you call `$user->createMangopayUser();` or `$user->updateMangopayUser();`.

In the exemple, all personnal data needed by Mangopay are fetch from your Model. **Please note that the only information stored by this package in the database are the mangopay user id and the mangopay user KYC level.**

### Create and update your mangopay user

[](#create-and-update-your-mangopay-user)

Then you can just create and update your mangopay user like that:

```
$user->createMangopayUser();
//or
$user->updateMangopayUser();
//or
$user->updateOrCreateMangopayUser();
```

If you do not use `buildMangopayUserData` method, or if you want to override it, you can pass an array of data: array from the method `buildMangopayUserData` and array passed as variable will be merged.

```
$user->createMangopayUser([
            'Name' => $this->company_name,
            'Email' => 'put your email here',
            'HeadquartersAddress' => [
                'AddressLine1' => $this->address->street,
                'AddressLine2' => null,
                'City' => $this->address->city,
                'Region' => null,
                'PostalCode' => $this->address->postal_code,
                'Country' => $this->address->country_code,
            ],
            "LegalRepresentativeEmail" => $this->representative->email,
            "LegalRepresentativeBirthday" => $this->representative->birthdate->getTimestamp(),
            "LegalRepresentativeCountryOfResidence" => $this->representative->country_code,
            "LegalRepresentativeNationality" => $this->representative->nationality_code,
            "LegalRepresentativeFirstName" => $this->representative->first_name,
            "LegalRepresentativeLastName" => $this->representative->last_name,
        ]);
```

please note that some fields are mandatory to be able to create a mangopay User (please see to the mangopay docs).

### Manage your mangopay wallets

[](#manage-your-mangopay-wallets)

```
$user->createMangopayWallet([
    'Description'=>'Main Wallet',
    'Currency'=>'EUR',
    'Tag'=>'a name or any info'
]);

//get the list of the user's wallets
$user->mangopayWallets();
```

### Add Bank account and mandate

[](#add-bank-account-and-mandate)

```
$bankAccount = $company->createMangopayBankAccount([
            'IBAN' => 'an IBAN',
            'Tag' => 'any name or tag',
            'BIC' => 'BIC is optional',
            'OwnerName' => 'the name',
            'OwnerAddress' => [
                'AddressLine1' => 'street',
                'AddressLine2' => null,
                'City' => 'the city name',
                'Region' => 'region is required for some countries',
                'PostalCode' => ' a postal code',
                'Country' => 'country code like FR, ...',
            ],
        ]);

//retreive all users bank accounts
$bankAccounts = $company->mangopayBankAccounts();

$mandate = $company->createMangopayMandate([
    'BankAccountId'=> "xxxx",
    'Culture'=> 'FR',
    'ReturnURL'=>'your-website.com'
]);
```

There are a lot of functions to manage everything, so don't hesitate to explore the trait (methods names are pretty clear).

### Do PayIn and PayOut

[](#do-payin-and-payout)

**IMPORTANT: This package only support Direct Debit PayIn with SEPA mandate for the moment. If you want to do credit card PayIn you have to use the service provider and so the php sdk**

```
//SEPA PayIn
$payIn = $user->createMangopayMandatePayIn([
    'DebitedFunds'=>[
        'Amount'=>1260,//12.60€
        'Currency'=>'EUR',
    ],
    'Fees'=>[
        'Amount'=>0,//0€
        'Currency'=>'EUR',
    ],
    'BankAccountId'=>123456,
    'CreditedWalletId'=>123456,
    'CreditedUserId'=>123456,//by default it's the owner of the wallet
    'MandateId'=>123456,
    'StatementDescriptor'=>'Your company name or a ref',
]);

$payout = $user->createMangopayPayOut([
    'DebitedFunds'=>[
        'Amount'=>1260,//12.60€
        'Currency'=>'EUR',
    ],
    'Fees'=>[
        'Amount'=>0,//0€
        'Currency'=>'EUR',
    ],
    'BankAccountId'=>123456,
    'DebitedWalletId'=>7891011,
    'BankWireRef'=>'Your company name or a ref',
]);
```

### Retreive Laravel User and Mangopay User from Mangopay User Id

[](#retreive-laravel-user-and-mangopay-user-from-mangopay-user-id)

This situation will happen very often when dealing with Mangopay hooks. You can use the `MangopayPivot` Model.

```
use Finller\Mangopay\Models\MangopayPivot;

$mangopayUserId = "123456";

$pivot = MangopayPivot::findByMangopayId($mangopayUserId);

$laravelUser = $pivot->billable;//this will give you the laravel User or whatever Model you use

$mangopayUser = $pivot->mangopayUser();//this will give you the Mangopay User Object
```

Managing Mangopay Hooks
-----------------------

[](#managing-mangopay-hooks)

This is just an example of how you can deal with Mangopay hooks in Laravel.

### Setup the route

[](#setup-the-route)

```
Route::namespace('Mangopay')->group(function () {
    Route::get('hook/mangopay/payin', 'MangopayHookController@payin');

    Route::get('hook/mangopay/payout', 'MangopayHookController@payout');

    Route::get('hook/mangopay/kyc', [MangopayHookController::class, "kyc"]);
});
```

Define the controller
---------------------

[](#define-the-controller)

```
use App\Events\Mangopay\PayInFailed;
use App\Events\Mangopay\PayInSucceeded;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

use MangoPay\EventType;

class MangopayHookController extends Controller
{
    /**
     * Handle mangopay hook
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function payin(Request $request)
    {
        $eventType = $request->input('EventType');
        $Id = $request->input('RessourceId');
        $date = $request->input('Timestamp');

        if (!!$Id and !!$eventType) {
            switch ($eventType) {
                case EventType::PayinNormalSucceeded:
                    event(new PayInSucceeded($Id, $date));
                    break;
                case EventType::PayinNormalFailed:
                    event(new PayInFailed($Id, $date));
                    break;
            }
        }

        //you have to respond in less than 2 secondes with a 200 status code
        return response();
    }
}
```

Define the event
----------------

[](#define-the-event)

And you can listen to mangopay Hooks !

```
use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
use MangoPay\PayIn;

class PayInFailed
{
    use Dispatchable, InteractsWithSockets, SerializesModels;

    public $Id;
    public $date;
    public $type = PayIn::class;

    /**
     * Create a new event instance.
     *
     * @return void
     */
    public function __construct($Id, $date)
    {
        $this->Id = $Id;
        $this->date = $date;
    }

    /**
     * Get the channels the event should broadcast on.
     *
     * @return \Illuminate\Broadcasting\Channel|array
     */
    public function broadcastOn()
    {
        return new PrivateChannel('channel-name');
    }
}
```

Deploy in production
--------------------

[](#deploy-in-production)

By default the mangopay sdk use the sandbox api url. If you want to go in production you have to define the production api url in the config file like this:

```
return [
    'api' => [
        'id' => env('MANGOPAY_ID'),
        'secret' => env('MANGOPAY_KEY'),
        'url' => env('MANGOPAY_URL', "https://api.mangopay.com") // storage_path('mangopay'),
    'defaultCurrency' => 'EUR',
];
```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Quentin Gabriele](https://github.com/QuentinGabriele)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity71

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~15 days

Recently: every ~6 days

Total

39

Last Release

1448d ago

Major Versions

v0.4 → v1.0.02021-02-13

v1.2.2 → v2.1.02021-09-13

PHP version history (2 changes)v0.1PHP ^7.4

v1.1.0PHP ^7.4|^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/d769563728757858e249f266ac2555f28db5640124df92821ed17d93ee76fc7b?d=identicon)[QuentinGab](/maintainers/QuentinGab)

---

Top Contributors

[![QuentinGab](https://avatars.githubusercontent.com/u/40128136?v=4)](https://github.com/QuentinGab "QuentinGab (142 commits)")

---

Tags

laravellaravel-packagemangopaymangopay-apiphpfinllerlaravel-mangopay

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/finller-laravel-mangopay/health.svg)

```
[![Health](https://phpackages.com/badges/finller-laravel-mangopay/health.svg)](https://phpackages.com/packages/finller-laravel-mangopay)
```

###  Alternatives

[bezhansalleh/filament-shield

Filament support for `spatie/laravel-permission`.

2.8k2.9M88](/packages/bezhansalleh-filament-shield)[spatie/laravel-honeypot

Preventing spam submitted through forms

1.6k6.0M60](/packages/spatie-laravel-honeypot)[spatie/laravel-health

Monitor the health of a Laravel application

85810.0M83](/packages/spatie-laravel-health)[spatie/laravel-livewire-wizard

Build wizards using Livewire

4061.0M4](/packages/spatie-laravel-livewire-wizard)[clickbar/laravel-magellan

This package provides functionality for working with the postgis extension in Laravel.

423715.4k1](/packages/clickbar-laravel-magellan)[spatie/laravel-prometheus

Export Laravel metrics to Prometheus

2651.3M6](/packages/spatie-laravel-prometheus)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
