PHPackages                             cixware/esewa-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. [API Development](/categories/api)
4. /
5. cixware/esewa-php-sdk

Abandoned → [remotemerge/esewa-php-sdk](/?search=remotemerge%2Fesewa-php-sdk)Library[API Development](/categories/api)

cixware/esewa-php-sdk
=====================

eSewa payment gateway integration in PHP.

3.1.0(1y ago)929.4k5[1 PRs](https://github.com/remotemerge/esewa-php-sdk/pulls)MITPHPPHP &gt;=8.1CI passing

Since Apr 7Pushed 1mo agoCompare

[ Source](https://github.com/remotemerge/esewa-php-sdk)[ Packagist](https://packagist.org/packages/cixware/esewa-php-sdk)[ Docs](https://github.com/remotemerge/esewa-php-sdk)[ RSS](/packages/cixware-esewa-php-sdk/feed)WikiDiscussions main Synced today

READMEChangelog (8)Dependencies (3)Versions (7)Used By (0)

**eSewa PHP SDK: Payment Gateway Integration for PHP**
======================================================

[](#esewa-php-sdk-payment-gateway-integration-for-php)

[![PHP Version](https://camo.githubusercontent.com/7e66e7633fd6f26a4b36879dc7b56d6b900ac1d8be66fdd6813ffd74a51c74c3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f72656d6f74656d657267652f65736577612d7068702d73646b3f6c6f676f3d706870267374796c653d666c6174)](https://packagist.org/packages/remotemerge/esewa-php-sdk)[![Tests](https://camo.githubusercontent.com/492907983c0b575f4399a316ed8830c813f8e082e542e39419a42c9b5fb4374a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f72656d6f74656d657267652f65736577612d7068702d73646b2f746573742e796d6c3f7374796c653d666c6174266c6f676f3d636f756e746572737472696b65266c6162656c3d74657374)](https://github.com/remotemerge/esewa-php-sdk/actions)[![Build](https://camo.githubusercontent.com/c0676d82736c50961c5bd52d87032f12510d6dbb18462e664423575a92589898/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f72656d6f74656d657267652f65736577612d7068702d73646b2f696e7374616c6c2e796d6c3f7374796c653d666c6174266c6f676f3d676974687562)](https://github.com/remotemerge/esewa-php-sdk/actions)[![Sonar Quality](https://camo.githubusercontent.com/0a4474553bfb07ce009b0fef5813625087706670cfa46a965648ac9640e4297a/68747470733a2f2f696d672e736869656c64732e696f2f736f6e61722f7175616c6974795f676174652f65736577612d7068702d73646b2f6d61696e3f7365727665723d6874747073253341253246253246736f6e6172636c6f75642e696f267374796c653d666c6174266c6f676f3d736f6e617271756265636c6f7564266c6f676f436f6c6f723d313236454433266c6162656c3d7175616c697479)](https://sonarcloud.io/summary/overall?id=esewa-php-sdk&branch=main)[![Sonar Coverage](https://camo.githubusercontent.com/07db3d04c0c96bea9d5344d39b3f5d9592524936163851418c345d551cec2a54/68747470733a2f2f696d672e736869656c64732e696f2f736f6e61722f636f7665726167652f65736577612d7068702d73646b2f6d61696e3f7365727665723d6874747073253341253246253246736f6e6172636c6f75642e696f267374796c653d666c6174266c6f676f3d736f6e617271756265736572766572266c6f676f436f6c6f723d313236454433)](https://sonarcloud.io/summary/overall?id=esewa-php-sdk&branch=main)[![Downloads](https://camo.githubusercontent.com/7afe7018f646fac515cd45caa1598cf36862f0211c91d92dd0dc093a16883628/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f72656d6f74656d657267652f65736577612d7068702d73646b2e7376673f7374796c653d666c6174266c6162656c3d646f776e6c6f616473)](https://packagist.org/packages/remotemerge/esewa-php-sdk)[![License](https://camo.githubusercontent.com/fb37ced55e9d862c26798372e0c19d5a61499d2ece1b71ad9aaf7dfe1e94cf69/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f72656d6f74656d657267652f65736577612d7068702d73646b)](https://github.com/remotemerge/esewa-php-sdk?tab=MIT-1-ov-file)

A production-ready PHP SDK for integrating [eSewa](https://esewa.com.np) payment gateway into any PHP application. The SDK implements the eSewa ePay v2 API with HMAC-SHA256 signature verification, full sandbox support, and a clean developer API. It works with any PHP framework or without one and handles the entire payment lifecycle from initiation through cryptographic verification.

> For official eSewa API reference, see the [eSewa Developer Portal](https://developer.esewa.com.np).

**Table of Contents**
---------------------

[](#table-of-contents)

\#TitleDescription1[Why eSewa PHP SDK?](#why-esewa-php-sdk)What makes this SDK a good choice for eSewa payment integration.2[Key Features](#key-features)Signing, verification, status checks, validation, and extensibility.3[Compatibility](#compatibility)PHP version, required extensions, and supported frameworks.4[Get Started in Minutes](#get-started-in-minutes)Install via Composer and verify the setup with a quick test.5[Configuration](#configuration)Sandbox and production environment setup with all available options.6[Basic Usage](#basic-usage)Initiate payments, verify responses, and check transaction status.7[Advanced Usage](#advanced-usage)Manual signature verification, custom HTTP clients, and helper methods.8[Error Handling](#error-handling)Exception categories, messages, and recommended handling patterns.9[Security](#security)How HMAC-SHA256 signing works and best practices for production.10[Try with Docker](#try-with-docker)Run the included demo store locally in a Docker container.11[Getting Help](#getting-help)Where to report bugs, request features, and find support.12[Contributing](#contributing)Coding standards, testing, and pull request guidelines.**Why eSewa PHP SDK?**
----------------------

[](#why-esewa-php-sdk)

eSewa PHP SDK is a focused, well-tested library that handles the full eSewa ePay v2 payment flow in PHP. It takes care of HMAC-SHA256 signature generation, response verification with timing-safe comparison, and transaction status checks so that developers can focus on their application logic instead of cryptographic plumbing. The SDK runs on PHP 8.1+, installs through Composer with PSR-4 autoloading, and works equally well in Laravel, Symfony, CodeIgniter, or plain PHP without any framework dependency.

---

**Key Features**
----------------

[](#key-features)

✅ **ePay v2 Payment Initiation**Creates signed payment forms with auto-calculated totals, ready to submit to the eSewa checkout page.

✅ **HMAC-SHA256 Signature Generation**Automatically signs all outgoing payment requests using your secret key, following the eSewa ePay v2 specification.

✅ **Cryptographic Response Verification**Decodes base64-encoded eSewa responses, reconstructs the signed string, and verifies the signature using timing-safe `hash_equals()`.

✅ **Transaction Status API**Provides a server-to-server method for querying payment status directly from the eSewa API, independent of the redirect flow.

✅ **Sandbox Environment**Full sandbox support with eSewa-provided test credentials for development and testing without real transactions.

✅ **Input Validation**Validates all payment parameters, configuration options, and API responses with clear, actionable error messages.

✅ **Custom HTTP Client**Accepts an injectable HTTP client via `HttpClientInterface` for proxy configuration, custom timeouts, or request logging.

---

**Compatibility**
-----------------

[](#compatibility)

RequirementVersionNotesPHP&gt;= 8.1Requires `ext-curl` and `ext-json`Composer&gt;= 2.0For package installation and autoloadingFrameworksAnyLaravel, Symfony, CodeIgniter, or plain PHP---

**Get Started in Minutes**
--------------------------

[](#get-started-in-minutes)

Adding eSewa PHP SDK to a project is quick. The library requires **PHP 8.1** or higher.

### **Installation**

[](#installation)

Install the library via Composer:

```
composer require remotemerge/esewa-php-sdk
```

Composer handles autoloading automatically. No manual file includes or bootstrapping required.

---

**Configuration**
-----------------

[](#configuration)

All SDK features are accessed through `EsewaFactory::createEpay()`. This factory method validates the provided configuration and returns a fully wired `EpayInterface` instance ready for use.

### **Sandbox (Test) Environment**

[](#sandbox-test-environment)

eSewa provides fixed sandbox credentials for development and testing. No real money moves in `test` mode, so these credentials can be used freely during development.

```
use RemoteMerge\Esewa\EsewaFactory;

$epay = EsewaFactory::createEpay([
    'environment'  => 'test',
    'product_code' => 'EPAYTEST',
    'secret_key'   => '8gBm/:&EnhH.1/q',
    'success_url'  => 'https://example.com/success.php',
    'failure_url'  => 'https://example.com/failed.php',
]);
```

> **Sandbox credentials:** eSewa ID `9806800001` – `9806800005`, password `Nepal@123`, MPIN `1122`, OTP `123456`. Full test credentials at [eSewa Developer Portal](https://developer.esewa.com.np).

### **Production Environment**

[](#production-environment)

For production, retrieve the live `product_code` and `secret_key` from the [eSewa Merchant Dashboard](https://merchant.esewa.com.np) and swap them in. Everything else stays the same.

```
use RemoteMerge\Esewa\EsewaFactory;

$epay = EsewaFactory::createEpay([
    'environment'  => 'production',
    'product_code' => 'YOUR_PRODUCT_CODE',
    'secret_key'   => 'YOUR_SECRET_KEY',
    'success_url'  => 'https://example.com/success.php',
    'failure_url'  => 'https://example.com/failed.php',
]);
```

### **Configuration Reference**

[](#configuration-reference)

OptionRequiredDefaultTypeDescription`environment`No`test``string``test` for sandbox, `production` for live`product_code`Yes-`string`Merchant product code assigned by eSewa`secret_key`Yes-`string`Secret key used to generate HMAC-SHA256 signatures`success_url`Yes-`string`Redirect URL on successful payment`failure_url`Yes-`string`Redirect URL on failed or cancelled payment**Basic Usage**
---------------

[](#basic-usage)

The eSewa ePay v2 payment flow has three steps: **initiate → redirect → verify**. The SDK handles cryptographic signing and verification at each step, so the integration code stays simple.

### **Initiate a Payment**

[](#initiate-a-payment)

Call `createPayment()` with order details. The SDK computes the `total_amount` and generates the HMAC-SHA256 signature automatically. The `transaction_uuid` should be a unique identifier per order. UUID v4 is recommended.

```
use Ramsey\Uuid\Uuid;
use RemoteMerge\Esewa\EsewaFactory;
use RemoteMerge\Esewa\Exceptions\EsewaException;

$epay = EsewaFactory::createEpay([
    'environment'  => 'test',
    'product_code' => 'EPAYTEST',
    'secret_key'   => '8gBm/:&EnhH.1/q',
    'success_url'  => 'https://example.com/success.php',
    'failure_url'  => 'https://example.com/failed.php',
]);

try {
    $paymentData = $epay->createPayment([
        'amount'                   => 500.00,
        'tax_amount'               => 65.00,
        'product_service_charge'   => 0,
        'product_delivery_charge'  => 100,
        'transaction_uuid'         => Uuid::uuid4()->toString(),
    ]);
} catch (EsewaException $e) {
    echo $e->getMessage();
}
```

**Payment Parameters:**

FieldRequiredTypeDescription`amount`Yes`float`Base product or service price`transaction_uuid`Yes`string`Unique order identifier (alphanumeric + hyphens)`tax_amount`No`float`VAT or tax on the order (default: `0`)`product_service_charge`No`float`Service fee, if applicable (default: `0`)`product_delivery_charge`No`float`Delivery/shipping fee, if applicable (default: `0`)The `total_amount` is calculated automatically as `amount + tax_amount + product_service_charge + product_delivery_charge`.

### **Render the Payment Form**

[](#render-the-payment-form)

Render the signed fields as a hidden HTML form and submit it to `getFormActionUrl()`. eSewa handles the checkout UI on their end and redirects users back to the configured URLs when the payment completes or fails.

```
