PHPackages                             pratiksahu1535/cashfree-payment - 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. pratiksahu1535/cashfree-payment

ActiveLibrary[Payment Processing](/categories/payments)

pratiksahu1535/cashfree-payment
===============================

A lightweight PHP SDK and Laravel package for the Cashfree Payment Gateway (PG v3 API).

00PHPCI failing

Since Jun 23Pushed 1mo agoCompare

[ Source](https://github.com/Pratiksahu2003/cashfree-sdk)[ Packagist](https://packagist.org/packages/pratiksahu1535/cashfree-payment)[ RSS](/packages/pratiksahu1535-cashfree-payment/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Cashfree Payment Gateway — PHP &amp; Laravel SDK
================================================

[](#cashfree-payment-gateway--php--laravel-sdk)

[![Tests](https://github.com/Pratiksahu2003/cashfree-sdk/actions/workflows/tests.yml/badge.svg)](https://github.com/Pratiksahu2003/cashfree-sdk/actions/workflows/tests.yml)[![License: MIT](https://camo.githubusercontent.com/08cef40a9105b6526ca22088bc514fbfdbc9aac1ddbf8d4e6c750e3a88a44dca/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d626c75652e737667)](LICENSE)[![PHP Version](https://camo.githubusercontent.com/fc4497a603befbbda4baa8c5111aec157b2e896f98b83ada63fb6949a353d57a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253545382e302d3737374242342e737667)](https://php.net)

> **Repository:** [github.com/Pratiksahu2003/cashfree-sdk](https://github.com/Pratiksahu2003/cashfree-sdk)

A production-ready PHP SDK and Laravel package for the **Cashfree Payment Gateway (PG v3 API)**.

Create orders, fetch payment status, process refunds, verify webhooks with HMAC-SHA256 signatures, and optionally persist transactions in Laravel using the included Eloquent model and migration.

---

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

[](#table-of-contents)

- [Features](#features)
- [Requirements](#requirements)
- [Installation](#installation)
- [Configuration](#configuration)
- [Usage](#usage)
    - [Laravel (Facade)](#laravel-facade)
    - [Plain PHP (No Framework)](#plain-php-no-framework)
    - [Webhook Verification](#webhook-verification)
    - [Database Model (Laravel)](#database-model-laravel)
- [Complete Laravel Example](#complete-laravel-example)
- [Error Handling](#error-handling)
- [Logging](#logging)
- [API Reference](#api-reference)
- [Testing](#testing)
- [Troubleshooting](#troubleshooting)
- [License](#license)

---

Features
--------

[](#features)

FeatureDescription**PG v3 API**Orders, order status, refunds**Webhook security**HMAC-SHA256 signature verification**Laravel integration**Auto-discovered service provider, facade, config, migrations**Plain PHP support**Use `CashfreeClient` directly without Laravel**Safe logging**Request/response logging with secret key redaction**Automatic retries**Configurable retries for network and transient API errors**Eloquent model**Optional `cashfree_payments` table for transaction records---

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

[](#requirements)

- PHP **8.0+**
- [Composer](https://getcomposer.org/)
- Cashfree merchant account ([Sign up](https://www.cashfree.com/))
- **Laravel 10, 11, or 12** (only if using the Laravel integration)

---

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

[](#installation)

Install in your Laravel project with one command:

```
composer require pratiksahu2003/cashfree-sdk
```

When Composer asks to trust the plugin, choose **yes** (or add this once to your Laravel `composer.json`):

```
"config": {
    "allow-plugins": {
        "pratiksahu2003/cashfree-sdk": true
    }
}
```

### What happens automatically

[](#what-happens-automatically)

After `composer require`, the package runs setup for you — no manual steps:

StepAutomatic actionService provider &amp; facadeLaravel auto-discoveryConfigPublished to `config/cashfree.php`Environment variablesAppended to `.env` and `.env.example`MigrationsLoaded from the package (run `php artisan migrate` when ready)Cache`package:discover` and `config:clear` run for youYou only need to fill in your Cashfree credentials in `.env`:

```
CASHFREE_APP_ID=your_app_id
CASHFREE_SECRET_KEY=your_secret_key
```

---

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

[](#configuration)

Config and `.env` keys are created automatically when you install the package. Customize `config/cashfree.php` if needed.

### Environment Variables

[](#environment-variables)

```
# Required — get from Cashfree Merchant Dashboard
CASHFREE_APP_ID=your_app_id
CASHFREE_SECRET_KEY=your_secret_key

# sandbox (testing) or production (live payments)
CASHFREE_ENV=sandbox

# Optional
CASHFREE_API_VERSION=2023-08-01
CASHFREE_LOGGING_ENABLED=true
CASHFREE_LOG_CHANNEL=cashfree
CASHFREE_RETRY_ATTEMPTS=3
CASHFREE_RETRY_BACKOFF_MS=500
```

VariableRequiredDefaultDescription`CASHFREE_APP_ID`Yes—Cashfree Client ID`CASHFREE_SECRET_KEY`Yes—Cashfree Client Secret`CASHFREE_ENV`No`sandbox``sandbox` or `production``CASHFREE_API_VERSION`No`2023-08-01`Cashfree API version header`CASHFREE_LOGGING_ENABLED`No`true`Enable API and webhook logs`CASHFREE_LOG_CHANNEL`NoLaravel defaultDedicated log channel name`CASHFREE_RETRY_ATTEMPTS`No`3`Retry count for transient failures`CASHFREE_RETRY_BACKOFF_MS`No`500`Backoff delay in milliseconds### Custom Log Channel (Optional)

[](#custom-log-channel-optional)

Add to `config/logging.php`:

```
'channels' => [
    'cashfree' => [
        'driver' => 'single',
        'path' => storage_path('logs/cashfree.log'),
        'level' => 'debug',
    ],
],
```

### Database Migration (Optional)

[](#database-migration-optional)

Run the included migration to create the `cashfree_payments` table:

```
php artisan migrate
```

To customize the schema, publish migrations first:

```
php artisan vendor:publish --tag=cashfree-migrations
php artisan migrate
```

---

Usage
-----

[](#usage)

### Laravel (Facade)

[](#laravel-facade)

#### Create an Order

[](#create-an-order)

```
use CashfreePayment\Facades\Cashfree;

$response = Cashfree::createOrder([
    'order_id' => 'order_' . uniqid(),
    'order_amount' => 150.00,
    'order_currency' => 'INR',
    'customer_details' => [
        'customer_id' => 'user_992',
        'customer_phone' => '9999999999',
        'customer_email' => 'customer@example.com',
    ],
    'order_meta' => [
        'return_url' => 'https://yoursite.com/payment/callback?order_id={order_id}',
        'notify_url' => 'https://yoursite.com/payment/webhook',
    ],
]);

$paymentSessionId = $response['payment_session_id'];
$paymentLink = $response['payment_link'];
```

#### Get Order Status

[](#get-order-status)

```
$order = Cashfree::getOrder('order_abc123');
$status = $order['order_status']; // PAID, ACTIVE, EXPIRED, etc.
```

#### Create a Refund

[](#create-a-refund)

```
$refund = Cashfree::createRefund('order_abc123', [
    'refund_amount' => 150.00,
    'refund_id' => 'refund_' . uniqid(),
    'refund_note' => 'Customer requested refund',
]);
```

#### List Refunds for an Order

[](#list-refunds-for-an-order)

```
$refunds = Cashfree::getRefunds('order_abc123');
```

#### Dependency Injection

[](#dependency-injection)

```
use CashfreePayment\CashfreeClient;

public function __construct(protected CashfreeClient $cashfree) {}

public function pay()
{
    return $this->cashfree->createOrder([/* ... */]);
}
```

---

### Plain PHP (No Framework)

[](#plain-php-no-framework)

Use `CashfreeClient` directly in any PHP project:

```
