Pinelabs Payment Gateway Integration Tutorial In Laravel

  • 18-06-2023
  • 2159
  • Laravel 10
  • Haresh Chauhan

Pinelabs payment gateway integration in laravel in this post we will see in brief integration tutorial with an example. Pinelab is India's popular payment gateway to collect finance via your users by integration API into your site. You can integrate various platforms like e-commerce, and business-related sites where you collect payment from the user.

Pinelabs is a leading provider of payment solutions and payment gateway services in India. They offer a range of payment products and services that cater to the needs of businesses in various industries.

Pinelabs' payment gateway enables merchants to accept online payments securely and efficiently. It supports multiple payment methods, including credit cards, debit cards, net banking, and mobile wallets. The payment gateway integrates with e-commerce platforms, allowing businesses to easily accept online payments on their websites or mobile applications.

To integrate the Pine Labs payment gateway with Laravel, you can follow these steps:

  • 1. Get Pine Labs Integration Details
  • 2. Set Up Laravel Project
  • 3. Install Required Package

Step 1. Clone New Laravel App:

First, we will install a new fresh laravel app, Open your terminal and hit this below provided command in your terminal. Before cloning the laravel app you must require the composer's latest version and php support Apache system.

composer create-project laravel/laravel example-app

Step 2. Composer Install:

Laravel provides various packages for integrating different payment gateways. To integrate Pine Labs, you can use the "omnipay" package, which is a multi-gateway payment processing library. Install it via Composer by running the following command.

In this step, we just need to install the composer "omnipay/omnipay" for the run core dependency of the pinelab payment in the laravel app. We will install Composer. use the given below command and paste it into your app terminal. This command will install a composer for the Pinelab payment gateway.

composer require omnipay/omnipay

Step 3. Configure Payment Gateway:

Create a configuration file for Pine Labs in your Laravel project. Run the following command to generate the file:

php artisan vendor:publish --provider="Omnipay\OmnipayServiceProvider" --tag=config

This command will generate the config/omnipay.php file where you can add your Pine Labs configuration details.

Step 4. Create Payment Controller:

Generate a new controller that will handle payment requests and responses. Run the following command:

php artisan make:controller PaymentController

This command will create a new file app/Http/Controllers/PaymentController.php. Open the file and define the necessary methods to initiate and process payments.

Step 5. Initiate Payment:

In the PaymentController, add a method to initiate the payment request. Here's an example implementation:

use Omnipay\Omnipay;

public function initiatePayment()
{
    $gateway = Omnipay::create('PineLabs');
    $gateway->setMerchantId('<your_merchant_id>');
    $gateway->setAccessCode('<your_access_code>');
    $gateway->setSecretKey('<your_secret_key>');

    $params = [
        'amount' => 100.00, // Amount to be charged
        'currency' => 'INR', // Currency code
        // Other parameters as required by Pine Labs
    ];

    $response = $gateway->purchase($params)->send();

    if ($response->isRedirect()) {
        $response->redirect();
    } else {
        // Handle payment initiation failure
    }
}

Make sure to replace <your_merchant_id>, <your_access_code>, and <your_secret_key> with your actual Pine Labs credentials.

Step 6. Handle Payment Response:

Add another method in the PaymentController to handle the response from Pine Labs after the payment process is completed. Example implementation:

public function handlePaymentResponse()
{
    $gateway = Omnipay::create('PineLabs');
    $gateway->setMerchantId('<your_merchant_id>');
    $gateway->setAccessCode('<your_access_code>');
    $gateway->setSecretKey('<your_secret_key>');

    $response = $gateway->completePurchase($_POST)->send();

    if ($response->isSuccessful()) {
        // Payment was successful
    } else {
        // Payment failed
    }
}

Step 7. Define Routes

In your Laravel project, define the routes that correspond to the methods in the PaymentController. Open the routes/web.php file and add the following routes:

Route::post('/payment/initiate', [PaymentController::class, 'initiatePayment'])->name('payment.initiate');
Route::post('/payment/response', [PaymentController::class, 'handlePaymentResponse'])->name('payment.response');

Step 8. Update Payment Form

In your application's view file where the payment form is displayed, make sure to set the form action to the payment.initiate route and include any required payment details.

Step 9. Start Server

In this step, we will start the developmet server, Use given below command and start your local development server. Ignore this step if you working on a live server and predefined domain.

php artisan serve

Copy the below-given example and create an initial payment in the Pinelabs account. That's it. You will redirect to the Pinelabs count after successful payment you will redirect to your return response url given.

http://127.0.0.1:8000/payment/initiate

We always thanks to you for reading our blogs.


dharmesh-image

Dharmesh Chauhan

(Swapinfoway Founder)

Hello Sir, We are brothers origin from Gujarat India, Fullstack developers working together since 2016. We have lots of skills in web development in different technologies here I mention PHP, Laravel, Javascript, Vuejs, Ajax, API, Payment Gateway Integration, Database, HTML5, CSS3, and Server Administration. So you need our service Please Contact Us

haresh-image

Haresh Chauhan

(Co-Founder)


We Are Also Recommending You :