Integration of payment gateway in Laravel 5.1

In Laravel Cashier we had about integrating Stripe Payment Gateway for users out off India. Now we will see how to integrate Indian Payment Gateways in Laravel 5.1.

Laravel has a package called “IndiPay – Indian Payment Gateways” which supports payment gateways like CCAvenue, PayUMoney, EBS, CitrusPay, InstaMojo.

Step 1: First we will Install the package through composer.

          composer require softon/indipay

Step 2: Add the service providers to the app.php file in the config folder.

          ‘SoftonIndipayIndipayServiceProvider’,

Step 3 : Add alias for the Facades to config/app.php file

          ‘Indipay’ => ‘SoftonIndipayFacadesIndipay’,

Step 4: Then, publish the vendor to have a config file in Laravel config folder.

How to implement it in our project?

It is always a best practice to keep configuration variables in .env file. Update the .env file with the appropriate Gateway Keys.

Then, edit the config/indipay.php file and set the Gateway name that we used in .env file.

Steps to Initialise the payment request with a Controller.

1.Add Facades in the beginning of the controller

           use SoftonIndipayFacadesIndipay;

2.After that in the method where the payment has to be achieved, include the following code:

          $parameters = [
                ‘txnid’ => ‘XXXX’,
                 ‘redirect_url’ => ‘XXXX’,
                ‘purpose’ => ‘Testing’,
                ‘amount’ => 2500,
                ‘buyer_name’ => ‘XXX’,
                ‘allow_repeated_payments’ => <true/false>
              ];

We need all the above POST parameters to successfully do the payment transaction.

3.After specifying the parameters, you need to two more lines to make payment request.

        $order = Indipay::prepare($parameters);
         return Indipay::process($order);

The above line of code will generate the below form,

         <html> 
         <head>
         <title>IndiPay</title>
         </head>
         <body>
         <form method=”get” name=”redirect” action=”{{ $longurl }}”></form>
         <script language=’javascript’>document.redirect.submit();</script>
         </body>
         </html>

that will be submitted automatically due to the statement return.

And then the page will be redirected to the specified Payment Gateway that we have configured. After the successful completion of the money transfer, it will be redirected to the URL which we have specified in the parameter list.

4.To get the response from the Payment Gateway, we can use the below lines of code to get the status of the transaction whether success or failure.

   public function response(Request $request)
     {
                $response = Indipay::response($request);
                dd($response);
     }

Sample response :

  {
         “payment_request”: {
          “id”: “92e58bd771414d05a5e443b0a85f8b43”,
          “phone”: “+919999999999”,
          “email”: “foo@example.com”,
           “buyer_name”: “David Doe”,
           …more properties…
           “payments”: [
                        {
                         “payment_id”: “MOJO5a07005J30161862”,
                          “quantity”: 1,
                          “status”: “Credit”,
                          …more properties
                          }
                ],
     },
      “success”: true
     }

Each payment response has a key “status” if the value of the key is “Credit” then the payment was successful otherwise it has failed.

Hope this blog has helped you in integrating Indian Payment gateway. We will come back with more interesting and useful blog next time keep watching for updates.

Suguna K,
PHP Developer,
Mallow Technologies.

3 Comments

  1. Ashwani

    Oops! The page couldn’t be found. getting error on http://localhost/edushedu/index.php/indipay/response. please help

    1. Mallow

      Ashwani, have you added the below keys with value from the instamojo account in .env file

      INSTAMOJO_API_KEY
      INSTAMOJO_AUTH_TOKEN
      INDIPAY_SALT

  2. sachin

    Class ‘SoftonIndipayIndipayServiceProvider’ not found

Leave a Reply

%d bloggers like this: