PHPackages                             phonepe/phonepe-pg-php-sdk - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Payment Processing](/categories/payments)
4. /
5. phonepe/phonepe-pg-php-sdk

ActiveLibrary[Payment Processing](/categories/payments)

phonepe/phonepe-pg-php-sdk
==========================

This SDK helps merchants integrate PhonePe Payments Gateway with their PHP applications.

2.0.0(7mo ago)0218↓31.3%1[1 PRs](https://github.com/PhonePe/phonepe-pg-sdk-php/pulls)MITPHPPHP &gt;=8.2.0

Since Aug 29Pushed 1mo ago7 watchersCompare

[ Source](https://github.com/PhonePe/phonepe-pg-sdk-php)[ Packagist](https://packagist.org/packages/phonepe/phonepe-pg-php-sdk)[ Docs](https://developer.phonepe.com)[ RSS](/packages/phonepe-phonepe-pg-php-sdk/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (5)Versions (6)Used By (0)

PhonePe Payment Gateway SDK for PHP
===================================

[](#phonepe-payment-gateway-sdk-for-php)

The PhonePe Payment Gateway SDK for PHP provides a convenient way to integrate with PhonePe's payment gateway APIs in your PHP applications. This SDK simplifies the process of initiating payments, checking transaction statuses, and handling callbacks.

Requirements
------------

[](#requirements)

- PHP 8.2 or later
- [Composer](https://getcomposer.org/) for dependency management

Installation
------------

[](#installation)

### Mandatory Setup

[](#mandatory-setup)

Before proceeding with the installation steps below, you must add the following repository details to your project’s root composer.json file. This step is required to fetch the PhonePe PHP SDK package.

```
{
 "repositories": [
      {
        "type": "package",
        "url": "./vendor/phonepe/pg-sdk-php/",
        "package": {
          "name": "phonepe/pg-php-sdk-v2",
          "version": "2.0.0",
          "dist": {
            "url": "https://phonepe.mycloudrepo.io/public/repositories/phonepe-pg-php-sdk/v2-sdk.zip",
            "type": "zip"
          },
          "autoload": {
            "classmap": ["/"]
          }
        }
      }
    ],

    "require": {
        "phonepe/pg-php-sdk-v2": "^2.0",
        "vlucas/phpdotenv": "^5.6",
        "netresearch/jsonmapper": "^4.4"
    }
}
```

You can add the PhonePe PG SDK for PHP as a dependency to your project using Composer.

```
composer install
```

Initialization
--------------

[](#initialization)

To start using the SDK, you need to initialize the `StandardCheckoutClient`. You'll need your `clientId`, `clientSecret`, and `clientVersion` from PhonePe.

```
use PhonePe\payments\v2\standardCheckout\StandardCheckoutClient;
use PhonePe\Env;

$clientId = "YOUR_CLIENT_ID";
$clientSecret = "YOUR_CLIENT_SECRET";
$clientVersion = "YOUR_CLIENT_VERSION";
$env = Env::UAT; // Or Env::PRODUCTION

$phonepeClient = StandardCheckoutClient::getInstance($clientId, $clientVersion, $clientSecret, $env);
```

Standard Checkout
-----------------

[](#standard-checkout)

The Standard Checkout flow allows you to redirect your users to the PhonePe payment page to complete their transactions.

### 1. Initiate a Payment

[](#1-initiate-a-payment)

First, create a `StandardCheckoutPayRequest` with a unique order ID, the amount, and a redirect URL.

```
use PhonePe\payments\v2\models\request\builders\StandardCheckoutPayRequestBuilder;

$merchantOrderId = "ORDER-" . uniqid();
$amount = 1000; // Amount in paise (e.g., 1000 for ₹10.00)
$redirectUrl = "https://your-website.com/payment-redirect";
$message = "Payment for order " . $merchantOrderId;

$payRequest = (new StandardCheckoutPayRequestBuilder())
    ->merchantOrderId($merchantOrderId)
    ->amount($amount)
    ->redirectUrl($redirectUrl)
    ->message($message)
    ->build();
```

### 2. Make the `pay` API Call

[](#2-make-the-pay-api-call)

Next, call the `pay` method with the request object to get a payment response.

```
try {
    $payResponse = $phonepeClient->pay($payRequest);
    $redirectUrl = $payResponse->getRedirectUrl();
    // Redirect the user to the $redirectUrl to complete the payment
    header("Location: " . $redirectUrl);
    exit();
} catch (PhonePe\common\exceptions\PhonePeException $e) {
    // Handle exceptions
    echo $e->getMessage();
}
```

The `pay` method will return a `StandardCheckoutPayResponse` containing a `redirectUrl`. You should redirect your user to this URL to complete the payment.

Check Order Status
------------------

[](#check-order-status)

You can check the status of a transaction using the `getOrderStatus` method with the merchant's order ID.

```
try {
    $statusResponse = $phonepeClient->getOrderStatus($merchantOrderId);
    // Process the status response
    echo "Payment state: " . $statusResponse->getState();
} catch (PhonePe\common\exceptions\PhonePeException $e) {
    // Handle exceptions
    echo $e->getMessage();
}
```

Handle Callbacks
----------------

[](#handle-callbacks)

PhonePe will send server-to-server callbacks to your specified callback URL to notify you of the payment status. The SDK provides a method to verify the authenticity of these callbacks.

```
// Get headers and body from the callback request
$headers = [];
foreach ($_SERVER as $key => $value) {
    if (strpos($key, 'HTTP_') === 0) {
        $headerKey = str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($key, 5)))));
        $headers[$headerKey] = $value;
    }
}
$requestBody = file_get_contents('php://input');
$username = "YOUR_CALLBACK_USERNAME";
$password = "YOUR_CALLBACK_PASSWORD";

try {
    $callbackResponse = $phonepeClient->verifyCallbackResponse($headers, $requestBody, $username, $password);
    // Process the callback response
    echo "Callback state: " . $callbackResponse->getState();
} catch (PhonePe\common\exceptions\PhonePeException $e) {
    // Handle exceptions
    echo $e->getMessage();
}
```

**Note:** The `getallheaders()` function is not available in all PHP environments (e.g., Nginx). The example above provides a more reliable way to get the headers. In the `$headers` array, the `Authorization` header key will be available as `Authorization`.

Refunds
-------

[](#refunds)

You can initiate a refund for a transaction using the `refund` method.

### 1. Initiate a Refund

[](#1-initiate-a-refund)

```
use PhonePe\payments\v2\models\request\builders\StandardCheckoutRefundRequestBuilder;

$merchantRefundId = "REFUND-" . uniqid();
$originalMerchantOrderId = "ORDER-12345"; // The original order ID
$amount = 500; // Amount to refund in paise

$refundRequest = (new StandardCheckoutRefundRequestBuilder())
    ->merchantRefundId($merchantRefundId)
    ->originalMerchantOrderId($originalMerchantOrderId)
    ->amount($amount)
    ->build();

try {
    $refundResponse = $phonepeClient->refund($refundRequest);
    // Process the refund response
    echo "Refund state: " . $refundResponse->getState();
} catch (PhonePe\common\exceptions\PhonePeException $e) {
    // Handle exceptions
    echo $e->getMessage();
}
```

### 2. Check Refund Status

[](#2-check-refund-status)

You can check the status of a refund using the `getRefundStatus` method.

```
try {
    $refundStatusResponse = $phonepeClient->getRefundStatus($merchantRefundId);
    // Process the refund status response
    echo "Refund status: " . $refundStatusResponse->getState();
} catch (PhonePe\common\exceptions\PhonePeException $e) {
    // Handle exceptions
    echo $e->getMessage();
}
```

Documentation
-------------

[](#documentation)

For detailed API documentation, advanced features, and integration options:

- [PHP SDK Documentation](https://developer.phonepe.com/payment-gateway/backend-sdk/php-be-sdk/introduction)
- [PhonePe Developer Portal](https://developer.phonepe.com/)

Contributing
------------

[](#contributing)

Contributions to the PhonePe PG SDK for PHP are welcome. Here's how you can contribute:

1. Fork the repository
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
3. Commit your changes (`git commit -m 'Add some amazing feature'`)
4. Push to the branch (`git push origin feature/amazing-feature`)
5. Open a Pull Request

Please ensure your code follows the project's coding standards and includes appropriate tests.

License
-------

[](#license)

This project is licensed under the Apache License 2.0 - see the [LICENSE](LICENSE) file for details.

```
Copyright 2025 PhonePe Private Limited

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

```

###  Health Score

41

—

FairBetter than 89% of packages

Maintenance77

Regular maintenance activity

Popularity15

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 50% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

239d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3adb794e5aace61e483243962074ce8a9af88a2456ed7027930440dfdd14d926?d=identicon)[merchant-pg-plugin@phonepe.com](/maintainers/merchant-pg-plugin@phonepe.com)

---

Top Contributors

[![282000ypk](https://avatars.githubusercontent.com/u/66812707?v=4)](https://github.com/282000ypk "282000ypk (2 commits)")[![MISBMS](https://avatars.githubusercontent.com/u/151795?v=4)](https://github.com/MISBMS "MISBMS (1 commits)")[![tshan10](https://avatars.githubusercontent.com/u/29731061?v=4)](https://github.com/tshan10 "tshan10 (1 commits)")

---

Tags

payment gatewayPhonePe

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/phonepe-phonepe-pg-php-sdk/health.svg)

```
[![Health](https://phpackages.com/badges/phonepe-phonepe-pg-php-sdk/health.svg)](https://phpackages.com/packages/phonepe-phonepe-pg-php-sdk)
```

###  Alternatives

[shetabit/payment

Laravel Payment Gateway Integration Package

944330.1k5](/packages/shetabit-payment)[shetabit/multipay

PHP Payment Gateway Integration Package

291348.2k3](/packages/shetabit-multipay)[cybersource/rest-client-php

Client SDK for CyberSource REST APIs

39881.3k6](/packages/cybersource-rest-client-php)[jomweb/billplz

PHP Agnostic library for working with BillPlz API

77199.0k3](/packages/jomweb-billplz)[luigel/laravel-paymongo

A laravel wrapper for Paymongo API

7956.2k1](/packages/luigel-laravel-paymongo)[hexters/coinpayment

CoinPayment is a Laravel module for handling transactions from CoinPayment like a create transaction, history transaction, etc.

7058.0k](/packages/hexters-coinpayment)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
