# 📮 Postman Collection Import Guide

## 🎯 **Mercury UPI PSP - Complete API Collection**

This Postman collection provides comprehensive testing coverage for all Mercury UPI PSP APIs including NPCI interface and Partner APIs.

## 📥 **How to Import**

### **Method 1: Import JSON File**
1. Open Postman
2. Click **Import** button (top-left)
3. Select **File** tab
4. Choose `Mercury_UPI_PSP_Postman_Collection.json`
5. Click **Import**

### **Method 2: Import from URL**
1. Open Postman
2. Click **Import** button
3. Select **Link** tab
4. Paste: `https://raw.githubusercontent.com/momentpay/UPI-PSP/main/Mercury_UPI_PSP_Postman_Collection.json`
5. Click **Continue** → **Import**

## 🏗️ **Collection Structure**

### **🏛️ NPCI → PSP Interface (Official UPI APIs)**
- ✅ **QR Validation (ReqValQR)** - NPCI validates merchant QR
- ✅ **Payment Processing (ReqPay)** - NPCI processes payment 
- ✅ **Transaction Status Check (ReqChkTxn)** - NPCI checks status
- ✅ **Heartbeat Check (ReqHbt)** - NPCI health monitoring
- ✅ **Batch Transaction Check** - Multiple transaction processing
- ✅ **Settlement Reconciliation** - Daily settlement matching
- ✅ **Mandate Management** - Recurring payment setup

### **🤝 Partner → PSP Interface (Business APIs)**
- ✅ **Generate QR Code** - Partner creates dynamic QR
- ✅ **Check QR Status** - Partner monitors QR usage

### **🔍 International UPI Queries**
- ✅ **Get International QR** - QR with FX conversion
- ✅ **Get FX Rate** - Real-time currency rates

### **📊 Legacy Transaction APIs**
- ✅ **List Transactions** - Transaction history
- ✅ **Get Transaction Details** - Detailed transaction info

## ⚙️ **Environment Setup**

### **Create Environment Variables:**

1. **Create New Environment** in Postman
2. **Add Variables:**

| Variable | Value | Description |
|----------|-------|-------------|
| `base_url` | `http://localhost:4040` | Local development server |
| `api_version` | `v1` | API version |
| `partner_token` | `your-partner-token` | Partner authentication |

### **Production Environment:**
| Variable | Value | Description |
|----------|-------|-------------|
| `base_url` | `https://upi-psp.mercury.com` | Production server |
| `api_version` | `v1` | API version |
| `partner_token` | `prod-partner-token` | Production token |

## 🧪 **Testing Features**

### **Pre-request Scripts:**
- ✅ **Auto-generate timestamps** for UPI requests
- ✅ **Generate random message IDs** (NPCI format)
- ✅ **Generate random transaction IDs** (UUID format)

### **Test Scripts:**
- ✅ **Response status validation** (200/201)
- ✅ **Content-Type validation** (JSON/XML/HTML)
- ✅ **Response time validation** (< 5 seconds)

### **Sample Data:**
- ✅ **Realistic UPI XML** requests
- ✅ **International merchant** data
- ✅ **Multi-currency** examples
- ✅ **Partner integration** scenarios

## 🚀 **Quick Start Testing**

### **1. Start Local Server:**
```bash
cd /path/to/mercury_upi_psp
mix phx.server
```

### **2. Test NPCI APIs:**
1. Open **"🏛️ NPCI → PSP Interface"** folder
2. Run **"4. Heartbeat Check (ReqHbt)"** first
3. Verify XML response with `result="SUCCESS"`
4. Test other NPCI APIs in sequence

### **3. Test Partner APIs:**
1. Open **"🤝 Partner → PSP Interface"** folder
2. Run **"1. Generate QR Code"**
3. Copy `qr_id` from response
4. Run **"2. Check QR Status"** with copied ID

### **4. Test International Features:**
1. Open **"🔍 International UPI Queries"** folder
2. Test **"2. Get FX Rate"** for SGD→INR conversion
3. Test **"1. Get International QR"** with FX parameters

## 📋 **Expected Response Formats**

### **NPCI APIs (XML):**
```xml
<?xml version="1.0" encoding="UTF-8"?>
<RespHbt>
  <Head ver="1.0" ts="2025-08-11T08:23:05Z" orgId="MERCURY001" msgId="MSG..."/>
  <Resp reqMsgId="..." result="SUCCESS" errCode="00"/>
</RespHbt>
```

### **Partner APIs (JSON):**
```json
{
  "success": true,
  "data": {
    "qr_id": "QR_SG_2025_001",
    "qr_string": "upi://pay?pa=merchant@mercury...",
    "amount": "100.50",
    "currency": "SGD",
    "fx_rate": "83.25",
    "inr_amount": "8325.00"
  },
  "message": "QR code generated successfully"
}
```

## 🔧 **Troubleshooting**

### **Common Issues:**

1. **Connection Refused:**
   - ✅ Ensure Phoenix server is running (`mix phx.server`)
   - ✅ Check `base_url` variable points to correct port

2. **XML Parsing Errors:**
   - ✅ Verify Content-Type is `application/xml`
   - ✅ Check XML format matches NPCI specification

3. **Authentication Errors:**
   - ✅ Set `partner_token` environment variable
   - ✅ Check Authorization header in Partner APIs

4. **Route Not Found:**
   - ✅ Verify API endpoints match router configuration
   - ✅ Check for typos in endpoint URLs

## 📊 **Testing Checklist**

### **✅ NPCI Compliance Tests:**
- [ ] All 4 mandatory UPI APIs respond correctly
- [ ] XML format matches NPCI specification
- [ ] Error codes follow UPI standard
- [ ] Response times under 5 seconds

### **✅ Partner Integration Tests:**
- [ ] QR generation with all currencies (SGD, USD, AED, EUR, GBP)
- [ ] FX rate conversion accuracy
- [ ] QR status tracking works correctly
- [ ] International corridors supported

### **✅ Performance Tests:**
- [ ] Concurrent request handling
- [ ] Large batch processing
- [ ] High-volume QR generation
- [ ] Database transaction integrity

## 🎉 **Collection Benefits**

1. **🎯 Complete Coverage** - All APIs documented and testable
2. **🔄 Environment Switching** - Easy dev/staging/prod testing
3. **🧪 Automated Testing** - Built-in validation scripts
4. **📚 Documentation** - Self-documenting API examples
5. **🚀 Quick Onboarding** - New developers can test immediately

---

**Your Mercury UPI PSP APIs are now fully testable with this comprehensive Postman collection!** 🚀
