dwivedianuj9118/phonepe-laravel

Laravel PhonePe Integration- Laravel PhonePe Payment gateway Integration package

dev-main 2025-03-22 10:11 UTC

This package is auto-updated.

Last update: 2025-04-22 10:17:01 UTC


README

Package Image

PhonePe Laravel Integration (PhonePe Payment Gateway)

This Laravel package allows you to integrate PhonePe payment on your Laravel Application easily.

Contributing

Pull requests are more than welcome. I have created with clean code and developer and begginer user friendly for easy to use and implement also i have tested our code many time its better for use.

If you are using any other payment methods, please create a pull request with your solution, and I will merge it.

Installation

composer require dwivedianuj9118/phonepe-payment-gateway dev-main

Add the required variables in the .env file:

APP_ENV="local" //local or production

Publish the vendor file for configuration:

php artisan vendor:publish --provider="Dwivedianuj9118\PhonePeLaravel\PhonePeLaravelServiceProvider"

open phonepe.config file and modify details with local and production environment variable

Usage generate payment link:

Redirect the user to the payment page from your controller:

<?php

use Dwivedianuj9118\PhonePeLaravel\PhonePeLaravel;

// Your Controller Method
public function phonePePayment()
{
    $phonepe = new PhonePeLaravel();
    // amount, phone number, callback URL, unique merchant transaction id
    $response = $phonepe->doPayment(1000, '9999999999', 'http://localhost:8000/redirect-url', '1');
    if($response->success == true){
         return redirect()->away($response->url);
    }
    else
    {
        // check $response array to find message  
    }
   
}

PhonePe check status api

After Successful Payment, PhonePe will redirect to your callback URL with the transaction ID and status. You can check the payment status using the transaction ID.

<?php

use Dwivedianuj9118\PhonePeLaravel\PhonePeLaravel;
use Illuminate\Http\Request;

public function callBackResponse(Request $request)
{
    $phonepe = new PhonePeLaravel();
    $response = $phonepe->getPaymentStatus($request->all());
    if($response->success == true){
        // Payment Success
        // use $response array for save detail or update
    }
    else
    {
        // Payment Failed           
    }
}

PhonePe refund api

    use Dwivedianuj9118\PhonePeLaravel\PhonePeLaravel;
    use Illuminate\Http\Request;
    
    public function refundPayment(Request $request)
    {
        $phonepe = new PhonePeLaravel();
        $response = $phonepe->refundPayment($request->all());
        if($response->success == true){
            // Payment refund
            //$response->state , $response->message, $response->status,  $response->state
            // use above details in array of refund method
        }
        else
        {
            // Payment Failed
            //  display $response->message
        }
    }

Official Documentation

Documentation can be found on my website.

License

MIT

Author

Support

For support, email dwivedianuj9118[at]gmail[dot]com.