PHPackages                             esanj/payment-client - 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. esanj/payment-client

ActiveLibrary

esanj/payment-client
====================

Laravel client package for the Esanj Payment Microservice

v0.0.1(yesterday)01↑2900%MITPHP ^8.2|^8.3|^8.4

Since Jul 19Compare

[ Source](https://github.com/eSanjDev/ms-package-payment)[ Packagist](https://packagist.org/packages/esanj/payment-client)[ RSS](/packages/esanj-payment-client/feed)WikiDiscussions Synced today

READMEChangelogDependencies (6)Versions (2)Used By (0)

Esanj Payment Client
====================

[](#esanj-payment-client)

A Laravel client package for the **Esanj Payment Microservice**. It authenticates with client credentials through the [`esanj/auth-bridge`](../ms-package-accounting-bridge) package, then lets you list merchant gateways and create, inspect and manage transactions — with typed DTOs, typed responses and structured error handling.

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

[](#installation)

```
composer update esanj/payment-client
```

The service provider and the `Payment` facade are auto-discovered.

Configuration
-------------

[](#configuration)

Publish the config (optional — it is merged automatically):

```
php artisan vendor:publish --tag=payment-config
```

Set the environment variables:

```
# Payment microservice
PAYMENT_SERVICE_URL=https://payments.esanj.io
PAYMENT_CLIENT_ID=your-merchant-client-id
PAYMENT_CLIENT_SECRET=your-merchant-client-secret

# Optional
PAYMENT_SCOPE=*
PAYMENT_TIMEOUT=30
PAYMENT_RETRY_ATTEMPTS=3
PAYMENT_RETRY_SLEEP_MS=1000
PAYMENT_LOG_CHANNEL=

# Required by esanj/auth-bridge — the OAuth server that issues the token
ACCOUNTING_BRIDGE_BASE_URL=https://accounting.esanj.io
```

> The access token is issued by the OAuth server configured for `esanj/auth-bridge`(`ACCOUNTING_BRIDGE_BASE_URL`) using the merchant's `PAYMENT_CLIENT_ID` / `PAYMENT_CLIENT_SECRET`, then sent as a `Bearer` token to the Payment service. Tokens are cached and refreshed automatically by auth-bridge.

Usage
-----

[](#usage)

### Dependency injection (recommended)

[](#dependency-injection-recommended)

```
use Esanj\PaymentClient\Contracts\PaymentClientInterface;

class CheckoutController
{
    public function __construct(private PaymentClientInterface $payment) {}
}
```

### Facade

[](#facade)

```
use Esanj\PaymentClient\Facades\Payment;

$gateways = Payment::listGateways();
```

### Create a transaction

[](#create-a-transaction)

```
use Esanj\PaymentClient\Facades\Payment;
use Esanj\PaymentClient\DTOs\InitTransactionData;
use Esanj\PaymentClient\DTOs\CartData;
use Esanj\PaymentClient\DTOs\CartItemData;

$result = Payment::initTransaction(new InitTransactionData(
    amount: 9_500_000,
    currency: 'IRR',
    gatewayKey: 'zibal-1',            // null → merchant default gateway (with failover)
    mobile: '09121234567',
    email: 'buyer@example.com',
    userId: 42,
    returnUrl: 'https://shop.example.com/payment/callback',
    description: 'Order #1234',
    discountAmount: 50_000,
    externalSourceAmount: 0,
    cartList: [
        new CartData(
            cartId: 581,
            items: [new CartItemData(id: 193, name: 'Laptop', category: 'Electronics', amount: 9_000_000, count: 1)],
            totalAmount: 9_000_000,
        ),
    ],
));

// Redirect the customer to the gateway:
return redirect()->away($result->paymentPageUrl);   // $result->paymentToken holds the code
```

### Inspect &amp; manage a transaction

[](#inspect--manage-a-transaction)

```
$status = Payment::status($code);       // TransactionStatusResource
$status->status->isPaid();              // typed TransactionStatus enum

Payment::verify($code);   // paid   → verified
Payment::settle($code);   // verified → settled
Payment::revert($code);   // verified → reverted (refund)
Payment::cancel($code);   // created/pending/settled → canceled
```

Error Handling
--------------

[](#error-handling)

Every failure throws a subclass of `Esanj\PaymentClient\Exceptions\PaymentException`:

ExceptionWhen`PaymentAuthenticationException`Client credentials missing/invalid; the OAuth server rejected the token request.`PaymentApiException`The Payment service returned an error response. Carries `statusCode`, `responseBody`, `getErrors()`.```
use Esanj\PaymentClient\Exceptions\PaymentApiException;
use Esanj\PaymentClient\Exceptions\PaymentAuthenticationException;

try {
    $result = Payment::verify($code);
} catch (PaymentApiException $e) {
    if ($e->isInvalidStatus())      { /* transaction not in a verifiable state */ }
    elseif ($e->isNotFound())       { /* unknown code */ }
    elseif ($e->isValidationError()){ $errors = $e->getErrors(); }
    else                            { report($e); }
} catch (PaymentAuthenticationException $e) {
    // credentials / OAuth problem
}
```

Server (5xx), connection and rejected-token (401/403) failures are retried automatically according to the `retry` config; a rejected token is invalidated and re-fetched before the retry.

API surface
-----------

[](#api-surface)

MethodEndpoint`listGateways()``GET  /api/v1/merchant/gateways``initTransaction(InitTransactionData)``POST /api/v1/payment/init-transaction``status(string $code)``POST /api/v1/payment/status``verify(string $code)``POST /api/v1/payment/verify``settle(string $code)``POST /api/v1/payment/settle``revert(string $code)``POST /api/v1/payment/revert``cancel(string $code)``POST /api/v1/payment/cancel`See [`docs/GUIDE.md`](docs/GUIDE.md) for a full walkthrough.

License
-------

[](#license)

MIT

###  Health Score

38

—

LowBetter than 83% of packages

Maintenance100

Actively maintained with recent releases

Popularity2

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity40

Maturing project, gaining track record

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

1d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/c908dfdf092a072c4bc678b161b053e20d00f90e9e9ba2c18ecddef6b848f1a4?d=identicon)[esanj](/maintainers/esanj)

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/esanj-payment-client/health.svg)

```
[![Health](https://phpackages.com/badges/esanj-payment-client/health.svg)](https://phpackages.com/packages/esanj-payment-client)
```

###  Alternatives

[craftcms/cms

Craft CMS

3.6k3.6M3.2k](/packages/craftcms-cms)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9762.4M133](/packages/roots-acorn)[illuminate/http

The Illuminate Http package.

11937.9M7.4k](/packages/illuminate-http)[spatie/laravel-export

Create a static site bundle from a Laravel app

674146.0k6](/packages/spatie-laravel-export)[eslazarev/wildberries-sdk

Wildberries OpenAPI clients (generated).

293.1k](/packages/eslazarev-wildberries-sdk)[fleetbase/core-api

Core Framework and Resources for Fleetbase API

1235.9k21](/packages/fleetbase-core-api)

PHPackages © 2026

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