Why Integrate Moneris Payment Gateway in Laravel 11?

Integrating a reliable payment gateway is crucial for any Laravel 11 application handling online transactions, especially if your audience includes customers in Canada or cross-border with the US. Moneris, as Canada's leading payment processor (backed by major banks like RBC and BMO), powers commerce for hundreds of thousands of businesses and remains a top choice in 2026 for secure, efficient e-commerce payments.


Here are the key reasons to choose Moneris for your Laravel 11 project:


  • Strong Focus on the Canadian Market
    Moneris is Canadian-born and bred, making it the most trusted option for businesses targeting Canadian customers. It excels at handling local payment preferences like Interac debit, contactless payments, credit cards (Visa, Mastercard, Amex), Apple Pay, Google Pay, and more. This ensures higher approval rates, lower decline risks, and a seamless checkout experience for Canadian shoppers—something global alternatives like Stripe or Square may not optimize as well for domestic transactions.
  • Robust Security and Fraud Prevention
    Moneris leads in payment security with advanced fraud tools, real-time monitoring, and full PCI DSS compliance (Level 1 as a service provider). Their solutions encrypt data and protect against threats, building customer trust and reducing chargeback risks. For developers, using modern integrations like Moneris Checkout (a hosted/tokenized payment page) significantly lowers your PCI compliance burden—often to SAQ-A level—by keeping sensitive card data off your Laravel server entirely.
  • Omnichannel and Flexible E-Commerce Support
    Moneris supports unified commerce, bridging online and in-store payments for consistent experiences. Features include multi-currency processing, recurring billing (via Vault if needed), and easy integration with platforms. In Laravel 11, you can leverage their APIs or hosted solutions to add secure checkout flows without reinventing the wheel.
  • Competitive Advantages Over Alternatives in Canada (2026)
    Compared to Stripe (flat ~2.9% + $0.30 fees, great for developers but higher FX for cross-border) or Square (simpler for in-person/retail but less optimized for pure e-commerce scale), Moneris often provides negotiable/custom rates for higher volumes, better local support (24/7 Canadian-based), and lower costs for certain card types (e.g., Amex in B2B). It's especially ideal if your app serves primarily Canadian users or combines online with potential physical expansion.
  • Modern Integration Recommendations for 2026
    While legacy methods (like eSELECTplus direct card handling) still work, Moneris strongly pushes Moneris Checkout and hosted/tokenization options in 2026. These reduce your PCI scope dramatically (up to 90% in some environments with P2PE enhancements), minimize risks from handling raw card data, and align with evolving standards like 3DS 2.0 for better fraud protection and user experience.

In short, if your Laravel 11 app targets Canadian e-commerce, needs rock-solid local compliance and support, or wants to prioritize security without heavy PCI overhead, Moneris delivers unmatched reliability and peace of mind.



Integrate Moneris Payment Gateway in Laravel 11: Step-by-Step Tutorial

Table Of Content

1 Prerequisites for Moneris Integration in Laravel 11

  • PHP 8.2+ (Laravel 11 requirement)
  • Composer
  • MySQL database
  • Moneris merchant account (test/store credentials from Merchant Resource Center)

2 Introduction

Integrating a reliable payment gateway like Moneris is essential for Canadian and US-based e-commerce apps built with Laravel. Moneris supports Visa, Mastercard, Amex, and more, with strong fraud tools.

3 Create a New Laravel 11 Project

3.1 Install Laravel Project

First, make sure your computer has a composer.
Use the following command to install new Laravel Project.

composer create-project laravel/laravel moneris-payment-app

Then, navigate to your project directory:

cd moneris-payment-app

3.2 Configure MySql Database

Upon Successful Transaction, the payment trasactions data will be stored in the database. This process involves accessing the .env file to input and define the database credentials.

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=moneris_app
DB_USERNAME=root
DB_PASSWORD=

4 Install Moneris Library (Legacy Approach)

4.1 Add Moneris Library

Download Moneris PHP library (from developer.moneris.com or similar). Place in app/Libraries/. Update composer.json autoload:

"autoload": {
    "psr-4": {
        "App\\": "app/",
        "App\\Libraries\\": "app/Libraries/"
    }
}
Now run the following command

composer dump-autoload

Modern Alternative Recommendation: Use a maintained wrapper like

https://github.com/craigpaul/moneris-api (via Composer if available) or implement Moneris Checkout JS SDK.

5  Obtain Moneris Credentials

5.1 Login into Moneris Merchant Resource Center

Login into Moneris Merchant Resource Center using "Username","Store ID" and Password

5.2 Get Moneris API Token

Inside the Moneris Gateway merchant account, you need to obtain an API Token. Go to My Account and click on the ADMIN. Then click on Store Settings and click on the button to generate an API Token.

Moneris Merchant Resource Center Dashboard
Moneris Merchant Resource Center Store Setting
Moneris Merchant Resource Center API Token

6 Configure Moneris Credentials

6.1 Add the Moneris API Credentials in .env

Insert the Store ID and API Token, Which we obtained from previous step MONERIS_STORE_ID and MONERIS_API_TOKEN.

MONERIS_STORE_ID=your_store_id
MONERIS_API_TOKEN=your_api_token
MONERIS_ENV=test  # change to 'prod' in production

7 Create Payment Model & Migration

Now, you need to create migration for new table payments to store the response of Moneris API. Also, create a model Payment for the same. Run this below command.

php artisan make:model Payment —migration

In the generated new migration file, update the up and down methods as described below:

database/migrations/2024_05_22_163057_payment.php


<?php
Schema::create('payments', function (Blueprint $table) {
    $table->id();
    $table->string('txn_number')->nullable();
    $table->string('receipt_id')->nullable();
    $table->string('reference_num')->nullable();
    $table->string('user_email')->nullable();
    $table->decimal('amount', 10, 2);
    $table->text('message')->nullable();
    $table->string('status')->default('pending'); // e.g., success/failed
    $table->timestamps();
});

Use the following command to run the migration to update your database.

php artisan migrate

app/Models/Payment.php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Payment extends Model
{
    protected $fillable = ['txn_number', 'receipt_id', 'reference_num', 'user_email', 'amount', 'message', 'status'];
}


8 Create New Controller - MonerisController

Use the following artisan command to Create Controller.

php artisan make:controller MonerisController

app/Http/Controllers/MonerisController.php (cleaned/updated):

<?php
namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\Payment;
// Import Moneris classes (adjust based on your library placement)
use App\Libraries\mpgHttpsPost;
use App\Libraries\mpgRequest;
use App\Libraries\Transaction;
use App\Libraries\mpgAvsInfo;
use App\Libraries\mpgCvdInfo;

class MonerisController extends Controller
{
    public function show()
    {
        return view('payment.form');
    }

    public function process(Request $request)
    {
        $request->validate([
            'amount' => 'required|numeric|min:1',
            'card_number' => 'required|digits_between:13,19',
            'expiry_month' => 'required|digits:2',
            'expiry_year' => 'required|digits:2',
            'cvv' => 'required|digits:3,4',
            'email' => 'required|email',
            // Add other fields as needed
        ]);

        $storeId = env('MONERIS_STORE_ID');
        $apiToken = env('MONERIS_API_TOKEN');
        $testMode = env('MONERIS_ENV', 'test') === 'test';

        // Build transaction (simplified; add full AVS/CVD as in original)
        $txn = [
            'type' => 'purchase',
            'order_id' => 'order-' . uniqid(),
            'amount' => number_format($request->amount, 2, '.', ''),
            'pan' => $request->card_number,
            'expdate' => $request->expiry_month . $request->expiry_year,
            'crypt_type' => '7',
            'cust_id' => 'cust-' . rand(1000, 9999),
        ];

        $mpgTxn = new Transaction($txn);
        // Add AVS/CVD objects similarly...

        $mpgRequest = new mpgRequest($mpgTxn);
        $mpgRequest->setProcCountryCode("CA"); // or "US"
        $mpgRequest->setTestMode($testMode);

        $mpgHttpPost = new mpgHttpsPost($storeId, $apiToken, $mpgRequest);
        $response = $mpgHttpPost->getMpgResponse();

        if ($response->getResponseCode() < 50) { // Adjust threshold per Moneris docs
            Payment::create([
                'txn_number' => $response->getTxnNumber(),
                'receipt_id' => $response->getReceiptId(),
                'reference_num' => $response->getReferenceNum(),
                'user_email' => $request->email,
                'amount' => $request->amount,
                'message' => $response->getMessage(),
                'status' => 'success',
            ]);

            return redirect()->back()->with('success', 'Payment processed successfully!');
        }

        return redirect()->back()->with('error', $response->getMessage() ?: 'Payment failed.');
    }
}
?>

9 Define Routes (routes/web.php)


use App\Http\Controllers\MonerisController;

Route::get('/payment', [MonerisController::class, 'show'])->name('payment.show');
Route::post('/payment/process', [MonerisController::class, 'process'])->name('payment.process');

10 Create Blade View (resources/views/payment/form.blade.php)

resources/views/payment/form.blade.php

@extends('layouts.app')

@section('content')
<div class="container mx-auto py-10">
    <h1 class="text-3xl font-bold mb-6">Moneris Payment Demo</h1>

    @if (session('success'))
        <div class="bg-green-100 p-4 mb-4 rounded">{{ session('success') }}</div>
    @endif
    @if (session('error'))
        <div class="bg-red-100 p-4 mb-4 rounded">{{ session('error') }}</div>
    @endif

    <form method="POST" action="{{ route('payment.process') }}" class="max-w-lg mx-auto">
        @csrf
        <!-- Amount, Card Number, Expiry, CVV, Email, AVS fields... -->
        <button type="submit" class="bg-blue-600 text-white px-6 py-3 rounded">Pay Now</button>
    </form>
</div>
@endsection


11 Folder Structure

12 Test the Integration

Use the following artisan command to Test the App.

php artisan serve

Visit /payment. Use Moneris test cards (e.g., 4242424242424242, expiry future, CVV 123).

13 Conclusion

You've now integrated Moneris into Laravel 11! For production, switch to Moneris Checkout to avoid handling raw card data. Explore recurring billing via Moneris Vault if needed. Questions? Comment below.
Revathi M - PHP and CodeIgniter Developer

Written by Revathi M

PHP Developer & Technical Writer · 10+ years building web applications with CodeIgniter and Laravel

Revathi specializes in PHP backend development, authentication systems, and REST API design. She writes practical, production-tested tutorials at Get Sample Code to help developers build secure applications faster.

Frequently Asked Questions

You need PHP 8.2 or higher, Composer, a MySQL database, and a Moneris Merchant account with Store ID and API Token.

Run `composer create-project laravel/laravel moneris-payment-app`, then `cd moneris-payment-app`.

Update the `.env` file with your MySQL details: `DB_DATABASE=laravel11`, `DB_USERNAME=root`, `DB_PASSWORD=`, etc.

Download the library ZIP, create `app/Libraries/`, place the files there, update `composer.json` autoload with 'App\\Libraries\\': 'app/libraries/', then run `composer dump-autoload`.

Log into Moneris Merchant Resource Center, generate API Token under Store Settings. Add to `.env`: `MONERIS_STORE_ID=your-store-id` and `MONERIS_API_TOKEN=your-api-token`.

Run `php artisan make:model Payment --migration`, update the migration to create `payments` table (txn_number, receipt_id, referenc_num, user_email, amount, message, timestamps), then `php artisan migrate`.

Run `php artisan make:controller MonerisController`, implement `index()` for the form view and `store()` for processing the transaction.

In `store()`, use Moneris classes like `MpgRequest`, `MpgHttpsPost`, add AVS and CVD info, send the purchase request, check response (success if responseCode < 50), and save to database.

Customer info (name, address, email, phone), card details (number, expiry, CVV), and amount.

In `routes/web.php`, add `Route::get('payment', [MonerisController::class, 'index']);` and `Route::post('moneris-payment', [MonerisController::class, 'store'])->name('moneris.payment.store');`.

Use `setTestMode(true)` in the request object during development.

Common issues: incorrect Store ID/API Token, invalid test card details, missing AVS/CVD fields, or network errors. Check `$mpgResponse->getMessage()`.

AVS verifies address details, CVD checks CVV for added fraud protection (both optional but recommended).

Run `php artisan serve`, visit `http://127.0.0.1:8000/payment`, use Moneris test card numbers, and submit the form.