Skip to content

Mollie API client wrapper for Laravel & Mollie Connect provider for Laravel Socialite

License

Notifications You must be signed in to change notification settings

gtapps/laravel-mollie

 
 

Repository files navigation

Mollie

Laravel-Mollie Build Status

Laravel-Mollie incorporates Mollie Connect and the Mollie API into your Laravel or Lumen project.

Requirements

Installation

Add Laravel-Mollie to your composer file via the composer require command:

$ composer require mollie/laravel-mollie

Or add it to composer.json manually:

"require": {
    "mollie/laravel-mollie": "~1.0"
}

Register the service provider by adding it to the providers key in config/app.php. Also register the facade by adding it to the aliases key in config/app.php.

'providers' => [
    ...
    Mollie\Laravel\MollieServiceProvider::class,
],

'aliases' => [
    ...
    'Mollie' => Mollie\Laravel\Facades\Mollie::class,
]

Make sure that Laravel Socialite service provider and facade are also registered in your configuration files, if you intend on using Mollie Connect.

Configuration

To get started, you'll need to publish all vendor assets:

$ php artisan vendor:publish --provider="Mollie\Laravel\MollieServiceProvider"

This will create a config/mollie.php file in your app that you can modify to set your configuration.

Mollie Connect with Laravel Socialite

If you intend on using Mollie Connect, update config/services.php by adding this to the array:

'mollie' => [
    'client_id' => env('MOLLIE_CLIENT_ID', 'app_xxx'),
    'client_secret' => env('MOLLIE_CLIENT_SECRET'),
    'redirect' => env('MOLLIE_REDIRECT_URI'),
],

To make sure Laravel Socialite can actually find the Mollie driver, use the following code snippet and paste it in the boot() method from your AppServiceProvider.php.

Socialite::extend('mollie', function ($app) {
    $config = $app['config']['services.mollie'];

    return Socialite::buildProvider('Mollie\Laravel\MollieConnectProvider', $config);
});

Usage

Here you can see an example of just how simple this package is to use.

Mollie API

$payment = Mollie::api()->payments()->create([
    "amount"      => 10.00,
    "description" => "My first API payment",
    "redirectUrl" => "https://webshop.example.org/order/12345/",
]);

$payment = Mollie::api()->payments()->get($payment->id);

if ($payment->isPaid())
{
    echo "Payment received.";
}

Mollie Connect with Laravel Socialite

Route::get('login', function () {
    return Socialite::with('mollie')
        ->scopes(['profiles.read']) // Additional permission: profiles.read
        ->redirect();
});

Route::get('login_callback', function () {
    $user = Socialite::with('mollie')->user();

    Mollie::api()->setAccessToken($user->token);

    return Mollie::api()->profiles()->all(); // Retrieve all payment profiles available on the obtained Mollie account
});

Possible problems

Webhook cannot be reached, because of CSRF protection

The VerifyCsrfToken middleware, which is included in the web middleware group by default, is the troublemaker if your webhook route is in the same middleware group in the app/Http/routes.php file.

Route::post('mollie/webhook', function ($paymentId) { /** Your logic... */ });

You can exclude URIs from the CSRF protection in the app/Http/Middleware/VerifyCsrfToken.php file:

/**
 * The URIs that should be excluded from CSRF verification.
 *
 * @var array
 */
protected $except = [
    'mollie/webhook'
];

If this solution does not work, open an issue so we can assist you.

Want to help us make our Laravel module even better?

Want to help us make our Laravel module even better? We take pull requests, sure. But how would you like to contribute to a technology oriented organization? Mollie is hiring developers and system engineers. Check out our vacancies or get in touch.

License

BSD (Berkeley Software Distribution) License. Copyright (c) 2016, Mollie B.V.

Support

Contact: www.mollie.com[email protected] — +31 20-612 88 55

About

Mollie API client wrapper for Laravel & Mollie Connect provider for Laravel Socialite

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%