# Heartbeat API Test

## Test Case: NPCI ReqHbt

### Request
```bash
curl -X POST http://localhost:4040/ReqHbt/2.0/urn:txnid:MERfb3b2da8511849259e669b6b356aa660 \
  -H "Content-Type: application/xml" \
  -d '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns2:ReqHbt xmlns:ns2="http://npci.org/upi/schema/">
    <Head ver="2.0" ts="2024-01-29T13:13:55+05:30" orgId="NPCI" msgId="PAM3eaf410eff2349638897034ef263d1e3"/>
    <Txn id="PAM3aee05cd100641a8b263d58f749abea8" note="ReqHbt" refId="083231151104" refUrl="www.test.co.in" ts="2024-01-29T13:13:55+05:30" type="Hbt" custRef="083231151104"/>
    <HbtMsg type="ALIVE" value="NA"/>
</ns2:ReqHbt>'
```

### Expected Response
```xml
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns2:Ack api="ReqHbt" reqMsgId="PAM3eaf410eff2349638897034ef263d1e3" ts="2024-01-29T07:43:56+00:00" xmlns:ns2="http://npci.org/upi/schema/"/>
```

### Alternative Test (Simple format)
```bash
curl -X POST http://localhost:4040/ReqHbt \
  -H "Content-Type: application/xml" \
  -d '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns2:ReqHbt xmlns:ns2="http://npci.org/upi/schema/">
    <Head ver="2.0" ts="2024-01-29T13:13:55+05:30" orgId="NPCI" msgId="PAM3eaf410eff2349638897034ef263d1e3"/>
    <Txn id="PAM3aee05cd100641a8b263d58f749abea8" note="ReqHbt" refId="083231151104" refUrl="www.test.co.in" ts="2024-01-29T13:13:55+05:30" type="Hbt" custRef="083231151104"/>
    <HbtMsg type="ALIVE" value="NA"/>
</ns2:ReqHbt>'
```

## Implementation Status ✅

### What's Configured:

1. **Router Configuration**: ✅
   - `/ReqHbt/*path` route handles NPCI's versioned URL format
   - `/ReqHbt` route handles simple format
   - Routes use `npci_upi` pipeline for XML-only processing

2. **Controller Implementation**: ✅
   - `UpiController.heartbeat/2` handles both route formats
   - Extracts path information from NPCI URL patterns
   - Proper logging for debugging NPCI requests

3. **XML Processing**: ✅
   - `UpiXmlSchema.parse_req_hbt/1` parses NPCI's ReqHbt XML format
   - `UpiXmlSchema.generate_resp_hbt/1` generates proper Ack response
   - Handles namespaced XML with `ns2:ReqHbt` and `ns2:Ack`

4. **Transaction Manager**: ✅
   - `UpiTransactionManager.process_heartbeat/1` orchestrates the flow
   - Validates request and generates appropriate response
   - Error handling for malformed requests

### Key Features:

- **NPCI URL Pattern Support**: Handles both `/ReqHbt/2.0/urn:txnid:...` and `/ReqHbt`
- **Proper XML Namespacing**: Uses `xmlns:ns2="http://npci.org/upi/schema/"`
- **Request/Response Logging**: Tracks NPCI communication for debugging
- **Error Handling**: Returns appropriate error codes for failures
- **Standard Compliance**: Follows NPCI UPI specification exactly

Your heartbeat implementation is now fully configured and ready for NPCI integration! 🎉
