A laravel wrapper for BnpParibas Mercanet payment gateway

Overview

Logo Laravel Mercanet

Laravel Mercanet

A laravel wrapper for BnpParibas Mercanet which provide a lightweight public api to process your online payments from your laravel application.

GitHub Tests Action Status GitHub Code Style Action Status

Installation

You can install the package via composer:

composer require mouadziani/laravel-mercanet

You can publish the config file with:

php artisan vendor:publish --provider="Mouadziani\Mercanet\MercanetServiceProvider"

Configuration

First, you need to change the following credentials located in the app/config/mercanet.php file, with your own credentials given from your mercanet account.

return [
    /**
     * Can only be 'TEST' Or 'Production'. If empty or invalid, 'TEST' will be used.
     */
    'mode' => env('MERCANET_MODE', 'TEST'),

    // Credentials of testing environment
    'test' => [
        'merchant_id' => env('MERCANET_TEST_MERCHANT_ID', ''), // Required
        'key_version' => env('MERCANET_TEST_KEY_VERSION', '1'),
        'secret_key' => env('MERCANET_TEST_SECRET_KEY', ''), // Required
    ],

    // Credentials of production environment
    'production' => [
        'merchant_id' => env('MERCANET_PRODUCTION_MERCHANT_ID', ''), // Required
        'key_version' => env('MERCANET_PRODUCTION_KEY_VERSION', '1'), // Required
        'secret_key' => env('MERCANET_PRODUCTION_SECRET_KEY', ''), // Required
    ],

    'currency' => env('MERCANET_CURRENCY', 'EUR'),

    // Should be replaced with a url of your callback post route,
    // which will be invoked by mercanet service after processing of any payment.
    'normal_return_url' => env('MERCANET_NORMAL_RETURN_URL', 'https://example.com/payments/callback'),

    /**
    * You can set the default locale that you need to be used to translate the mercanet payment page
     * Allowed languages 'nl', 'fr', 'de', 'it', 'es', 'cy', 'en'
     */
    'language' => env('MERCANET_LOCALE', 'en'),
];

Usage

Following are some ways through which you can bootstrap the process of payment:

// Import the class namespaces first, before using it directly
use Mouadziani\Mercanet\Mercanet;

// You can either create new instance from Mercanet
$mercanet = new Mercanet();

// Or through static constructor boot.
$mercanet = Mercanet::boot();

Prepare and process payment request

In order to process new payment you need to call newPaymentRequest() from the existing mercanet instance and then set the following arguments

$mercanet->newPaymentRequest();

// Required
$mercanet->setTransactionReference('123456789'); 

// By default the currency used is EUR. If you wish to change it,
// you may call setCurrency method to set a different currency before calling pay() method
$mercanet->setCurrency('EUR');

// Optionally, You can also call setLanguage method to change the default locale of payment page
$mercanet->setLanguage('fr');

// Required and it should be integer
$mercanet->setAmount(19000);

// Optional
$mercanet->setBillingContactFirstname('John');

 // Optional
$mercanet->setBillingContactLastname('Doe');

 // Optional
$mercanet->setCustomerContactEmail('[email protected]');

// Then you can call pay() method to redirect user to the payment page of mercanet website.
$mercanet->pay();

Instead of creation new instance from Mercanet class and call method separately on it, you can use also the static constructor as the following example:

use Mouadziani\Mercanet\Mercanet;

Mercanet::boot()
    ->newPaymentRequest()
    ->setTransactionReference('123456789')
    ->setCurrency('EUR')
    ->setLanguage('fr')
    ->setAmount(19000.50)
    ->setBillingContactFirstname('John')
    ->setBillingContactLastname('Doe')
    ->setCustomerContactEmail('[email protected]')
    ->pay();

Validate payment transaction from callback request

In order to retrieve transaction reference and payment status from the given callback request, you can use the following methods.

use Mouadziani\Mercanet\Mercanet;

// Create new instance or call the static constructor from Mercanet class 
// and then call fromRequest() method and pass request parameters into it. 
$paymentResponse = Mercanet::boot()->fromResponse(request()->all());

// Then you can check if the given payment response is successfully passed by calling isSuccessfullyPassed() method
if($paymentResponse->isSuccessfullyPassed()) {
    // The payment is accepted.
    
    // You can get the transaction reference from the initialized payment request object
    $transactionReference = $paymentResponse->getTransactionReference();
    
    // Then you can do what you want, eg. change the status of the order related to the transaction reference, or mark it as paid...
    App\Order::query()
        ->where('transaction_reference', $transactionReference)
        ->update([
            'is_paid' => true
        ]);
} else {
    // The payment is failed 
}

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Credits

License

The MIT License (MIT). Please see License File for more information.

You might also like...
Mollie API client wrapper for Laravel & Mollie Connect provider for Laravel Socialite
Mollie API client wrapper for Laravel & Mollie Connect provider for Laravel Socialite

Mollie for Laravel Laravel-Mollie incorporates the Mollie API and Mollie Connect into your Laravel or Lumen project. Accepting iDEAL, Apple Pay, Banco

A Laravel Wrapper for the CoinDCX API. Now easily connect and consume the CoinDCX Public API in your Laravel apps without any hassle.
A Laravel Wrapper for the CoinDCX API. Now easily connect and consume the CoinDCX Public API in your Laravel apps without any hassle.

This package provides a Laravel Wrapper for the CoinDCX API and allows you to easily communicate with it. Important Note This package is in early deve

A CommonMark wrapper for Laravel
A CommonMark wrapper for Laravel

Laravel Markdown Laravel Markdown was created by, and is maintained by Graham Campbell, and is a CommonMark wrapper for Laravel. It ships with integra

Laravel wrapper package for the Aimon.it API

Laravel Aimon Package A laravel wrapper package for the Aimon.it API. For more information see Aimon Requirements Laravel 6 or later Installation Inst

A Laravel wrapper for spatie/dns. Allows to query and validate DNS records.

A Laravel wrapper for spatie/dns. Allows to query and validate DNS records.

Laravel API wrapper to interact fluently with your Janus Media Server

Laravel API wrapper to interact fluently with your Janus Media Server. Core server interactions, as well as the video room plugin included.

Open Food Facts API wrapper for Laravel

Laravel Open Food Facts API This package provides a convenient wrapper to the Open Food Facts API for Laravel applications (5.7+). Installation You ca

a Google API v3 wrapper for Laravel 4.x

A Google API v3 wrapper for Laravel 4 This package enables a Laravel flavoured way to manage Google services through its API interface (v3) Installati

27Laracurl Laravel wrapper package for PHP cURL class that provides OOP interface to cURL. [10/27/2015] View Details

Laracurl Laravel cURL Wrapper for Andreas Lutro's OOP cURL Class Installation To install the package, simply add the following to your Laravel install

Releases(v1.3.0)
Owner
Mouad ZIANI
Software Engineer. Experienced in PHP & Laravel/Vuejs Stacks
Mouad ZIANI
SSLCommerz Payment gateway library for Laravel framework

SSLCommerz SSLCommerz Payment gateway library for Laravel framework. Official documentation is here. install composer require sam-asif/sslcommerz Pro

Md. Asif Iqbal 1 Oct 28, 2021
Integrasi Payment Gateway Midtrans dengan Framework Laravel 8

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

Martin Mulyo Syahidin 25 Dec 4, 2022
Backend application using Laravel 9.x REST APIs for games topup from digiflazz.com and payment gateway using xendit.co

TOPUP - Laravel 9.x REST API Documentation is still on progress. For now, you can fork this postman collection Installation Clone this project git clo

Muhammad Athhar Kautsar 46 Dec 17, 2022
PayuMoney Gateway wrapper for Laravel.

PayuMoney Integration with Laravel Easy to use integration for PayUMoney into Laravel apps. Video Tutorial Usage composer require infyomlabs/laravel-p

InfyOmLabs (InfyOm Technologies) 10 Nov 29, 2022
Learn how to accept a payment from customers around the world with a variety of payment methods.

Accept a payment Learn how to securely accept payments online. This repository includes examples of 2 types of integration types. Prebuilt Checkout pa

Stripe Samples 337 Jan 2, 2023
Laravel SMS Gateway

This is a Laravel Package for SMS Gateway Integration. Now Sending SMS is easy.

Fowitech 12 Sep 6, 2022
Zarinpal is a laravel package to easily use zarinpal.com payment services in your applications

پکیج اتصال به درگاه پرداخت زرین پال zarinpal.com برای اتصال به درگاه پرداخت اینترنتی زرین پال و استفاده از api های آن می توانید از این پکیج استفاده کن

Rahmat Waisi 4 Jan 26, 2022
A Laravel package to simplify using DPO Payment API in your application.

DPO (Direct Pay Online) Laravel Package The best DPO Laravel package, simple Ever This is the package that will help you add DPO Payment API to your L

Zepson Technologies 5 Nov 17, 2022
Dedicated laravel package for Behpadakht Mellat bank payment service.

Iranian Mellat bank full online payment service Dedicated laravel package for Behpadakht Mellat bank payment service. Features Event calls Log on chan

Mahdi Jedari 5 Apr 19, 2022
Integerating Laravel with Payment Gateways Paypal, Stripe, Paymob, Paytabs and MyFatoorah

This Repo is for integerating Laravel with some Payment gateways Integeration with For these integerations you need to provide env variables from your

Sherif Nabil 4 Jul 12, 2022