Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
5942595
feat: add ccavenue payment integration
dhrumilpatel30 Apr 17, 2025
9ad645f
feat: add ivyliving erp support in payments for ccavenue
dhrumilpatel30 Apr 17, 2025
df4036c
CCAvenue - Use ignore_permissions=True to bypass permission checks
domjv Apr 18, 2025
5c647a4
Merge branch 'dhrumil/ccavenue-integreation-base' into dhrumil/ccaven…
dhrumilpatel30 Apr 20, 2025
5119580
fix: add required fields
dhrumilpatel30 Apr 21, 2025
7246aec
Change design of checkout page
dhrumilpatel30 Apr 21, 2025
93b984e
Add: billing details from customer if present
dhrumilpatel30 Apr 21, 2025
6946460
Add: doctype for charges
dhrumilpatel30 Apr 23, 2025
52a9ca0
Add: charges markup in integration request
dhrumilpatel30 Apr 23, 2025
e1d9f55
Add: more precision, rounding off with ceil logic
dhrumilpatel30 Apr 25, 2025
7bafa70
temp commit for commenting out the hooks so that Razorpay works
domjv Apr 25, 2025
40abadb
Uncommented the hooks for CCAvenue
domjv May 12, 2025
95ff474
logging added
domjv Jun 9, 2025
d4487f0
Log line added to 1 command
domjv Jun 9, 2025
242882d
charge.name removed
domjv Jun 9, 2025
5849c80
error log adjusted to fit in the char limit
domjv Jun 9, 2025
4964543
disabling hooks temporarily for re-enabling razorpay
domjv Jun 9, 2025
7b03e43
hooks enabled for CCAvenue
domjv Jun 10, 2025
f7fe6cb
Merge branch 'dhrumil/ccavenue-integreation-ivyliving' of https://git…
domjv Nov 16, 2025
7c7eed5
[skip] - [cashfree integration with multiple merchants in the same er…
domjv Nov 16, 2025
f1fcdc3
updated cahsfree settings
domjv Nov 16, 2025
2487473
Updated the cashfree settings
domjv Nov 16, 2025
3a26367
temp commit
domjv Nov 16, 2025
21ec0f2
Updated the cashfree sdk to use domjv branch
domjv Nov 28, 2025
36e3489
Updated the error logging
domjv Dec 1, 2025
985a883
cashfree settings emails added
domjv Dec 1, 2025
b7c1600
cashfree settings updated
domjv Dec 6, 2025
4bef685
updated the customer details
domjv Dec 6, 2025
e889823
updated the phone number formatting
domjv Dec 6, 2025
e0d6e5e
CC Avenue code updated
domjv Dec 30, 2025
1a48e93
CCAvenue - on_payment_authorized implemented
domjv Dec 30, 2025
d5690e3
log error ccavene redirect url
domjv Dec 31, 2025
cc170b3
logging more for debugging
domjv Dec 31, 2025
7749950
Updated the redirect_url update
domjv Dec 31, 2025
184dc38
Updated to get the payment entry working and added additional logging
domjv Dec 31, 2025
11bc5ed
additional logging added
domjv Dec 31, 2025
112621c
updated hooks to trigger payment entry creation on the on_payment_aut…
domjv Dec 31, 2025
d7a110b
Updated few places
domjv Dec 31, 2025
c1f18f0
hard coded CCAvenue as mode of payment
domjv Dec 31, 2025
e7504d0
Hard coded CCAvenue as mode of payment when creating payment entry
domjv Dec 31, 2025
03395c2
Updated the make the payment correctly - clean up
domjv Jan 2, 2026
b7e44fc
webhooks added
domjv Jan 4, 2026
d52eecf
webhook fixed
domjv Jan 5, 2026
e72f4c8
updated webhook to add a comment and send email
domjv Jan 5, 2026
694c4b2
logs added
domjv Jan 5, 2026
083f336
Removed webhook integrations
domjv Jan 5, 2026
33c9d3d
webhooks added back
domjv Jan 5, 2026
bfec593
Added check for duplicate payment entry creation
domjv Jan 6, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ payments/docs/current
node_modules/
__pycache__/
.aider*
.helix
.helix
.idea
348 changes: 348 additions & 0 deletions CASHFREE_SETUP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,348 @@
# Cashfree Payment Gateway Integration - Setup Guide

## 🎉 Implementation Complete!

The Cashfree payment gateway has been successfully integrated into the Payments app with full support for:

- ✅ Multiple Cashfree accounts (one per company/hostel)
- ✅ Default account fallback
- ✅ Sandbox and Production environments
- ✅ Invoice payments
- ✅ Shopping cart integration
- ✅ Payment links via email
- ✅ Webhook support for real-time updates
- ✅ Guest payments (onboarding flow)

---

## 📦 Installation Steps

### 1. Install the Cashfree SDK

```bash
cd /Users/dom/frappe-bench
bench pip install cashfree_pg
```

Or the SDK will be automatically installed when you update/install the app:
```bash
bench install-app payments
# or
bench update --apps payments
```

### 2. Restart Bench

```bash
bench restart
```

### 3. Run Migrations

```bash
bench --site your-site-name migrate
```

This will create the `Cashfree Settings` DocType in your database.

---

## ⚙️ Configuration

### Step 1: Get Cashfree Credentials

1. Sign up for Cashfree account at https://www.cashfree.com/
2. Login to [Cashfree Dashboard](https://merchant.cashfree.com/)
3. Go to **Developers > API Keys**
4. Get your **App ID** (Client ID) and **Secret Key**
5. Note: Use Sandbox credentials for testing

### Step 2: Create Cashfree Settings

1. In ERPNext, go to: **Payment Gateways > Cashfree Settings > New**
2. Fill in the details:

**For Hostel 1:**
- Gateway Name: `Cashfree-Hostel1`
- Company: Select "Hostel 1" (or your company name)
- Is Default: Uncheck (only if you have multiple)
- Environment: `Sandbox` (for testing)
- Client ID: Your Cashfree App ID
- Client Secret: Your Cashfree Secret Key

3. Save the document

4. Copy the **Webhook URL** shown in the form

### Step 3: Configure Multiple Accounts (Optional)

Repeat Step 2 for each hostel/company:

**For Hostel 2:**
- Gateway Name: `Cashfree-Hostel2`
- Company: Select "Hostel 2"
- Environment: `Sandbox`
- ... (different credentials)

**For Default Account:**
- Gateway Name: `Cashfree-Default`
- Company: Leave blank
- Is Default: **Check this**
- Environment: `Sandbox`
- ... (credentials)

### Step 4: Configure Webhooks in Cashfree Dashboard

1. Login to [Cashfree Dashboard](https://merchant.cashfree.com/)
2. Go to **Developers > Webhooks**
3. Click **Add Webhook**
4. Paste the Webhook URL from your Cashfree Settings
5. Select these events:
- ✅ `PAYMENT_SUCCESS_WEBHOOK`
- ✅ `PAYMENT_FAILED_WEBHOOK`
6. Save

**Note:** For local testing, use ngrok:
```bash
ngrok http 8000
# Use the ngrok URL in webhook configuration
```

---

## 🧪 Testing

### Test 1: Invoice Payment

1. Create a Sales Invoice
2. Click **Get Payment** button (or create Payment Request)
3. Select payment gateway: `Cashfree-Hostel1`
4. Complete payment using test credentials:
- Card: 4111 1111 1111 1111
- CVV: 123
- Expiry: Any future date
- OTP: 123456
5. Verify payment status updates to "Paid"

### Test 2: Payment Link

Open ERPNext console (bench console):

```python
from payments.payment_gateways.doctype.cashfree_settings.cashfree_settings import CashfreeSettings

# Get settings for a specific company
settings = CashfreeSettings.get_cashfree_settings_by_company("Hostel 1")

# Create payment link
link = settings.create_payment_link(
amount=5000,
currency="INR",
payer_name="John Doe",
payer_email="john@example.com",
payer_phone="9999999999",
title="Admission Fee",
description="Hostel admission fee for 2025",
send_email=True
)

print("Payment Link:", link["link_url"])
```

### Test 3: Shopping Cart

1. Enable Shopping Cart in Website Settings
2. Add items to cart as a customer
3. Proceed to checkout
4. Complete payment
5. Verify order is created

### Test 4: Webhooks

1. Make a test payment
2. Check **Integration Request** list for status updates
3. Check Error Log if webhooks fail
4. Verify `on_payment_authorized` is called on invoice

---

## 🏢 Usage by Company

The system automatically selects the correct Cashfree account based on the company:

```python
payment_details = {
"amount": 10000,
"currency": "INR",
"company": "Hostel 1", # ← Determines which Cashfree account to use
"reference_doctype": "Sales Invoice",
"reference_docname": "INV-001",
"payer_email": "student@example.com",
"payer_name": "John Doe",
"payer_phone": "9876543210",
"title": "Hostel Fee Payment",
"description": "Monthly hostel fee"
}

from payments.utils import get_payment_gateway_controller
controller = get_payment_gateway_controller("Cashfree-Hostel1")
url = controller.get_payment_url(**payment_details)
```

---

## 🔐 Production Deployment

### 1. Get Production Credentials

1. Complete KYC verification in Cashfree Dashboard
2. Get production App ID and Secret Key
3. Test in production with small amounts first

### 2. Update Settings

1. Go to your Cashfree Settings
2. Change Environment to: `Production`
3. Update Client ID and Client Secret with production credentials
4. Save

### 3. Update Webhook URL

1. Update webhook URL in Cashfree Production Dashboard
2. Ensure your site has HTTPS (required for webhooks)
3. Test webhook delivery

---

## 📊 Monitoring

### Check Payment Status

1. **Integration Request List**: Shows all payment attempts
2. **Payment Entry**: Created automatically on successful payment
3. **Error Log**: Shows any errors during payment processing

### Cashfree Dashboard

- View transactions: Cashfree Dashboard > Transactions
- Check settlements: Dashboard > Settlements
- Webhook logs: Dashboard > Developers > Webhooks

---

## 🐛 Troubleshooting

### Issue: "No Cashfree Settings found"
**Solution:** Create at least one Cashfree Settings with "Is Default" checked

### Issue: Webhook not received
**Solutions:**
- Verify webhook URL is correct in Cashfree Dashboard
- Check site is accessible from internet (not localhost)
- Use ngrok for local testing
- Check Error Log for webhook errors

### Issue: Payment fails immediately
**Solutions:**
- Verify credentials (Client ID and Secret)
- Check environment matches (Sandbox vs Production)
- Review Integration Request for error details

### Issue: "Invalid signature" in webhooks
**Solutions:**
- Ensure credentials match the account in Cashfree Dashboard
- Check that webhook secret is correct
- Verify environment setting

---

## 📁 Files Created

```
payments/
├── pyproject.toml # Updated with cashfree_pg dependency
├── payment_gateways/
│ └── doctype/
│ └── cashfree_settings/
│ ├── __init__.py
│ ├── cashfree_settings.json # DocType definition
│ ├── cashfree_settings.py # Main controller
│ ├── cashfree_settings.js # Client script
│ ├── test_cashfree_settings.py # Unit tests
│ └── README.md # Documentation
└── templates/
├── pages/
│ ├── cashfree_checkout.py # Checkout page logic
│ └── cashfree_checkout.html # Checkout page template
└── includes/
└── cashfree_checkout.js # Checkout client script
```

---

## 🚀 Next Steps

1. **Install SDK**: `bench pip install cashfree_pg`
2. **Restart**: `bench restart`
3. **Migrate**: `bench --site your-site migrate`
4. **Configure**: Create Cashfree Settings records
5. **Test**: Make a test payment in sandbox mode
6. **Deploy**: Switch to production when ready

---

## 📞 Support

- **Cashfree Documentation**: https://docs.cashfree.com/
- **Cashfree Support**: https://www.cashfree.com/contact-us/
- **ERPNext Forum**: https://discuss.erpnext.com/

---

## ✅ Features Implemented

| Feature | Status | Notes |
|---------|--------|-------|
| Multiple Accounts | ✅ | One per company |
| Default Fallback | ✅ | Site-wide default |
| Sandbox Support | ✅ | For testing |
| Production Support | ✅ | For live payments |
| Invoice Payment | ✅ | Via Payment Request |
| Shopping Cart | ✅ | Auto-integration |
| Payment Links | ✅ | Email/SMS support |
| Webhooks | ✅ | Real-time updates |
| Guest Payments | ✅ | Token-based |
| Signature Verification | ✅ | Security |
| Error Logging | ✅ | Debugging |
| Multi-currency | ✅ | INR, USD, EUR, etc. |

---

## 🎓 Example Usage Scenarios

### Scenario 1: Student Pays Invoice
1. Admin creates Sales Invoice for student
2. Student clicks "Pay Now" in portal
3. System selects Hostel's Cashfree account
4. Student completes payment
5. Invoice marked as paid automatically

### Scenario 2: Payment Link for Admission
1. Admin creates payment link via console/API
2. Link sent to prospective student's email
3. Student (guest) clicks link and pays
4. Webhook updates status
5. Admin notified, customer record created

### Scenario 3: Shopping Cart Purchase
1. Student browses hostel store
2. Adds items to cart (mattress, supplies)
3. Proceeds to checkout
4. Pays via Cashfree
5. Order created automatically

---

**Implementation Date:** 16 November 2025
**Version:** 1.0.0
**Status:** ✅ Ready for Testing
Loading