• Stars
    star
    31
  • Rank 817,679 (Top 17 %)
  • Language
    PHP
  • License
    MIT License
  • Created about 3 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

💵 A Laravel package for integrating the BnpParibas Mercanet

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.

License

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

As a first step, you need to change the following credentials located in the 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 
// Make sure to multiply the original amount * 100 (eg: 199.00 * 100 = 19000)
$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)
    ->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.

Sponsors

featured_repository

More Repositories

1

xstate

✨ A lightweight state machine library for PHP (inspired by xstate.js)
PHP
85
star
2

laravel-model-trackable

🔍 Laravel package that allows you to track and log nested changes applied on your models
PHP
58
star
3

laravel-query-inspector

The missing laravel helper that allows you to inspect your eloquent queries with it's bind parameters
PHP
56
star
4

mouadziani.com

🤵 My personal website, built with Nuxt.js and TailwindCss
Vue
43
star
5

laravel-deployer

Fast way to deploy your laravel project with one single command
Shell
40
star
6

Larabye

🎉 Larabye (Laravel + Rockabye) is a mini PHP starter / framework inspired from laravel features
PHP
31
star
7

ur-fullstack-coding-challenge

💪 My own implementation of the United Remote web coding challenge.
PHP
15
star
8

awesome-rockabye

🎵 Best covers of ROCKABYE ( CLEAN BANDIT FT. SEAN PAUL & ANNE-MARIE ), Nb: Only for Rockabye lovers
12
star
9

mouadziani

11
star
10

operator-mono-font

10
star
11

design-patterns-in-java

☕️ Implementation of the most popular design patterns using JAVA
Java
10
star
12

30-days-of-spring

🌱 30 days of Spring Framework Challenge
Java
9
star
13

millions-backend-challenge

My own implementation of the backend challenge
PHP
8
star
14

file-upload-jhispter

The repository contains an example for upload file using Jhipster (Spring and Angular)
Java
6
star
15

trolls-maker

[WIP] - Web application that allows you to make your own memes
Vue
6
star
16

access-tests-management

🚀 This project is for first tests management, for university that has tests before registration of students for the scholar year based on Java swing
Java
6
star
17

excel-diff-checker

Excel-diff-checker is a python script to compare lines to find the difference between two csv files.
Python
6
star
18

me

☕️ My resume
CSS
4
star
19

ngrx-practices

TypeScript
4
star
20

mouadziani.github.io

Personal website 🤵🏼
HTML
4
star
21

trance

🎵 Collection of my preferred trance tracks (for trance hipsters only)
4
star
22

Value-Object-Maker

[WIP] Generate a Value Object class with attributes from your existing eloquent models with one single command
4
star
23

votes-system

PHP
3
star
24

messneger-ui

Messenger UI clone using Vuejs & Tailwind Css
Vue
3
star
25

Flutter_EXAM

This repository contains my own implementation of the final exam of the mobile development 2 module (Master ISI)
Dart
3
star
26

laravel-model-progressible

[WIP] Easily make your model entries progressible
3
star
27

github-actions-laravel

Shared configs to deploy your laravel project via SSH using github actions
3
star
28

sales-analysis-hadoop

Sales analysis program using Hadoop
Java
3
star
29

travels-template

Landing page travel website buit on html, css, js, bootstrap4 from scratch :)
HTML
3
star
30

spring-boot-security-starter

Spring boot with spring security starter
Java
2
star
31

hierarchical-clustering

Hierarchical Clustering with Python and Scikit-Learn
Jupyter Notebook
2
star
32

Agents_Communication_JADE_MADKIT

Exchange messages between agents using Jade and Madkit platforms
Java
2
star
33

nova-acl

[WIP] Full roles and permissions system for laravel nova panel
2
star
34

ify

IdeaForYou App with angular and spring boot
Java
2
star
35

software-security-notes

My notes while studying Software Security
1
star
36

student_coloco_web

PHP
1
star
37

ACADEMIC-WEB-DEVELOPMENT-PROJECTS

My academic projects that I created while learning web development as Master ISI Student
PHP
1
star
38

zero-spark

[WIP] - Laravel spark clone based on TALL stack (built for artisanal web developers)
1
star
39

WH-FE-SLICING-TEST

My own implementation of the WalletHub Frontend slicing Tests challenge.
HTML
1
star
40

pizza-delivry

Web application for manage pizza deliveries based on JavaEE (JSF & JPA)
Java
1
star
41

SPRING-MVC-ACADEMIC-PROJECTS

Java
1
star
42

logistique

JavaScript
1
star
43

cosmy-web

Social Network and E-commerce platform for hairdressers staff
CSS
1
star
44

users-manager

Web application for manage users based on Jave EE, MVC Pattern & DataSource JNDI
Java
1
star
45

hb-hs

CSS
1
star
46

personnes-manager

Demo descktop application based on Java Swing & MVC Pattern
Java
1
star
47

mastering-laravel-step-by-step

This repository will contains lot of laravel modules as exercises (made for H.S = ANTAR)
1
star
48

Laravel_EXAM

This repository contains my own implementation of the final exam of the backend web development module (Master ISI)
PHP
1
star
49

watchcrunch

PHP
1
star
50

WH-FE-NG-TEST

My own implementation of the WalletHub Angular Tests challenge.
TypeScript
1
star