Pay10 Payment Gateway Integration In Laravel 10

  • 27-03-2023
  • 2984
  • Laravel 10
  • Haresh Chauhan

Watch Youtube Video (HINDI) :

Pay10 Payment Gateway Integration In Laravel 10; in this post, we will integrate the pay10 payment gateway from scratch, I will tell you how to integrate pay10 payment integration in laravel step-by-step guidelines. Before we start integrating you just need to generate your API keys from the pay10 dashboard login or signup for your account and generate.

This pay10 payment is popular, if you are running your e-commerce sites or any payment-accept sites, and want to give the option pay10 to the users you can integrate it into your laravel 10 apps. This article will tell you all the guidelines step by step to integrate into your app.

Pay10 payment gateway that allows merchants to accept online payments from users securely and conveniently. It offers a range of payment options including credit, and debit cards, e-wallets, and net banking. Pay10 payment is designed to be user-friendly and easily integrable with various platforms like laravel, making it an ideal solution for e-commerce businesses, or any payment platform.

Step 1. Install Laravel 10

Install the laravel 10 project, use the provided command in your system terminal, and paste this command. hit enter and it will install laravel current version in your system. Skip this step if you already installed the laravel app.

composer create-project laravel/laravel example-app

Step 2. Make PaymentController

We will create a PaymentController, and use the given command in your laravel 10 project terminal. This command will create a controller in your app.

php artisan make:controller PaymentController

Copy the given PaymentController code and paste it into your project PaymentController. In this controller, we have defined two methods. The first method for the make or creating a payment will redirect to payment. The second method is the success method. This method will handle the successful response from the payment gateway.

App\Http\Controllers\PaymentController.php
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\Pay10PGModule;

class PaymentController extends Controller
{
    public function index()
    {
        $pay10_transaction = new Pay10PGModule;

        $global_vars = $GLOBALS['global_vars'];

        //Mandate Fields
        $pay10_transaction->setPayId($global_vars['PAY_ID']);
        $pay10_transaction->setPgRequestUrl($global_vars['PG_REQUEST_URL']);
        $pay10_transaction->setSalt($global_vars['SALT']);
        $pay10_transaction->setReturnUrl($global_vars['RETURN_URL']);
        $pay10_transaction->setCurrencyCode($global_vars['CURRENCY_CODE']);
        $pay10_transaction->setTxnType($global_vars['TXNTYPE']);
        $pay10_transaction->setOrderId(time());
        $pay10_transaction->setCustEmail('dharmesh@gmail.com');
        $pay10_transaction->setCustName('Dharmesh Chauhan');
        $pay10_transaction->setCustStreetAddress1('Rajkot');
        $pay10_transaction->setAmount(1*100); // convert to Rupee from Paisa
        $pay10_transaction->setCustPhone(9999999999);

        //Mandate Fields

        //Optional Fields

        // $pay10_transaction->setCustCity((isset($_REQUEST['CUST_CITY'])?$_REQUEST['CUST_CITY']:''));
        // $pay10_transaction->setCustState((isset($_REQUEST['CUST_STATE'])?$_REQUEST['CUST_STATE']:''));
        // $pay10_transaction->setCustCountry((isset($_REQUEST['CUST_COUNTRY'])?$_REQUEST['CUST_COUNTRY']:''));
        // $pay10_transaction->setCustZip((isset($_REQUEST['CUST_ZIP'])?$_REQUEST['CUST_ZIP']:''));
        // $pay10_transaction->setProductDesc((isset($_REQUEST['PRODUCT_DESC'])?$_REQUEST['PRODUCT_DESC']:''));
        // $pay10_transaction->setCustShipStreetAddress1((isset($_REQUEST['CUST_SHIP_STREET_ADDRESS1'])?$_REQUEST['CUST_SHIP_STREET_ADDRESS1']:''));
        // $pay10_transaction->setCustShipCity((isset($_REQUEST['CUST_SHIP_CITY'])?$_REQUEST['CUST_SHIP_CITY']:''));
        // $pay10_transaction->setCustShipState((isset($_REQUEST['CUST_SHIP_STATE'])?$_REQUEST['CUST_SHIP_STATE']:''));
        // $pay10_transaction->setCustShipCountry((isset($_REQUEST['CUST_SHIP_COUNTRY'])?$_REQUEST['CUST_SHIP_COUNTRY']:''));
        // $pay10_transaction->setCustShipZip((isset($_REQUEST['CUST_SHIP_ZIP'])?$_REQUEST['CUST_SHIP_ZIP']:''));
        // $pay10_transaction->setCustShipPhone((isset($_REQUEST['CUST_SHIP_PHONE'])?$_REQUEST['CUST_SHIP_PHONE']:''));
        // $pay10_transaction->setCustShipName((isset($_REQUEST['CUST_SHIP_NAME'])?$_REQUEST['CUST_SHIP_NAME']:''));

        //Optional Fields

        $postdata = $pay10_transaction->createTransactionRequest();
        $pay10_transaction->redirectForm($postdata);
    }

    public function success(Request $request)
    {
        $input = $request->all();

        $pay10_transaction = new Pay10PGModule;

        $global_vars = $GLOBALS['global_vars'];

        $pay10_transaction->setSalt($global_vars['SALT']);
        $pay10_transaction->setMerchantHostedKey($global_vars['HOSTED_KEY']);
        $string = $pay10_transaction->aes_decryption($_POST['ENCDATA']);
        
        $data = $pay10_transaction->split_decrypt_string($string); 

        dd($data);
    }
}

Step 3. Make Model

Now we will create a model, using the given below command. This command will create a model. This model is now used for the database table purpose, This model's purpose is to define configuration and settings regarding payments.

php artisan make:model Pay10PGModule

After creating Pay10PGModule. Copy the given mode code and paste it into your model. You don't need to do anything just copy the whole model code and paste your above command through a created model that's it.

App\Models\Pay10PGModule.php
<?php

namespace App\Models;

$GLOBALS['global_vars'] = [
    'PAY_ID'=>'',
    'SALT'=>'',
    'HOSTED_KEY'=>'',
    'TXNTYPE'=>'SALE',
    'CURRENCY_CODE'=>356,
    'RETURN_URL'=> route('success'),
    'PG_REQUEST_URL' =>'https://secure.pay10.com/pgui/jsp/paymentrequest'
];

class Pay10PGModule
{
    /**
     * [$pay_id description]
     * @var [type]
     */
    private $pay_id;

    /**
     * [$salt description]
     * @var [type]
     */
    private $salt;
    
    /**
     * [$order_id description]
     * @var [type]
     */
    private $order_id;
    
    /**
     * [$return_url description]
     * @var [type]
     */
    private $return_url;
    
    /**
     * [$cust_email description]
     * @var [type]
     */
    private $cust_email;
    
    /**
     * [$cust_name description]
     * @var [type]
     */
    private $cust_name;
    
    /**
     * [$cust_street_address1 description]
     * @var [type]
     */
    private $cust_street_address1;
    
    /**
     * [$cust_city description]
     * @var [type]
     */
    private $cust_city;
    
    /**
     * [$cust_state description]
     * @var [type]
     */
    private $cust_state;
    
    /**
     * [$cust_country description]
     * @var [type]
     */
    private $cust_country;
    
    /**
     * [$cust_zip description]
     * @var [type]
     */
    private $cust_zip;
    
    /**
     * [$cust_phone description]
     * @var [type]
     */
    private $cust_phone;
    
    /**
     * [$currency_code description]
     * @var [type]
     */
    private $currency_code;
    
    /**
     * [$amount description]
     * @var [type]
     */
    private $amount;
    
    /**
     * [$product_desc description]
     * @var [type]
     */
    private $product_desc;
    
    /**
     * [$cust_ship_street_address1 description]
     * @var [type]
     */
    private $cust_ship_street_address1;
    
    /**
     * [$cust_ship_city description]
     * @var [type]
     */
    private $cust_ship_city;
    
    /**
     * [$cust_ship_state description]
     * @var [type]
     */
    private $cust_ship_state;
    
    /**
     * [$cust_ship_country description]
     * @var [type]
     */
    private $cust_ship_country;
    
    /**
     * [$cust_ship_zip description]
     * @var [type]
     */
    private $cust_ship_zip;
    
    /**
     * [$cust_ship_phone description]
     * @var [type]
     */
    private $cust_ship_phone;
    
    /**
     * [$cust_ship_name description]
     * @var [type]
     */
    private $cust_ship_name;
    
    /**
     * [$txn_type description]
     * @var [type]
     */
    private $txn_type;

    /**
     * [$pg_request_url description]
     * @var [type]
     */
    private $pg_request_url;
    private $pg_merchant_hosted_key;
    

    /**
     * @param string $pay_id
     *
     * @return self
     */
    public function setPayId($pay_id)
    {
        $this->pay_id = $pay_id;

        return $this;
    }

    /**
     * @param string $salt
     *
     * @return self
     */
    public function setSalt($salt)
    {
        $this->salt = $salt;

        return $this;
    }

    /**
     * @param string $order_id
     *
     * @return self
     */
    public function setOrderId($order_id)
    {
        $this->order_id = $order_id;

        return $this;
    }

    /**
     * @param string $return_url
     *
     * @return self
     */
    public function setReturnUrl($return_url)
    {
        $this->return_url = $return_url;

        return $this;
    }

    /**
     * @param string $cust_email
     *
     * @return self
     */
    public function setCustEmail($cust_email)
    {
        $this->cust_email = $cust_email;

        return $this;
    }

    /**
     * @param string $cust_name
     *
     * @return self
     */
    public function setCustName($cust_name)
    {
        $this->cust_name = $cust_name;

        return $this;
    }

    /**
     * @param string $cust_street_address1
     *
     * @return self
     */
    public function setCustStreetAddress1($cust_street_address1)
    {
        $this->cust_street_address1 = $cust_street_address1;

        return $this;
    }

    /**
     * @param string $cust_city
     *
     * @return self
     */
    public function setCustCity($cust_city)
    {
        $this->cust_city = $cust_city;

        return $this;
    }

    /**
     * @param string $cust_state
     *
     * @return self
     */
    public function setCustState($cust_state)
    {
        $this->cust_state = $cust_state;

        return $this;
    }

    /**
     * @param string $cust_country
     *
     * @return self
     */
    public function setCustCountry($cust_country)
    {
        $this->cust_country = $cust_country;

        return $this;
    }

    /**
     * @param string $cust_zip
     *
     * @return self
     */
    public function setCustZip($cust_zip)
    {
        $this->cust_zip = $cust_zip;

        return $this;
    }

    /**
     * @param string $cust_phone
     *
     * @return self
     */
    public function setCustPhone($cust_phone)
    {
        $this->cust_phone = $cust_phone;

        return $this;
    }

    /**
     * @param string $currency_code
     *
     * @return self
     */
    public function setCurrencyCode($currency_code)
    {
        $this->currency_code = $currency_code;

        return $this;
    }

    /**
     * @param string $amount
     *
     * @return self
     */
    public function setAmount($amount)
    {
        $this->amount = $amount;

        return $this;
    }

    /**
     * @param string $product_desc
     *
     * @return self
     */
    public function setProductDesc($product_desc)
    {
        $this->product_desc = $product_desc;

        return $this;
    }

    /**
     * @param string $cust_ship_street_address1
     *
     * @return self
     */
    public function setCustShipStreetAddress1($cust_ship_street_address1)
    {
        $this->cust_ship_street_address1 = $cust_ship_street_address1;

        return $this;
    }

    /**
     * @param string $cust_ship_city
     *
     * @return self
     */
    public function setCustShipCity($cust_ship_city)
    {
        $this->cust_ship_city = $cust_ship_city;

        return $this;
    }

    /**
     * @param string $cust_ship_state
     *
     * @return self
     */
    public function setCustShipState($cust_ship_state)
    {
        $this->cust_ship_state = $cust_ship_state;

        return $this;
    }

    /**
     * @param string $cust_ship_country
     *
     * @return self
     */
    public function setCustShipCountry($cust_ship_country)
    {
        $this->cust_ship_country = $cust_ship_country;

        return $this;
    }

    /**
     * @param string $cust_ship_zip
     *
     * @return self
     */
    public function setCustShipZip($cust_ship_zip)
    {
        $this->cust_ship_zip = $cust_ship_zip;

        return $this;
    }

    /**
     * @param string $cust_ship_phone
     *
     * @return self
     */
    public function setCustShipPhone($cust_ship_phone)
    {
        $this->cust_ship_phone = $cust_ship_phone;

        return $this;
    }

    /**
     * @param string $cust_ship_name
     *
     * @return self
     */
    public function setCustShipName($cust_ship_name)
    {
        $this->cust_ship_name = $cust_ship_name;

        return $this;
    }

    /**
     * @param string $txn_type
     *
     * @return self
     */
    public function setTxnType($txn_type)
    {
        $this->txn_type = $txn_type;
        return $this;
    }

    /**
     * @param string $pg_request_url
     *
     * @return self
     */
    public function setPgRequestUrl($pg_request_url)
    {
        $this->pg_request_url = $pg_request_url;

        return $this;
    }

    public function setMerchantHostedKey($pg_merchant_hosted_key)
    {
        $this->pg_merchant_hosted_key = $pg_merchant_hosted_key;

        return $this;
    }

    

    /**
     * [_empty to remove null values]
     * @param  string $value input string
     * @return string        same as value or empty string
     */
    public function _empty($value)
    {
        return isset($value) ? $value : '';
    }

    /**
     * [generateHash description]
     * @param  array $postdata Post data
     * @return string           hash of string
     */
    public function generateHash($postdata)
    {
        ksort($postdata);
        $all = '';
        foreach ($postdata as $name => $value) {
            $all .= $name."=".$value."~";
        }
        $all = substr($all, 0, -1);
        $all .= $this->salt;
        return strtoupper(hash('sha256', $all));
    }

    /**
     * [createTransactionRequest description]
     * @return string [description]
     */
    public function createTransactionRequest()
    {
        $this->performChecks();
        $post_variables = array(
            "PAY_ID" => $this->_empty($this->pay_id),
            "ORDER_ID" => $this->_empty($this->order_id),
            "RETURN_URL" => $this->_empty($this->return_url),
            "CUST_EMAIL" => $this->_empty($this->cust_email),
            "CUST_NAME" => $this->_empty($this->cust_name),
            "CUST_STREET_ADDRESS1" => $this->_empty($this->cust_street_address1),
            "CUST_CITY" => $this->_empty($this->cust_city),
            "CUST_STATE" => $this->_empty($this->cust_state),
            "CUST_COUNTRY" => $this->_empty($this->cust_country),
            "CUST_ZIP" => $this->_empty($this->cust_zip),
            "CUST_PHONE" => $this->_empty($this->cust_phone),
            "CURRENCY_CODE" => $this->_empty($this->currency_code),
            "AMOUNT" => $this->_empty($this->amount),
            "PRODUCT_DESC" => $this->_empty($this->product_desc),
            "CUST_SHIP_STREET_ADDRESS1" => $this->_empty($this->cust_ship_street_address1),
            "CUST_SHIP_CITY" => $this->_empty($this->cust_ship_city),
            "CUST_SHIP_STATE" => $this->_empty($this->cust_ship_state),
            "CUST_SHIP_COUNTRY" => $this->_empty($this->cust_ship_country),
            "CUST_SHIP_ZIP" => $this->_empty($this->cust_ship_zip),
            "CUST_SHIP_PHONE" => $this->_empty($this->cust_ship_phone),
            "CUST_SHIP_NAME" => $this->_empty($this->cust_ship_name),
            "TXNTYPE" => $this->_empty($this->txn_type),
        );
        $post_variables['HASH'] = $this->generateHash($post_variables);

        return $post_variables;
    }

    /**
     * [performChecks description]
     * @return [type] [description]
     */
    public function performChecks()
    {
        // required values
        $check_values = array(
            'PAY_ID' => $this->pay_id,
            'ORDER_ID' => $this->order_id,
            'RETURN_URL' => $this->return_url,
            'CUST_EMAIL' => $this->cust_email,
            'CUST_PHONE' => $this->cust_phone,
            'AMOUNT' => $this->amount,
            'TXNTYPE' => $this->txn_type,
            'CURRENCY_CODE' => $this->currency_code
        );

        foreach ($check_values as $key => $value) {
            if (!isset($value)) {
                die('

'.$key.' value is missing

'); } } } /** * [validateResponse description] * @param [type] $response [description] * @return [type] [description] */ public function validateResponse($response) { $postdata = $response; $salt=$this->salt; ksort($postdata); unset($postdata["HASH"]); unset($postdata["CARD_ISSUER_BANK"]); $all = ''; foreach ($postdata as $name => $value) { $all .= $name."=".$value."~"; } $all = substr($all, 0, -1); $all .= $salt; $generated_hash = strtoupper(hash('sha256', $all)); if ($response['HASH'] == $generated_hash) { return true; } else { return false; } } /** * [redirectForm description] * @param [type] $postdata [description] * @return [type] [description] */ public function redirectForm($postdata) { $output = '<form id="payForm" action="'.$this->pg_request_url.'" method="post">'; foreach ($postdata as $key => $value) { $output .= '<input type="hidden" name="' . $key . '" value="' . $value . '">' . "\n"; } $output .= '</form><script> document.getElementById("payForm").submit(); </script><h2>Redirecting...</h2>'; echo $output; exit(); } //for aes encrytion public function aes_encyption($hash_string){ $CryptoKey= $this->pg_merchant_hosted_key; //Prod Key $iv = substr($CryptoKey, 0, 16); //or provide iv $method = "AES-256-CBC"; $ciphertext = openssl_encrypt($hash_string, $method, $CryptoKey, OPENSSL_RAW_DATA, $iv); $ENCDATA= base64_encode($ciphertext); return $ENCDATA; } public function aes_decryption($ENCDATA){ $CryptoKey= $this->pg_merchant_hosted_key; //Prod Key $iv = substr($CryptoKey, 0, 16); //or provide iv $method = "AES-256-CBC"; $encrptedString = openssl_decrypt($ENCDATA, $method, $CryptoKey, 0, $iv); return $encrptedString; } public function split_decrypt_string($value) { $plain_string=explode('~',$value); $final_data = array(); foreach ($plain_string as $key => $value) { $simple_string=explode('=',$value); $final_data[$simple_string[0]]=isset($simple_string[1])?$simple_string[1]:''; } return $final_data; } }

Step 4. Routes Define

Now we will create two routes for the creation of payment and handle success response from the payment gateway. Copy the given web.php file routes and paste them into your web.php file. You just need to copy that given two routes only. Make sure you imported that create a controller in the web.php routes file. as in the below given example.

routes\web.php
<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\PaymentController;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider and all of them will
| be assigned to the "web" middleware group. Make something great!
|
*/

Route::get('pay',[PaymentController::class,'index']);
Route::any('success',[PaymentController::class,'success'])->name('success');

Step 5. Start Development Server

In this step, we will start the development server, using the given provided command. copy that given command and paste it into your app terminal. This command will start your local development server.

php artisan serve

Copy this given URL and paste it into your web browser. You will redirect to open your pay10 payment accept platform.

http://localhost:8000/pay

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 :