All Projects → anandsiddharth → Laravel Paytm Wallet

anandsiddharth / Laravel Paytm Wallet

Licence: mit
Integrate paytm wallet in your laravel application easily with this package. This package uses official Paytm PHP SDK's.

Projects that are alternatives of or similar to Laravel Paytm Wallet

Notifier
NO LIBRARIES socket per page bridge for your Laravel application. (CLIENT PART INCLUDED)
Stars: ✭ 57 (-1.72%)
Mutual labels:  laravel, laravel-5-package
Orderable
My very first Laravel package
Stars: ✭ 21 (-63.79%)
Mutual labels:  laravel, laravel-5-package
Socialite Mailru
MailRu OAuth2 Provider for Laravel Socialite
Stars: ✭ 25 (-56.9%)
Mutual labels:  laravel, laravel-5-package
Angular5.2 Laravel5.6
Angular 5.2 and Laravel 5.6 Authentication and CRUD
Stars: ✭ 17 (-70.69%)
Mutual labels:  laravel, laravel-5-package
Larrock Core
Core components for LarrockCMS
Stars: ✭ 46 (-20.69%)
Mutual labels:  laravel, laravel-5-package
Identity Number
Validator for Swedish personal identity numbers (personnummer). For use "standalone" or with Laravel.
Stars: ✭ 17 (-70.69%)
Mutual labels:  laravel, laravel-5-package
Laravel Test Factory Helper
Generate Laravel test factories from your existing models
Stars: ✭ 873 (+1405.17%)
Mutual labels:  laravel, laravel-5-package
Laravel Mysql Spatial
MySQL Spatial Data Extension integration with Laravel.
Stars: ✭ 578 (+896.55%)
Mutual labels:  laravel, laravel-5-package
Laravel Settings
Simple Settings package for a laravel application
Stars: ✭ 45 (-22.41%)
Mutual labels:  laravel, laravel-5-package
Russianpost Sdk
PHP SDK для Почты России
Stars: ✭ 43 (-25.86%)
Mutual labels:  laravel, laravel-5-package
Laravel Widgetize
A minimal package to help you make your laravel application cleaner and faster.
Stars: ✭ 791 (+1263.79%)
Mutual labels:  laravel, laravel-5-package
Indipay
The Laravel Framework Package for Indian Payment Gateways. Currently Supported Gateway: CCAvenue, PayUMoney, EBS, CitrusPay ,ZapakPay (Mobikwik), Paytm, InstaMojo , Mocker
Stars: ✭ 50 (-13.79%)
Mutual labels:  payment-gateway, laravel-5-package
Orm
A drop-in Doctrine ORM 2 implementation for Laravel 5+ and Lumen
Stars: ✭ 712 (+1127.59%)
Mutual labels:  laravel, laravel-5-package
Laravel Tools
路飞laravel工具
Stars: ✭ 24 (-58.62%)
Mutual labels:  laravel, laravel-5-package
Laravel Video Chat
Laravel Video Chat using Socket.IO and WebRTC
Stars: ✭ 646 (+1013.79%)
Mutual labels:  laravel, laravel-5-package
Improved Polymorphic Eloquent Builder
🔨 Improved Polymorphic Eloquent Builder
Stars: ✭ 12 (-79.31%)
Mutual labels:  laravel, laravel-5-package
Sudo Su
Laravel package to easily login as other users during development.
Stars: ✭ 554 (+855.17%)
Mutual labels:  laravel, laravel-5-package
Ip Location Zh
获取 IP 地址的真实地理位置
Stars: ✭ 556 (+858.62%)
Mutual labels:  laravel, laravel-5-package
Laravel User Settings
Simple and persistent boolean settings per user
Stars: ✭ 34 (-41.38%)
Mutual labels:  laravel, laravel-5-package
Fluent Facebook
A laravel 5 package for reading and writing to facebook graph object with ease in laravelish syntax
Stars: ✭ 49 (-15.52%)
Mutual labels:  laravel, laravel-5-package

Laravel Paytm Wallet

Latest Stable Version Total Downloads License Join the chat at https://gitter.im/laravel-paytm-wallet/Lobby

For Laravel 5.0 use version ^1.0.0
For Laravel 6.0 use version ^1.0.0
For Laravel 7.0 use version ^1.0.0
For Laravel 8.0 use version ^2.0.0

Introduction

Integrate paytm wallet in your laravel application easily with this package. This package uses official Paytm PHP SDK's.

License

Laravel Paytm Wallet open-sourced software licensed under the MIT license

Getting Started

To get started add the following package to your composer.json file using this command.

composer require anandsiddharth/laravel-paytm-wallet

Configuring

Note: For Laravel 5.5 and above auto-discovery takes care of below configuration.

When composer installs Laravel Paytm Wallet library successfully, register the Anand\LaravelPaytmWallet\PaytmWalletServiceProvider in your config/app.php configuration file.

'providers' => [
    // Other service providers...
    Anand\LaravelPaytmWallet\PaytmWalletServiceProvider::class,
],

Also, add the PaytmWallet facade to the aliases array in your app configuration file:

'aliases' => [
    // Other aliases
    'PaytmWallet' => Anand\LaravelPaytmWallet\Facades\PaytmWallet::class,
],

Add the paytm credentials to the .env file

PAYTM_ENVIRONMENT=local
PAYTM_MERCHANT_ID=YOUR_MERCHANT_ID_HERE
PAYTM_MERCHANT_KEY=YOUR_SECRET_KEY_HERE
PAYTM_MERCHANT_WEBSITE=YOUR_MERCHANT_WEBSITE
PAYTM_CHANNEL=YOUR_CHANNEL_HERE
PAYTM_INDUSTRY_TYPE=YOUR_INDUSTRY_TYPE_HERE

One more step to go....

On your config/services.php add the following configuration

'paytm-wallet' => [
        'env' => env('PAYTM_ENVIRONMENT'), // values : (local | production)
        'merchant_id' => env('PAYTM_MERCHANT_ID'),
        'merchant_key' => env('PAYTM_MERCHANT_KEY'),
        'merchant_website' => env('PAYTM_MERCHANT_WEBSITE'),
        'channel' => env('PAYTM_CHANNEL'),
        'industry_type' => env('PAYTM_INDUSTRY_TYPE'),
],

Note : All the credentials mentioned are provided by Paytm after signing up as merchant.

Laravel 7 Changes

Our package is comptible with Laravel 7 but same_site setting is changed in default Laravel installation, make sure you change same_site to null in config/session.php or callback won't include cookies and you will be logged out when a payment is completed

<?php

use Illuminate\Support\Str;

return [
  /...
  'same_site' => null,
];

Usage

Making a transaction

<?php

namespace App\Http\Controllers;

use PaytmWallet;

class OrderController extends Controller
{
    /**
     * Redirect the user to the Payment Gateway.
     *
     * @return Response
     */
    public function order()
    {
        $payment = PaytmWallet::with('receive');
        $payment->prepare([
          'order' => $order->id,
          'user' => $user->id,
          'mobile_number' => $user->phonenumber,
          'email' => $user->email,
          'amount' => $order->amount,
          'callback_url' => 'http://example.com/payment/status'
        ]);
        return $payment->receive();
    }

    /**
     * Obtain the payment information.
     *
     * @return Object
     */
    public function paymentCallback()
    {
        $transaction = PaytmWallet::with('receive');
        
        $response = $transaction->response(); // To get raw response as array
        //Check out response parameters sent by paytm here -> http://paywithpaytm.com/developer/paytm_api_doc?target=interpreting-response-sent-by-paytm
        
        if($transaction->isSuccessful()){
          //Transaction Successful
        }else if($transaction->isFailed()){
          //Transaction Failed
        }else if($transaction->isOpen()){
          //Transaction Open/Processing
        }
        $transaction->getResponseMessage(); //Get Response Message If Available
        //get important parameters via public methods
        $transaction->getOrderId(); // Get order id
        $transaction->getTransactionId(); // Get transaction id
    }    
}

Make sure the callback_url you have mentioned while receiving payment is post on your routes.php file, Example see below:

Route::post('/payment/status', [App\Http\Controllers\PaytmController::class,'paymentCallback'])->name('status');

Important: The callback_url must not be csrf protected Check out here to how to do that

Get transaction status/information using order id

<?php

namespace App\Http\Controllers;

use PaytmWallet;

class OrderController extends Controller
{
    /**
    * Obtain the transaction status/information.
    *
    * @return Object
    */
    public function statusCheck(){
        $status = PaytmWallet::with('status');
        $status->prepare(['order' => $order->id]);
        $status->check();
        
        $response = $status->response(); // To get raw response as array
        //Check out response parameters sent by paytm here -> http://paywithpaytm.com/developer/paytm_api_doc?target=txn-status-api-description
        
        if($status->isSuccessful()){
          //Transaction Successful
        }else if($status->isFailed()){
          //Transaction Failed
        }else if($status->isOpen()){
          //Transaction Open/Processing
        }
        $status->getResponseMessage(); //Get Response Message If Available
        //get important parameters via public methods
        $status->getOrderId(); // Get order id
        $status->getTransactionId(); // Get transaction id
    }
}

Initiating Refunds

<?php

namespace App\Http\Controllers;

use PaytmWallet;

class OrderController extends Controller
{
    /**
    * Initiate refund.
    *
    * @return Object
    */
    public function refund(){
        $refund = PaytmWallet::with('refund');
        $refund->prepare([
            'order' => $order->id,
            'reference' => "refund-order-4", // provide refund reference for your future reference (should be unique for each order)
            'amount' => 300, // refund amount 
            'transaction' => $order->transaction_id // provide paytm transaction id referring to this order 
        ]);
        $refund->initiate();
        $response = $refund->response(); // To get raw response as array
        
        if($refund->isSuccessful()){
          //Refund Successful
        }else if($refund->isFailed()){
          //Refund Failed
        }else if($refund->isOpen()){
          //Refund Open/Processing
        }else if($refund->isPending()){
          //Refund Pending
        }
    }
}

Check Refund Status

<?php

namespace App\Http\Controllers;

use PaytmWallet;

class OrderController extends Controller
{
    /**
    * Initiate refund.
    *
    * @return Object
    */
    public function refund(){
        $refundStatus = PaytmWallet::with('refund_status');
        $refundStatus->prepare([
            'order' => $order->id,
            'reference' => "refund-order-4", // provide reference number (the same which you have entered for initiating refund)
        ]);
        $refundStatus->check();
        
        $response = $refundStatus->response(); // To get raw response as array
        
        if($refundStatus->isSuccessful()){
          //Refund Successful
        }else if($refundStatus->isFailed()){
          //Refund Failed
        }else if($refundStatus->isOpen()){
          //Refund Open/Processing
        }else if($refundStatus->isPending()){
          //Refund Pending
        }
    }
}

Customizing transaction being processed page

Considering the modern app user interfaces, default "transaction being processed page" is too dull which comes with this package. If you would like to modify this, you have the option to do so. Here's how: You just need to change 1 line in you OrderController's code.

<?php

namespace App\Http\Controllers;

use PaytmWallet;

class OrderController extends Controller
{
    /**
     * Redirect the user to the Payment Gateway.
     *
     * @return Response
     */
    public function order()
    {
        $payment = PaytmWallet::with('receive');
        $payment->prepare([
          'order' => $order->id,
          'user' => $user->id,
          'mobile_number' => $user->phonenumber,
          'email' => $user->email,
          'amount' => $order->amount,
          'callback_url' => 'http://example.com/payment/status'
        ]);
        return $payment->view('your_custom_view')->receive();
    }

Here $payment->receive() is replaced with $payment->view('your_custom_view')->receive(). Replace your_custom_view with your view name which resides in your resources/views/your_custom_view.blade.php.

And in your view file make sure you have added this line of code before </body> (i.e. before closing body tag), which redirects to payment gateway.

@yield('payment_redirect')

Here's a sample custom view:

<html>
<head>
</head>
<body>
    <h1>Custom payment message</h1>
    @yield('payment_redirect')
</body>
</html>

That's all folks!

Wait you still here?

I am working on this cool project called yoheim. It's an all in one collaboration platform to manage and share ssh servers. Download now and start using it for free www.yoheim.com

yoheim log

Support on Beerpay

Beerpay Beerpay

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].