Have any questions:

Toll free:9801887718Available 24/7

Email our experts:info@mantraideas.com

In: Laravel

In recent years, Nepal’s digital economy has taken a significant leap forward, with ConnectIPS (also known as www connectips or connectips com) emerging as one of the country’s leading e-payment platforms in Nepal. Developed by Nepal Clearing House Ltd. (NCHL), ConnectIPS allows seamless interbank transactions, enabling users to pay for goods, services, government fees, and more, directly from their bank accounts. For Laravel developers building applications tailored for the Nepali market, integrating ConnectIPS unlocks a powerful, local payment gateway in your Laravel application development that supports real-time bank transfers across multiple financial institutions. In this blog, we’ll walk through how to integrate ConnectIPS into your Laravel application and start accepting payments the Nepali way.

Creating a Laravel Project

Let’s create a new laravel project by following command

laravel new connect-ips-integration
creating laravel project using laravel new command

Now, we have created fresh laravel project, let’s setup the project and create payments table in your Laravel framework project to store payment records.

php artisan make:model Payment -m

Now let’s add columns in migration file

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('payments', function (Blueprint $table) {
           $table->id();
           $table->string('amount');
           $table->string('status')->comment('Initiated,Pending,Failed,Success');
           $table->string('payment_method');
           $table->string('internal_transaction_id');
           $table->string('external_transaction_id')->nullable();
           $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('payments');
    }
};

Here, we have added amount, status, payment_method, internal_transaction_id and external_transaction_id. We will have two transaction ids, Internal for our application and External for ConnectIPS transaction id.

Lets migrate the migration file to database using php artisan migrate Command.

Payment Integration Using Third Party Package

Now, we have database setup, let’s install the package which we will use to integrate ConnectIPS payment .

composer require mantraideas/laravel-connectips

This will install required modules to our project.

installing laravel-connectips package

We have installed the package, let’s setup environment for the ConnectIPS integration.

Now we have to publish the config file. (This is optional)

php artisan vendor:publish --provider="MantraIdeas\LaravelConnectips\LaravelConnectipsServiceProvider"
publishing config from the package

Now, we have to add new env variables to our .env file.

CONNECTIPS_MERCHANT_ID=""
CONNECTIPS_APP_ID=""
CONNECTIPS_PASSWORD=""
CONNECTIPS_APP_NAME=""
CONNECTIPS_SUCCESS_URL="${APP_URL}/connectips/success/"
CONNECTIPS_FAILURE_URL="${APP_URL}/connectips/failure"
CONNECTIPS_PEM_PATH="app/private/privatekey.pem"
CONNECTIPS_URL="https://uat.connectips.com"

All the variables will be provided by ConnectIPS. And PEM file will be provided by ConnectIPS and you need to specify the path of the private key here.

laravel project directory where private key is stored

Now, we have configured our environment, let’s create route to make a payment. First let’s create a url where we will show a ConnectIPS form for payment and the user will submit it after connect ips login or QR scan and then we will be redirected to ConnectIPS payment page.

<?php

//web.php

use App\Enums\StatusEnum;
use App\Models\MembershipUser;
use App\Models\Order;
use App\Models\Payment;
use Illuminate\Support\Facades\Route;

Route::get('/', function () {

    $connectips = new \Mantraideas\LaravelConnectips\LaravelConnectips();
    $transactionId = uniqid('txn_');
    $transactionDetails = $connectips->generateData(
        transactionId: $transactionId,
        transactionAmount: 5000,
        referenceId: 'REF_' . uniqid(),
        remarks: 'Payment for service',
        particulars: 'Service payment',
        transactionDate: now()->format('d-m-Y'),
        transactionCurrency: 'NPR'
    );
    \App\Models\Payment::create(
        [
            'amount' => $transactionDetails['TXNAMT'],
            'status' => 'Initiated',
            'payment_method' => 'ConnectIPS',
            'internal_transaction_id' => $transactionId,

        ]
    );
    return view('welcome', [
        'connectIpsUrl' => config('connectips.connectIpsUrl') . '/connectipswebgw/loginpage',
        'transaction' => $transactionDetails,
        'successUrl' => route('payment.success'),
        'failureUrl' => route('payment.failure')
    ]);
});

Route::get('/payment/success', function () {
    $transactionId = request()->query('TXNID');
    if (!$transactionId) {
        return redirect()->route('payment.failed')->with('error', 'Invalid payment.');
    }

    $payment = Payment::where('internal_transaction_id', $transactionId)->first();
    if (!$payment) {
        return redirect()->route('payment.failed')->with('error', 'Transaction not found.');
    }
    $connectips = new \Mantraideas\LaravelConnectips\LaravelConnectips();
    $paymentValidation = $connectips->validatePayment($transactionId, ($payment->amount) * 100);
    if (isset($paymentValidation['status']) && $paymentValidation['status'] == 'SUCCESS') {
        $payment->status = "Success";
    } else {
        $payment->status = "Failed";
    }
    $payment->save();
    return view('payment.success', [
        'transactionId' => request()->query('TXNID')
    ]);
})->name('payment.success');

Route::get('/payment/failure', function () {
    $transactionId = request()->query('TXNID');
    if (!$transactionId) {
        return redirect()->route('payment.failed')->with('error', 'Invalid payment.');
    }

    $payment = Payment::where('internal_transaction_id', $transactionId)->first();
    if (!$payment) {
        return redirect()->route('payment.failed')->with('error', 'Transaction not found.');
    }
    $connectips = new \Mantraideas\LaravelConnectips\LaravelConnectips();
    $paymentValidation = $connectips->validatePayment($transactionId, ($payment->amount) * 100);
    if (isset($paymentValidation['status']) && $paymentValidation['status'] == 'SUCCESS') {
        $payment->status = "Success";
    } else {
        $payment->status = "Failed";
    }
    $payment->save();
    return view('payment.failure', [
        'transactionId' => request()->query('TXNID')
    ]);
})->name('payment.failure');

Here, we have three routes. One for payment initiaition, another for success handling and the last one for cancel or failed handling.

And the blade looks like this.

<!DOCTYPE html>
<html>
<head>
    <title>Payment Gateway Form (Debug View)</title>
    <style>
        body { font-family: Arial, sans-serif; padding: 20px; }
        .form-container { max-width: 600px; margin: 0 auto; }
        .form-field { margin-bottom: 15px; }
        label { display: inline-block; width: 150px; font-weight: bold; }
        input[type="text"] { width: 300px; padding: 8px; }
        .submit-btn { padding: 10px 20px; background: #4CAF50; color: white; border: none; cursor: pointer; }
    </style>
</head>
<body>
<div class="form-container">
    <h1>Connect IPS Payment Form</h1>
    <p>This is a debug view of the form that would auto-submit to Connect IPS</p>

    <form id="paymentForm" action="{{ $connectIpsUrl }}" method="POST">
        @foreach($transaction as $key => $value)
            <div class="form-field">
                <label for="{{ $key }}">{{ $key }}:</label>
                <input type="text" id="{{ $key }}" name="{{ $key }}" value="{{ $value }}" readonly>
            </div>
        @endforeach

        <div class="form-field">
            <label for="successUrl">successUrl:</label>
            <input type="text" id="successUrl" name="successUrl" value="{{ $successUrl }}" readonly>
        </div>

        <div class="form-field">
            <label for="failureUrl">failureUrl:</label>
            <input type="text" id="failureUrl" name="failureUrl" value="{{ $failureUrl }}" readonly>
        </div>

        <button type="submit" class="submit-btn">Submit to Connect IPS Manually</button>
    </form>

    <div style="margin-top: 30px; background: #f5f5f5; padding: 15px;">
        <h3>Debug Information</h3>
        <p><strong>POST URL:</strong> {{ $connectIpsUrl }}</p>
        <p><strong>Token:</strong> {{ $transaction['TOKEN'] ?? 'Not generated' }}</p>
        <p><strong>TXNID:</strong> {{ $transaction['TXNID'] ?? '' }}</p>
    </div>
</div>
</body>
</html>

Once you’ve set up the project, run it to view the ConnectIPS payment form landing page in your Laravel application.

payment form for ConnectIPS integration

Now, When user submit the form then the user will be redirected to connectIPS payment form (https://connectips.com/).

connectIPS payment form

Now, you can make the payment through QR scan or manual Login process. After payment completion user will be redirected to success url and on failed payment or on cancellation user will be redirected to fail url. After that we will handle the payment records accordingly.

Let’s handle the success payment first.

Route::get('/payment/success', function () {
    $transactionId = request()->query('TXNID');
    if (!$transactionId) {
        return redirect()->route('payment.failed')->with('error', 'Invalid payment.');
    }

    $payment = Payment::where('internal_transaction_id', $transactionId)->first();
    if (!$payment) {
        return redirect()->route('payment.failed')->with('error', 'Transaction not found.');
    }
    $connectips = new \Mantraideas\LaravelConnectips\LaravelConnectips();
    $paymentValidation = $connectips->validatePayment($transactionId, ($payment->amount) * 100);
    if (isset($paymentValidation['status']) && $paymentValidation['status'] == 'SUCCESS') {
        $payment->status = "Success";
    } else {
        $payment->status = "Failed";
    }
    $payment->save();
    return view('payment.success', [
        'transactionId' => request()->query('TXNID')
    ]);
})->name('payment.success');

Here, we get the transactionId from query param and check with our internal_transaction_id and check the status of the payment again and update the payment record based on the data received.

Likewise, we can validate the data and mark the payment as failed on the failure URL.

FYI: You will receive MERCHANT_ID, APP_ID, PASSWORD, APP_NAME and PEM file from ConnectIPS Nepal (connect ips contact number or connect ips contact email) and you will have to provide them your success url and failure url.

Conclusion

Now you can integrate ConnectIPS to your Laravel application easily. The LaravelConnectips package allows you to create payment and validate the status of payment. Here is the Github link for this demo project.

Spread the love

Leave a Reply

Your email address will not be published. Required fields are marked *