diff --git a/apps/upi_core/lib/upi_core/special_handlers/acc_ip_10_scenario.ex b/apps/upi_core/lib/upi_core/special_handlers/acc_ip_10_scenario.ex
index bb88469..4080de8 100644
--- a/apps/upi_core/lib/upi_core/special_handlers/acc_ip_10_scenario.ex
+++ b/apps/upi_core/lib/upi_core/special_handlers/acc_ip_10_scenario.ex
@@ -386,218 +386,276 @@ defmodule UpiCore.SpecialHandlers.AccIp10Scenario do
     end
   end
 
-  defp generate_resp_pay_accip10(reversal_data, original_xml) do
-    # Generate ACC_IP_10 specific RespPay XML with exact NPCI format requirements
-    # This follows the strict format for accip10@mercury reversal scenario
-
-    Logger.info("[AccIp10Scenario] 📝 Generating ACC_IP_10 specific RespPay XML")
-
-    # Extract settlement info from QR payload - ensures INR values
-    qr_payload = reversal_data[:qr_payload] || reversal_data["qr_payload"] || ""
-    {settlement_currency, settlement_amount} = extract_settlement_info_from_qr_payload(qr_payload)
-
-    # Extract required data from reversal ReqPay
-    req_msg_id = reversal_data[:msg_id] || reversal_data["msg_id"] || generate_msg_id()
-    txn_id = reversal_data[:txn_id] || reversal_data["txn_id"] || generate_txn_id()
-    org_txn_id = reversal_data[:org_txn_id] || reversal_data["org_txn_id"] || txn_id
-    amount = reversal_data[:amount] || reversal_data["amount"] || settlement_amount || "999.00"
-    cust_ref = reversal_data[:cust_ref] || reversal_data["cust_ref"] || ""
-    ref_url = reversal_data[:ref_url] || reversal_data["ref_url"] || "https://mercurypay.com"
-
-    # Extract QR data from original reversal XML
-    qr_data = extract_qr_data_from_xml(original_xml)
-    qr_expire_ts = qr_data[:expire_ts] || generate_future_timestamp()
-    qr_ts = qr_data[:qr_ts] || generate_npci_timestamp()
-
-    Logger.info("[AccIp10Scenario]   • Request Msg ID: #{req_msg_id}")
-    Logger.info("[AccIp10Scenario]   • Transaction ID: #{txn_id}")
-    Logger.info("[AccIp10Scenario]   • Amount: #{amount} INR")
-    Logger.info("[AccIp10Scenario]   • Type: REVERSAL with subType: CREDIT")
-    Logger.info("[AccIp10Scenario]   • Response Code: CS (SUCCESS)")
-    Logger.info("[AccIp10Scenario]   • Settlement Amount: #{settlement_amount} #{settlement_currency}")
-
-    # Generate ACC_IP_10 compliant RespPay XML
-    resp_xml = """
-    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
-    <upi:RespPay xmlns:upi="http://npci.org/upi/schema/">
-        <Head msgId="#{generate_msg_id()}"
-              orgId="MER101"
-              prodType="UPI"
-              ts="#{generate_npci_timestamp()}"
-              ver="2.0"/>
-        <Txn custRef="#{cust_ref}"
-             id="#{txn_id}"
-             initiationMode="16"
-             note="ACCIP10"
-             orgTxnId="#{org_txn_id}"
-             purpose="11"
-             refCategory="00"
-             refId="#{cust_ref}"
-             refUrl="https://mercurypay.aritic.app"
-             subType="CREDIT"
-             ts="#{generate_npci_timestamp()}"
-             type="REVERSAL">
-            <QR expireTs="#{qr_expire_ts}"
-                qVer="02"
-                qrMedium="03"
-                stan="000125"
-                ts="#{qr_ts}"/>
-        </Txn>
-        <Resp reqMsgId="#{req_msg_id}"
-              result="SUCCESS">
-            <Ref IFSC="AEBK0108766"
-                 acNum="AE123456781"
-                 accType="CURRENT"
-                 addr="#{@target_vpa}"
-                 approvalNum="#{generate_approval_num()}"
-                 code="5932"
-                 orgAmount="#{amount}"
-                 regName="Fujairah Fresh Foods"
-                 respCode="CS"
-                 seqNum="1"
-                 settAmount="#{settlement_amount}"
-                 settCurrency="#{settlement_currency}"
-                 type="PAYEE"/>
-        </Resp>
-        #{generate_signature_section()}
-    </upi:RespPay>
-    """
-
-    Logger.info("[AccIp10Scenario] ✅ Generated ACC_IP_10 RespPay XML successfully")
-    Logger.debug("[AccIp10Scenario] Generated XML (first 500 chars): #{String.slice(resp_xml, 0, 500)}")
-
-    resp_xml
-  end
-
-  defp generate_success_resp_pay(parsed_data, original_xml \\ nil) do
-    # Generate RespPay XML using the standard UpiXmlSchema.generate_resp_pay function
-    # This ensures proper NPCI compliance and formatting
-
-    # Extract settlement info from QR payload - ensures INR values
-    qr_payload = parsed_data[:qr_payload] || parsed_data["qr_payload"] || ""
-    {settlement_currency, settlement_amount} = extract_settlement_info_from_qr_payload(qr_payload)
-
-    # Extract data from the reversal request
-    req_msg_id = parsed_data[:msg_id] || parsed_data["msg_id"] || generate_msg_id()
-    txn_id = parsed_data[:txn_id] || parsed_data["txn_id"] || generate_txn_id()
-    org_txn_id = parsed_data[:org_txn_id] || parsed_data["org_txn_id"] || txn_id
-
-    # Extract amount and payer details from the request
-    amount = parsed_data[:payee_amount] || parsed_data[:amount] || parsed_data["payee_amount"] ||
-             parsed_data["amount"] || settlement_amount || "100.00"
-    payer_addr = parsed_data[:payer_addr] || parsed_data["payer_addr"] || "testpayer@upi"
-    payer_name = parsed_data[:payer_name] || parsed_data["payer_name"] || "Test Payer"
-
-    # Extract QR data from original XML if available
-    qr_data = if original_xml do
-      extract_qr_data_from_xml(original_xml)
-    else
-      %{}
-    end
+  # [RespPay-REVERSAL <Resp> template] OLD FUNCTION kept for reference. It hand-built the XML with hard-coded values: Head msgId "MSG..." (generate_msg_id), prodType, Txn refId=custRef, new Txn ts / QR ts, qVer 02, stan 000125,
+  # Ref IFSC AEBK0108766 / acNum AE123456781 / accType CURRENT / code 5932 / regName "Fujairah Fresh Foods", settAmount from the QR am= and settCurrency from cu=, no reversalRespCode.
+  # [RespPay-REVERSAL Txn.type / subType / refId / ts, QR.expireTs / qVer / ts / stan, Ref.*, Head.msgId, Ref.reversalRespCode] CHANGED: the response is now built by UpiXmlSchema.generate_resp_pay from the reversal ReqPay
+  # (stored original ReqPay fills what the reversal does not carry). TSD Table 4: Txn / QR / Ref echo the request; REVERSAL adds Ref reversalRespCode (CS = credit stands).
+  # OLD:   defp generate_resp_pay_accip10(reversal_data, original_xml) do
+  # OLD:     # Generate ACC_IP_10 specific RespPay XML with exact NPCI format requirements
+  # OLD:     # This follows the strict format for accip10@mercury reversal scenario
+  # OLD:
+  # OLD:     Logger.info("[AccIp10Scenario] 📝 Generating ACC_IP_10 specific RespPay XML")
+  # OLD:
+  # OLD:     # Extract settlement info from QR payload - ensures INR values
+  # OLD:     qr_payload = reversal_data[:qr_payload] || reversal_data["qr_payload"] || ""
+  # OLD:     {settlement_currency, settlement_amount} = extract_settlement_info_from_qr_payload(qr_payload)
+  # OLD:
+  # OLD:     # Extract required data from reversal ReqPay
+  # OLD:     req_msg_id = reversal_data[:msg_id] || reversal_data["msg_id"] || generate_msg_id()
+  # OLD:     txn_id = reversal_data[:txn_id] || reversal_data["txn_id"] || generate_txn_id()
+  # OLD:     org_txn_id = reversal_data[:org_txn_id] || reversal_data["org_txn_id"] || txn_id
+  # OLD:     amount = reversal_data[:amount] || reversal_data["amount"] || settlement_amount || "999.00"
+  # OLD:     cust_ref = reversal_data[:cust_ref] || reversal_data["cust_ref"] || ""
+  # OLD:     ref_url = reversal_data[:ref_url] || reversal_data["ref_url"] || "https://mercurypay.com"
+  # OLD:
+  # OLD:     # Extract QR data from original reversal XML
+  # OLD:     qr_data = extract_qr_data_from_xml(original_xml)
+  # OLD:     qr_expire_ts = qr_data[:expire_ts] || generate_future_timestamp()
+  # OLD:     qr_ts = qr_data[:qr_ts] || generate_npci_timestamp()
+  # OLD:
+  # OLD:     Logger.info("[AccIp10Scenario]   • Request Msg ID: #{req_msg_id}")
+  # OLD:     Logger.info("[AccIp10Scenario]   • Transaction ID: #{txn_id}")
+  # OLD:     Logger.info("[AccIp10Scenario]   • Amount: #{amount} INR")
+  # OLD:     Logger.info("[AccIp10Scenario]   • Type: REVERSAL with subType: CREDIT")
+  # OLD:     Logger.info("[AccIp10Scenario]   • Response Code: CS (SUCCESS)")
+  # OLD:     Logger.info("[AccIp10Scenario]   • Settlement Amount: #{settlement_amount} #{settlement_currency}")
+  # OLD:
+  # OLD:     # Generate ACC_IP_10 compliant RespPay XML
+  # OLD:     resp_xml = """
+  # OLD:     <?xml version="1.0" encoding="UTF-8" standalone="no"?>
+  # OLD:     <upi:RespPay xmlns:upi="http://npci.org/upi/schema/">
+  # OLD:         <Head msgId="#{generate_msg_id()}"
+  # OLD:               orgId="MER101"
+  # OLD:               prodType="UPI"
+  # OLD:               ts="#{generate_npci_timestamp()}"
+  # OLD:               ver="2.0"/>
+  # OLD:         <Txn custRef="#{cust_ref}"
+  # OLD:              id="#{txn_id}"
+  # OLD:              initiationMode="16"
+  # OLD:              note="ACCIP10"
+  # OLD:              orgTxnId="#{org_txn_id}"
+  # OLD:              purpose="11"
+  # OLD:              refCategory="00"
+  # OLD:              refId="#{cust_ref}"
+  # OLD:              refUrl="https://mercurypay.aritic.app"
+  # OLD:              subType="CREDIT"
+  # OLD:              ts="#{generate_npci_timestamp()}"
+  # OLD:              type="REVERSAL">
+  # OLD:             <QR expireTs="#{qr_expire_ts}"
+  # OLD:                 qVer="02"
+  # OLD:                 qrMedium="03"
+  # OLD:                 stan="000125"
+  # OLD:                 ts="#{qr_ts}"/>
+  # OLD:         </Txn>
+  # OLD:         <Resp reqMsgId="#{req_msg_id}"
+  # OLD:               result="SUCCESS">
+  # OLD:             <Ref IFSC="AEBK0108766"
+  # OLD:                  acNum="AE123456781"
+  # OLD:                  accType="CURRENT"
+  # OLD:                  addr="#{@target_vpa}"
+  # OLD:                  approvalNum="#{generate_approval_num()}"
+  # OLD:                  code="5932"
+  # OLD:                  orgAmount="#{amount}"
+  # OLD:                  regName="Fujairah Fresh Foods"
+  # OLD:                  respCode="CS"
+  # OLD:                  seqNum="1"
+  # OLD:                  settAmount="#{settlement_amount}"
+  # OLD:                  settCurrency="#{settlement_currency}"
+  # OLD:                  type="PAYEE"/>
+  # OLD:         </Resp>
+  # OLD:         #{generate_signature_section()}
+  # OLD:     </upi:RespPay>
+  # OLD:     """
+  # OLD:
+  # OLD:     Logger.info("[AccIp10Scenario] ✅ Generated ACC_IP_10 RespPay XML successfully")
+  # OLD:     Logger.debug("[AccIp10Scenario] Generated XML (first 500 chars): #{String.slice(resp_xml, 0, 500)}")
+  # OLD:
+  # OLD:     resp_xml
+  # OLD:   end
+  # [RespPay-REVERSAL generate_resp_pay_accip10] CHANGED: defp -> def (@doc false) so the reversal builder can be unit-tested; callers are unchanged
+  # OLD:   defp generate_resp_pay_accip10(reversal_data, _original_xml) do
+  @doc false
+  def generate_resp_pay_accip10(reversal_data, _original_xml) do
+    Logger.info("[AccIp10Scenario] 📝 Generating ACC_IP_10 REVERSAL RespPay with UpiXmlSchema.generate_resp_pay")
 
-    Logger.info("[AccIp10Scenario] 📝 Generating SUCCESS RespPay using standard UpiXmlSchema:")
-    Logger.info("[AccIp10Scenario]   • Original reqMsgId: #{req_msg_id}")
-    Logger.info("[AccIp10Scenario]   • TxnId: #{txn_id}")
-    Logger.info("[AccIp10Scenario]   • Amount: #{amount} INR")
-    Logger.info("[AccIp10Scenario]   • Type: CREDIT (for accip10@mercury scenario)")
-    Logger.info("[AccIp10Scenario]   • QR ExpireTs: #{qr_data[:expire_ts]}")
-    Logger.info("[AccIp10Scenario]   • Settlement Amount: #{settlement_amount} #{settlement_currency}")
+    # [RespPay-REVERSAL Ref.addr / code / regName / IFSC / acNum / accType] CHANGED: values from the request, else from the stored original ReqPay
+    request_data =
+      UpiXmlSchema.fill_payee_from_stored_req_pay(reversal_data, find_stored_req_pay_for_reversal(reversal_data))
 
-    # Build response data in the format expected by UpiXmlSchema.generate_resp_pay
     response_data = %{
-      # Request identifiers
-      req_msg_id: req_msg_id,
-      msg_id: generate_msg_id(),
-      txn_id: txn_id,
-      org_txn_id: org_txn_id,
-
-      # Response details
+      org_id: "MER101",
+      req_msg_id: reversal_data[:msg_id],
       result: "SUCCESS",
-      err_code: "CS",
+      # [RespPay-REVERSAL Ref.reversalRespCode] ADDED: CS = credit stands (ACC_IP_10); Ref.respCode carries the same value
       resp_code: "CS",
+      reversal_resp_code: "CS",
       approval_num: generate_approval_num(),
-
-      # Transaction details (preserve original note)
-      note: parsed_data[:note] || parsed_data["note"] || "ACCIP10",
-      txn_type: "CREDIT",  # CREDIT type for accip10@mercury scenario
-      org_amount: amount,
-      sett_amount: settlement_amount,  # Use INR amount from QR payload
-      sett_currency: settlement_currency,  # Use INR from QR payload
-
-      # Payer information
-      payer_addr: payer_addr,
-      payer_name: payer_name,
-
-      # Payee information
-      payee_addr: @target_vpa,
-      payee_name: "ACC IP 10 Merchant",
-      payee_code: "0000",
-      reg_name: "ACC IP 10 Merchant",
-      ifsc: "SBIN0000001",
-      ac_num: "1234567890",
-      acc_type: "SAVINGS",
-
-      # QR information from original request
-      expire_ts: qr_data[:expire_ts],
-      qr_ver: qr_data[:qr_ver] || "02",
-      qr_medium: qr_data[:qr_medium] || "03",
-
-      # Timestamps and other metadata
-      head_ts: generate_npci_timestamp(),
-      txn_ts: generate_npci_timestamp(),
-      org_id: "MER101"  # Use PSP org ID per NPCI spec
+      txn_type: "REVERSAL",
+      sub_type: "CREDIT",
+      request_data: request_data
     }
 
-    # Add original request data as request_source for UpiXmlSchema
-    request_source = %{
-      expire_ts: qr_data[:expire_ts],
-      txn_id: txn_id,
-      note: parsed_data[:note] || parsed_data["note"] || "ACCIP10"
-    }
-
-    # Use standard UpiXmlSchema.generate_resp_pay function for ACC_IP_10 scenario
-    Logger.info("[AccIp10Scenario] Using standard UpiXmlSchema.generate_resp_pay for NPCI compliance")
-    case UpiXmlSchema.generate_resp_pay(response_data, request_source) do
-      {:ok, xml} ->
-        Logger.info("[AccIp10Scenario] ✅ Generated standard RespPay XML successfully")
-        xml
-      {:error, reason} ->
-        Logger.error("[AccIp10Scenario] ❌ Failed to generate standard RespPay: #{inspect(reason)}")
-        generate_fallback_resp_pay_xml(response_data)
-    end
+    {:ok, resp_xml} = UpiXmlSchema.generate_resp_pay(response_data)
+    resp_xml
   end
 
-  # Generate proper NPCI-compliant RespPay XML per NPCI Spec v1.7.2
-  defp generate_fallback_resp_pay_xml(data) do
-    Logger.warn("[AccIp10Scenario] Using NPCI v1.7.2 compliant RespPay XML generation")
-
-    """
-    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
-    <ns2:RespPay xmlns:ns2="http://npci.org/upi/schema/">
-      <Head ver="2.0" ts="#{generate_npci_timestamp()}" orgId="MER101" msgId="#{generate_msg_id()}"/>
-      <Txn id="#{data.txn_id}"
-           note="ACC_IP_10 Credit Success"
-           ts="#{generate_npci_timestamp()}"
-           type="CREDIT"
-           orgTxnId="#{data.org_txn_id}"
-           refId="#{data.org_txn_id}"
-           refUrl="">
-      </Txn>
-      <Resp reqMsgId="#{data.req_msg_id}" result="SUCCESS" errCode="CS" approvalNum="#{data.approval_num}"/>
-      <Payer addr="#{data.payer_addr}" name="#{data.payer_name}" seqNum="1" type="PERSON" code="0000"/>
-      <Payee addr="#{data.payee_addr}" name="#{data.payee_name}" seqNum="2" type="ENTITY" code="0000"/>
-      <Amount value="#{data.amount}" curr="INR"/>
-    </ns2:RespPay>
-    """
-  end
+  # [RespPay-REVERSAL Ref.*] ADDED: the stored original ReqPay of a reversal (reversal Txn orgTxnId = original Txn id)
+  defp find_stored_req_pay_for_reversal(reversal_data) do
+    org_txn_id = reversal_data[:org_txn_id]
 
-  defp generate_msg_id do
-    "MSG" <> (:crypto.strong_rand_bytes(8) |> Base.encode16())
-  end
+    if is_binary(org_txn_id) and org_txn_id != "" do
+      from(rp in ReqPay, where: rp.txn_id == ^org_txn_id, order_by: [desc: rp.inserted_at], limit: 1)
+      |> Repo.one()
+    end
+  rescue
+    # [RespPay-REVERSAL Ref.*] CHANGED: also catch :exit - a Repo call without a DB connection / sandbox owner exits instead of raising; the stored ReqPay is optional
+    # OLD:     _ -> nil
+    _ -> nil
+  catch
+    :exit, _ -> nil
+  end
+
+  # [RespPay-REVERSAL generate_resp_pay/2] REMOVED: generate_success_resp_pay (clause) is unused now - dead code since the baseline (never called); its generate_resp_pay/2 call was corrected to /1 above and the reversal is built by generate_resp_pay_accip10
+  # OLD:   defp generate_success_resp_pay(parsed_data, original_xml \\ nil) do
+  # OLD:     # Generate RespPay XML using the standard UpiXmlSchema.generate_resp_pay function
+  # OLD:     # This ensures proper NPCI compliance and formatting
+  # OLD:
+  # OLD:     # Extract settlement info from QR payload - ensures INR values
+  # OLD:     qr_payload = parsed_data[:qr_payload] || parsed_data["qr_payload"] || ""
+  # OLD:     {settlement_currency, settlement_amount} = extract_settlement_info_from_qr_payload(qr_payload)
+  # OLD:
+  # OLD:     # Extract data from the reversal request
+  # OLD:     req_msg_id = parsed_data[:msg_id] || parsed_data["msg_id"] || generate_msg_id()
+  # OLD:     txn_id = parsed_data[:txn_id] || parsed_data["txn_id"] || generate_txn_id()
+  # OLD:     org_txn_id = parsed_data[:org_txn_id] || parsed_data["org_txn_id"] || txn_id
+  # OLD:
+  # OLD:     # Extract amount and payer details from the request
+  # OLD:     amount = parsed_data[:payee_amount] || parsed_data[:amount] || parsed_data["payee_amount"] ||
+  # OLD:              parsed_data["amount"] || settlement_amount || "100.00"
+  # OLD:     payer_addr = parsed_data[:payer_addr] || parsed_data["payer_addr"] || "testpayer@upi"
+  # OLD:     payer_name = parsed_data[:payer_name] || parsed_data["payer_name"] || "Test Payer"
+  # OLD:
+  # OLD:     # Extract QR data from original XML if available
+  # OLD:     qr_data = if original_xml do
+  # OLD:       extract_qr_data_from_xml(original_xml)
+  # OLD:     else
+  # OLD:       %{}
+  # OLD:     end
+  # OLD:
+  # OLD:     Logger.info("[AccIp10Scenario] 📝 Generating SUCCESS RespPay using standard UpiXmlSchema:")
+  # OLD:     Logger.info("[AccIp10Scenario]   • Original reqMsgId: #{req_msg_id}")
+  # OLD:     Logger.info("[AccIp10Scenario]   • TxnId: #{txn_id}")
+  # OLD:     Logger.info("[AccIp10Scenario]   • Amount: #{amount} INR")
+  # OLD:     Logger.info("[AccIp10Scenario]   • Type: CREDIT (for accip10@mercury scenario)")
+  # OLD:     Logger.info("[AccIp10Scenario]   • QR ExpireTs: #{qr_data[:expire_ts]}")
+  # OLD:     Logger.info("[AccIp10Scenario]   • Settlement Amount: #{settlement_amount} #{settlement_currency}")
+  # OLD:
+  # OLD:     # Build response data in the format expected by UpiXmlSchema.generate_resp_pay
+  # OLD:     response_data = %{
+  # OLD:       # Request identifiers
+  # OLD:       req_msg_id: req_msg_id,
+  # OLD:       msg_id: generate_msg_id(),
+  # OLD:       txn_id: txn_id,
+  # OLD:       org_txn_id: org_txn_id,
+  # OLD:
+  # OLD:       # Response details
+  # OLD:       result: "SUCCESS",
+  # OLD:       err_code: "CS",
+  # OLD:       resp_code: "CS",
+  # OLD:       approval_num: generate_approval_num(),
+  # OLD:
+  # OLD:       # Transaction details (preserve original note)
+  # OLD:       note: parsed_data[:note] || parsed_data["note"] || "ACCIP10",
+  # OLD:       txn_type: "CREDIT",  # CREDIT type for accip10@mercury scenario
+  # OLD:       org_amount: amount,
+  # OLD:       sett_amount: settlement_amount,  # Use INR amount from QR payload
+  # OLD:       sett_currency: settlement_currency,  # Use INR from QR payload
+  # OLD:
+  # OLD:       # Payer information
+  # OLD:       payer_addr: payer_addr,
+  # OLD:       payer_name: payer_name,
+  # OLD:
+  # OLD:       # Payee information
+  # OLD:       # [RespPay-REVERSAL Ref.*] REMOVED: invented payee values (ACC IP 10 Merchant, 0000, SBIN0000001, 1234567890, SAVINGS); Ref comes from the request / stored ReqPay
+  # OLD:       # OLD:       payee_addr: @target_vpa,
+  # OLD:       # OLD:       payee_name: "ACC IP 10 Merchant",
+  # OLD:       # OLD:       payee_code: "0000",
+  # OLD:       # OLD:       reg_name: "ACC IP 10 Merchant",
+  # OLD:       # OLD:       ifsc: "SBIN0000001",
+  # OLD:       # OLD:       ac_num: "1234567890",
+  # OLD:       # OLD:       acc_type: "SAVINGS",
+  # OLD:
+  # OLD:       # QR information from original request
+  # OLD:       # [RespPay-REVERSAL QR.expireTs / qVer / qrMedium] CHANGED: no invented 02 / 03 defaults
+  # OLD:       # OLD:       expire_ts: qr_data[:expire_ts],
+  # OLD:       # OLD:       qr_ver: qr_data[:qr_ver] || "02",
+  # OLD:       # OLD:       qr_medium: qr_data[:qr_medium] || "03",
+  # OLD:       expire_ts: qr_data[:expire_ts],
+  # OLD:       qr_ver: qr_data[:qr_ver],
+  # OLD:       qr_medium: qr_data[:qr_medium],
+  # OLD:
+  # OLD:       # Timestamps and other metadata
+  # OLD:       head_ts: generate_npci_timestamp(),
+  # OLD:       txn_ts: generate_npci_timestamp(),
+  # OLD:       org_id: "MER101"  # Use PSP org ID per NPCI spec
+  # OLD:     }
+  # OLD:
+  # OLD:     # [RespPay-REVERSAL generate_resp_pay request] CHANGED: the whole parsed reversal ReqPay is the request (request_source with only expire_ts / txn_id / note is gone)
+  # OLD:     # OLD:     # Add original request data as request_source for UpiXmlSchema
+  # OLD:     # OLD:     request_source = %{
+  # OLD:     # OLD:       expire_ts: qr_data[:expire_ts],
+  # OLD:     # OLD:       txn_id: txn_id,
+  # OLD:     # OLD:       note: parsed_data[:note] || parsed_data["note"] || "ACCIP10"
+  # OLD:     # OLD:     }
+  # OLD:
+  # OLD:     # Use standard UpiXmlSchema.generate_resp_pay function for ACC_IP_10 scenario
+  # OLD:     Logger.info("[AccIp10Scenario] Using standard UpiXmlSchema.generate_resp_pay for NPCI compliance")
+  # OLD:     # [RespPay-REVERSAL generate_resp_pay/2] CHANGED: only generate_resp_pay/1 exists (the /2 call could never compile-run); request goes in as :request_data
+  # OLD:     # OLD:     case UpiXmlSchema.generate_resp_pay(response_data, request_source) do
+  # OLD:     case UpiXmlSchema.generate_resp_pay(Map.put(response_data, :request_data, parsed_data)) do
+  # OLD:       {:ok, xml} ->
+  # OLD:         Logger.info("[AccIp10Scenario] ✅ Generated standard RespPay XML successfully")
+  # OLD:         xml
+  # OLD:       {:error, reason} ->
+  # OLD:         Logger.error("[AccIp10Scenario] ❌ Failed to generate standard RespPay: #{inspect(reason)}")
+  # OLD:         generate_fallback_resp_pay_xml(response_data)
+  # OLD:     end
+  # OLD:   end
 
-  defp generate_txn_id do
-    "TXN" <> (:crypto.strong_rand_bytes(8) |> Base.encode16())
-  end
+  # Generate proper NPCI-compliant RespPay XML per NPCI Spec v1.7.2
+  # [RespPay-REVERSAL generate_resp_pay/2] REMOVED: generate_fallback_resp_pay_xml (clause) is unused now - dead code since the baseline (never called); its generate_resp_pay/2 call was corrected to /1 above and the reversal is built by generate_resp_pay_accip10
+  # OLD:   defp generate_fallback_resp_pay_xml(data) do
+  # OLD:     Logger.warn("[AccIp10Scenario] Using NPCI v1.7.2 compliant RespPay XML generation")
+  # OLD:
+  # OLD:     """
+  # OLD:     <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+  # OLD:     <ns2:RespPay xmlns:ns2="http://npci.org/upi/schema/">
+  # OLD:       <Head ver="2.0" ts="#{generate_npci_timestamp()}" orgId="MER101" msgId="#{generate_msg_id()}"/>
+  # OLD:       <Txn id="#{data.txn_id}"
+  # OLD:            note="ACC_IP_10 Credit Success"
+  # OLD:            ts="#{generate_npci_timestamp()}"
+  # OLD:            type="CREDIT"
+  # OLD:            orgTxnId="#{data.org_txn_id}"
+  # OLD:            refId="#{data.org_txn_id}"
+  # OLD:            refUrl="">
+  # OLD:       </Txn>
+  # OLD:       <Resp reqMsgId="#{data.req_msg_id}" result="SUCCESS" errCode="CS" approvalNum="#{data.approval_num}"/>
+  # OLD:       <Payer addr="#{data.payer_addr}" name="#{data.payer_name}" seqNum="1" type="PERSON" code="0000"/>
+  # OLD:       <Payee addr="#{data.payee_addr}" name="#{data.payee_name}" seqNum="2" type="ENTITY" code="0000"/>
+  # OLD:       <Amount value="#{data.amount}" curr="INR"/>
+  # OLD:     </ns2:RespPay>
+  # OLD:     """
+  # OLD:   end
+
+  # [RespPay-REVERSAL <Resp> template] REMOVED: generate_msg_id (clause) is unused now - the hand-built reversal XML moved to UpiXmlSchema.generate_resp_pay
+  # OLD:   defp generate_msg_id do
+  # OLD:     "MSG" <> (:crypto.strong_rand_bytes(8) |> Base.encode16())
+  # OLD:   end
+
+  # [RespPay-REVERSAL <Resp> template] REMOVED: generate_txn_id (clause) is unused now - the hand-built reversal XML moved to UpiXmlSchema.generate_resp_pay
+  # OLD:   defp generate_txn_id do
+  # OLD:     "TXN" <> (:crypto.strong_rand_bytes(8) |> Base.encode16())
+  # OLD:   end
 
   defp generate_approval_num do
     # Generate 6 character approval number: APP + 3 digits (e.g., APP000, APP123)
@@ -605,48 +663,55 @@ defmodule UpiCore.SpecialHandlers.AccIp10Scenario do
     "APP" <> String.pad_leading(Integer.to_string(random_number), 3, "0")
   end
 
-  defp extract_qr_data_from_xml(xml_string) when is_binary(xml_string) do
-    Logger.debug("[AccIp10Scenario] Extracting QR data from original XML")
-
-    # Extract QR expireTs using regex
-    expire_ts = case Regex.run(~r/expireTs="([^"]+)"/, xml_string) do
-      [_, ts] ->
-        Logger.debug("[AccIp10Scenario] Found QR expireTs: #{ts}")
-        ts
-      _ ->
-        Logger.warn("[AccIp10Scenario] QR expireTs not found in XML")
-        nil
-    end
-
-    # Extract QR version
-    qr_ver = case Regex.run(~r/qVer="([^"]+)"/, xml_string) do
-      [_, ver] -> ver
-      _ -> "02"  # Default
-    end
-
-    # Extract QR medium
-    qr_medium = case Regex.run(~r/qrMedium="([^"]+)"/, xml_string) do
-      [_, medium] -> medium
-      _ -> "03"  # Default
-    end
-
-    %{
-      expire_ts: expire_ts,
-      qr_ver: qr_ver,
-      qr_medium: qr_medium
-    }
-  end
-
-  defp extract_qr_data_from_xml(_), do: %{}
-
-  defp generate_npci_timestamp do
-    # Generate NPCI-compliant timestamp with +05:30 offset (IST)
-    # Format: YYYY-MM-DDTHH:MM:SS+05:30
-    DateTime.now!("Asia/Kolkata")
-    |> DateTime.to_iso8601()
-    |> String.replace("Z", "+05:30")
-    |> String.replace(~r/\.\d+\+/, "+")  # Remove microseconds but keep offset
-  end
+  # [RespPay-REVERSAL <Resp> template] REMOVED: extract_qr_data_from_xml (clause) is unused now - the hand-built reversal XML moved to UpiXmlSchema.generate_resp_pay
+  # OLD:   defp extract_qr_data_from_xml(xml_string) when is_binary(xml_string) do
+  # OLD:     Logger.debug("[AccIp10Scenario] Extracting QR data from original XML")
+  # OLD:
+  # OLD:     # Extract QR expireTs using regex
+  # OLD:     expire_ts = case Regex.run(~r/expireTs="([^"]+)"/, xml_string) do
+  # OLD:       [_, ts] ->
+  # OLD:         Logger.debug("[AccIp10Scenario] Found QR expireTs: #{ts}")
+  # OLD:         ts
+  # OLD:       _ ->
+  # OLD:         Logger.warn("[AccIp10Scenario] QR expireTs not found in XML")
+  # OLD:         nil
+  # OLD:     end
+  # OLD:
+  # OLD:     # Extract QR version
+  # OLD:     qr_ver = case Regex.run(~r/qVer="([^"]+)"/, xml_string) do
+  # OLD:       [_, ver] -> ver
+  # OLD:       # [RespPay-REVERSAL QR.qVer] CHANGED: no invented default 02
+  # OLD:       # OLD:       _ -> "02"  # Default
+  # OLD:       _ -> nil
+  # OLD:     end
+  # OLD:
+  # OLD:     # Extract QR medium
+  # OLD:     qr_medium = case Regex.run(~r/qrMedium="([^"]+)"/, xml_string) do
+  # OLD:       [_, medium] -> medium
+  # OLD:       # [RespPay-REVERSAL QR.qrMedium] CHANGED: no invented default 03
+  # OLD:       # OLD:       _ -> "03"  # Default
+  # OLD:       _ -> nil
+  # OLD:     end
+  # OLD:
+  # OLD:     %{
+  # OLD:       expire_ts: expire_ts,
+  # OLD:       qr_ver: qr_ver,
+  # OLD:       qr_medium: qr_medium
+  # OLD:     }
+  # OLD:   end
+
+  # [RespPay-REVERSAL <Resp> template] REMOVED: extract_qr_data_from_xml (clause) is unused now - the hand-built reversal XML moved to UpiXmlSchema.generate_resp_pay
+  # OLD:   defp extract_qr_data_from_xml(_), do: %{}
+
+  # [RespPay-REVERSAL <Resp> template] REMOVED: generate_npci_timestamp (clause) is unused now - the hand-built reversal XML moved to UpiXmlSchema.generate_resp_pay
+  # OLD:   defp generate_npci_timestamp do
+  # OLD:     # Generate NPCI-compliant timestamp with +05:30 offset (IST)
+  # OLD:     # Format: YYYY-MM-DDTHH:MM:SS+05:30
+  # OLD:     DateTime.now!("Asia/Kolkata")
+  # OLD:     |> DateTime.to_iso8601()
+  # OLD:     |> String.replace("Z", "+05:30")
+  # OLD:     |> String.replace(~r/\.\d+\+/, "+")  # Remove microseconds but keep offset
+  # OLD:   end
 
   @doc """
   Send RespPay to NPCI with comprehensive ACK parsing and logging for ACC_IP_10 scenario
@@ -805,36 +870,37 @@ defmodule UpiCore.SpecialHandlers.AccIp10Scenario do
     final_url
   end
 
-  defp generate_signature_section do
-    # Generate signature placeholder for ACC_IP_10 RespPay
-    # In production, this would contain actual digital signature
-    signature_value = generate_signature_value()
-
-    """
-        <Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
-            <SignedInfo>
-                <CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>
-                <SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"/>
-                <Reference URI="">
-                    <Transforms>
-                        <Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/>
-                    </Transforms>
-                    <DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/>
-                    <DigestValue>NBY7jHmq6eYQTPTKr5tanMvGPd3HIRXasQYO1gOtSSw=</DigestValue>
-                </Reference>
-            </SignedInfo>
-            <SignatureValue>#{signature_value}</SignatureValue>
-            <KeyInfo>
-                <KeyValue>
-                    <RSAKeyValue>
-                        <Modulus>wWXCG5Wc7AWtDBzyB1ksRITjMy85NMzGbdRdGL3jiB8S2kHq6F7vaAv53svriaRpIF2MexXebInAroX2j7e35e+/zO9EgC8Fcz89GLPrPLAOkAszNw9Ckhbr6vI8ZL8B5/wY2dakv7OFw4w8Z2jo0rPrhMqKxPvXAQDLRTqja0cOeuRh6w0yXDq7vamZKTvrMAGEephhOo0zA4+OqmunJs7eEUcMLINbEghPVfUmoNKVlkV0RnbkLkwEf8Ha+Qy0M0M1xsifnWJYpC5N267unvMIYXnNtg7rl0UTe1wbEElvjoIK6lWW8JBpoIt/5ybxqHBqTG9+IiPcLD2aecYI1Q==</Modulus>
-                        <Exponent>AQAB</Exponent>
-                    </RSAKeyValue>
-                </KeyValue>
-            </KeyInfo>
-        </Signature>
-    """
-  end
+  # [RespPay-REVERSAL <Resp> template] REMOVED: generate_signature_section (clause) is unused now - the hand-built reversal XML moved to UpiXmlSchema.generate_resp_pay
+  # OLD:   defp generate_signature_section do
+  # OLD:     # Generate signature placeholder for ACC_IP_10 RespPay
+  # OLD:     # In production, this would contain actual digital signature
+  # OLD:     signature_value = generate_signature_value()
+  # OLD:
+  # OLD:     """
+  # OLD:         <Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
+  # OLD:             <SignedInfo>
+  # OLD:                 <CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>
+  # OLD:                 <SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"/>
+  # OLD:                 <Reference URI="">
+  # OLD:                     <Transforms>
+  # OLD:                         <Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/>
+  # OLD:                     </Transforms>
+  # OLD:                     <DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/>
+  # OLD:                     <DigestValue>NBY7jHmq6eYQTPTKr5tanMvGPd3HIRXasQYO1gOtSSw=</DigestValue>
+  # OLD:                 </Reference>
+  # OLD:             </SignedInfo>
+  # OLD:             <SignatureValue>#{signature_value}</SignatureValue>
+  # OLD:             <KeyInfo>
+  # OLD:                 <KeyValue>
+  # OLD:                     <RSAKeyValue>
+  # OLD:                         <Modulus>wWXCG5Wc7AWtDBzyB1ksRITjMy85NMzGbdRdGL3jiB8S2kHq6F7vaAv53svriaRpIF2MexXebInAroX2j7e35e+/zO9EgC8Fcz89GLPrPLAOkAszNw9Ckhbr6vI8ZL8B5/wY2dakv7OFw4w8Z2jo0rPrhMqKxPvXAQDLRTqja0cOeuRh6w0yXDq7vamZKTvrMAGEephhOo0zA4+OqmunJs7eEUcMLINbEghPVfUmoNKVlkV0RnbkLkwEf8Ha+Qy0M0M1xsifnWJYpC5N267unvMIYXnNtg7rl0UTe1wbEElvjoIK6lWW8JBpoIt/5ybxqHBqTG9+IiPcLD2aecYI1Q==</Modulus>
+  # OLD:                         <Exponent>AQAB</Exponent>
+  # OLD:                     </RSAKeyValue>
+  # OLD:                 </KeyValue>
+  # OLD:             </KeyInfo>
+  # OLD:         </Signature>
+  # OLD:     """
+  # OLD:   end
 
   # Helper function to build ReqPay attributes from parsed data
   defp build_req_pay_attrs_from_parsed_data(parsed_data) do
@@ -895,37 +961,42 @@ defmodule UpiCore.SpecialHandlers.AccIp10Scenario do
     {:ok, resp_pay_xml}
   end
 
-  defp generate_signature_value do
-    # Generate mock signature value for testing
-    # In production, this would be actual cryptographic signature
-    :crypto.strong_rand_bytes(256) |> Base.encode64()
-  end
-
-  defp generate_future_timestamp do
-    # Generate a timestamp 30 minutes in the future for QR expiry
-    DateTime.now!("Asia/Kolkata")
-    |> DateTime.add(30 * 60, :second)  # 30 minutes
-    |> DateTime.to_iso8601()
-    |> String.replace("Z", "+05:30")
-    |> String.replace(~r/\.\d+\+/, "+")  # Remove microseconds but keep offset
-  end
-
-  @doc false
+  # [RespPay-REVERSAL <Resp> template] REMOVED: generate_signature_value (clause) is unused now - the hand-built reversal XML moved to UpiXmlSchema.generate_resp_pay
+  # OLD:   defp generate_signature_value do
+  # OLD:     # Generate mock signature value for testing
+  # OLD:     # In production, this would be actual cryptographic signature
+  # OLD:     :crypto.strong_rand_bytes(256) |> Base.encode64()
+  # OLD:   end
+
+  # [RespPay-REVERSAL <Resp> template] REMOVED: generate_future_timestamp (clause) is unused now - the hand-built reversal XML moved to UpiXmlSchema.generate_resp_pay
+  # OLD:   defp generate_future_timestamp do
+  # OLD:     # Generate a timestamp 30 minutes in the future for QR expiry
+  # OLD:     DateTime.now!("Asia/Kolkata")
+  # OLD:     |> DateTime.add(30 * 60, :second)  # 30 minutes
+  # OLD:     |> DateTime.to_iso8601()
+  # OLD:     |> String.replace("Z", "+05:30")
+  # OLD:     |> String.replace(~r/\.\d+\+/, "+")  # Remove microseconds but keep offset
+  # OLD:   end
+
+  # [RespPay-REVERSAL @doc false] REMOVED: it documented extract_settlement_info_from_qr_payload, which is commented out; left alone it would attach to nothing
+  # OLD:   @doc false
   # Extract settlement currency and amount from QR payload
-  defp extract_settlement_info_from_qr_payload(qr_payload) when is_binary(qr_payload) and qr_payload != "" do
-    # Extract settlement currency - look for cu= parameter (INR)
-    settlement_currency = case Regex.run(~r/[?&]cu=([A-Z]{3})/, qr_payload) do
-      [_, currency] -> currency
-      _ -> "INR"
-    end
-
-    # Extract settlement amount - look for am= parameter (INR debit amount)
-    settlement_amount = case Regex.run(~r/[?&]am=([0-9.]+)/, qr_payload) do
-      [_, amount] -> amount
-      _ -> "0.00"
-    end
-
-    {settlement_currency, settlement_amount}
-  end
-  defp extract_settlement_info_from_qr_payload(_), do: {"INR", "0.00"}
+  # [RespPay-REVERSAL <Resp> template] REMOVED: extract_settlement_info_from_qr_payload (clause) is unused now - the hand-built reversal XML moved to UpiXmlSchema.generate_resp_pay
+  # OLD:   defp extract_settlement_info_from_qr_payload(qr_payload) when is_binary(qr_payload) and qr_payload != "" do
+  # OLD:     # Extract settlement currency - look for cu= parameter (INR)
+  # OLD:     settlement_currency = case Regex.run(~r/[?&]cu=([A-Z]{3})/, qr_payload) do
+  # OLD:       [_, currency] -> currency
+  # OLD:       _ -> "INR"
+  # OLD:     end
+  # OLD:
+  # OLD:     # Extract settlement amount - look for am= parameter (INR debit amount)
+  # OLD:     settlement_amount = case Regex.run(~r/[?&]am=([0-9.]+)/, qr_payload) do
+  # OLD:       [_, amount] -> amount
+  # OLD:       _ -> "0.00"
+  # OLD:     end
+  # OLD:
+  # OLD:     {settlement_currency, settlement_amount}
+  # OLD:   end
+  # [RespPay-REVERSAL <Resp> template] REMOVED: extract_settlement_info_from_qr_payload (clause) is unused now - the hand-built reversal XML moved to UpiXmlSchema.generate_resp_pay
+  # OLD:   defp extract_settlement_info_from_qr_payload(_), do: {"INR", "0.00"}
 end
diff --git a/apps/upi_core/lib/upi_core/special_handlers/timeout_simulation_handler.ex b/apps/upi_core/lib/upi_core/special_handlers/timeout_simulation_handler.ex
index 4d90596..4732f8d 100644
--- a/apps/upi_core/lib/upi_core/special_handlers/timeout_simulation_handler.ex
+++ b/apps/upi_core/lib/upi_core/special_handlers/timeout_simulation_handler.ex
@@ -171,23 +171,36 @@ defmodule UpiCore.SpecialHandlers.TimeoutSimulationHandler do
 
       # Payee details
       seq_num: "1",
-      payee_addr: @timeout_vpa,
-      payee_code: Map.get(parsed_data, :payee_code, "5912"),
+      # [RespPay-REVERSAL Ref.addr / Ref.code] CHANGED: the scenario VPA constant and the dummy MCC 5912 are gone - the request's Payee is echoed by generate_resp_pay
+      # OLD:       payee_addr: @timeout_vpa,
+      # OLD:       payee_code: Map.get(parsed_data, :payee_code, "5912"),
+      payee_addr: Map.get(parsed_data, :payee_addr),
+      payee_code: Map.get(parsed_data, :payee_code),
       org_amount: Map.get(parsed_data, :payee_amount, "0.00"),
       resp_code: "00",  # Success
-      reg_name: Map.get(parsed_data, :payee_name, "Test Merchant"),
-      ifsc: Map.get(parsed_data, :payee_ifsc, "AEBK0098765"),
-      ac_num: Map.get(parsed_data, :payee_ac_num, "AE987654321"),
-      acc_type: Map.get(parsed_data, :payee_ac_type, "CURRENT"),
+      # [RespPay-REVERSAL Ref.regName / IFSC / acNum / accType] CHANGED: no invented Test Merchant / AEBK0098765 / AE987654321 / CURRENT
+      # OLD:       reg_name: Map.get(parsed_data, :payee_name, "Test Merchant"),
+      # OLD:       ifsc: Map.get(parsed_data, :payee_ifsc, "AEBK0098765"),
+      # OLD:       ac_num: Map.get(parsed_data, :payee_ac_num, "AE987654321"),
+      # OLD:       acc_type: Map.get(parsed_data, :payee_ac_type, "CURRENT"),
+      reg_name: Map.get(parsed_data, :payee_name),
+      ifsc: Map.get(parsed_data, :payee_ifsc),
+      ac_num: Map.get(parsed_data, :payee_ac_num),
+      acc_type: Map.get(parsed_data, :payee_ac_type),
       approval_num: generate_approval_number(),
       sett_amount: Map.get(parsed_data, :payee_amount, "0.00"),
-      sett_currency: "AED",
-      initiation_mode: "16",
+      # [RespPay-REVERSAL Ref.settCurrency / Txn.initiationMode / Ref.reversalRespCode] CHANGED: settCurrency INR (was AED); initiationMode is echoed from the request (was fixed 16); reversalRespCode 00 = reversed ADDED
+      # TSD Table 4: settCurrency INR; REVERSAL carries Ref reversalRespCode (00 = reversed)
+      # OLD:       sett_currency: "AED",
+      # OLD:       initiation_mode: "16",
+      sett_currency: "INR",
+      reversal_resp_code: "00",
 
       # QR details
-      qr_ver: "02",
-      qr_medium: "03",
-      expire_ts: DateTime.utc_now() |> DateTime.add(1800, :second) |> DateTime.to_iso8601(),
+      # [RespPay-REVERSAL QR.qVer / QR.qrMedium / QR.expireTs] CHANGED: the generated UTC "...Z" expiry (now+30min) and the fixed 02 / 03 are gone - the ReqPay QR element is echoed
+      # OLD:       qr_ver: "02",
+      # OLD:       qr_medium: "03",
+      # OLD:       expire_ts: DateTime.utc_now() |> DateTime.add(1800, :second) |> DateTime.to_iso8601(),
 
       # Request data for XML generation
       request_data: parsed_data
diff --git a/apps/upi_core/lib/upi_core/upi_xml_schema.ex b/apps/upi_core/lib/upi_core/upi_xml_schema.ex
index 68a7634..09ec343 100644
--- a/apps/upi_core/lib/upi_core/upi_xml_schema.ex
+++ b/apps/upi_core/lib/upi_core/upi_xml_schema.ex
@@ -580,6 +580,40 @@ defmodule UpiCore.UpiXmlSchema do
   end
   def extract_ref_data_from_req_pay(_), do: {:ok, %{}}
 
+  @doc """
+  [RespPay-REVERSAL / RespChkTxn Ref] ADDED: fills the Payee values a request does not carry (addr, name, code, IFSC, acNum, accType, amount)
+  from the stored ReqPay row (`UpiCore.Transactions.ReqPay` or any map with the same fields). Values already in the request always win;
+  nothing is invented - a field stays missing when neither has it.
+  """
+  def fill_payee_from_stored_req_pay(request_data, nil), do: request_data
+
+  def fill_payee_from_stored_req_pay(request_data, stored) do
+    fill = fn map, key, value ->
+      if Map.get(map, key) in [nil, ""] and value not in [nil, ""],
+        do: Map.put(map, key, value),
+        else: map
+    end
+
+    amount =
+      case Map.get(stored, :amount) do
+        %Decimal{} = d -> Decimal.to_string(d)
+        other -> other
+      end
+
+    request_data
+    |> fill.(:payee_addr, Map.get(stored, :payee_addr))
+    |> fill.(:payee_name, Map.get(stored, :payee_name))
+    |> fill.(:payee_code, Map.get(stored, :merchant_category_code))
+    |> fill.(:payee_ifsc, Map.get(stored, :payee_ifsc))
+    |> fill.(:payee_ac_num, Map.get(stored, :payee_account_number))
+    |> fill.(:payee_ac_type, Map.get(stored, :payee_account_type))
+    |> fill.(:payee_amount, amount)
+  end
+
+    # [RespPay-REVERSAL Ref.reversalRespCode] ADDED: reversalRespCode right after respCode when Txn type is REVERSAL (same value as respCode)
+    # OLD:     <Ref type="PAYEE" seqNum="1"#{attr_always.("addr", payee_addr)}#{attr_always.("code", req_val.(:payee_code))} orgAmount="#{NpciFormat.xml_attr(org_amount)}"#{attr_always.("respCode", ref_resp_code)}#{attr_always.("regName", Map.get(request_source, :payee_name) || Map.get(response_data, :reg_name))}#{attr_always.("IFSC", Map.get(request_source, :payee_ifsc) || Map.get(response_data, :ifsc))}#{attr_always.("acNum", Map.get(request_source, :payee_ac_num) || Map.get(response_data, :ac_num))}#{attr_always.("accType", Map.get(request_source, :payee_ac_type) || Map.get(response_data, :acc_type))} approvalNum="#{approval_num_truncated}" settAmount="#{NpciFormat.xml_attr(sett_amount_final)}" settCurrency="INR" />
+  # [RespPay-REVERSAL Head.msgId] CHANGED: REVERSAL responses use NpciFormat.new_msg_id/0 (head_msg_id above); other RespPay keep the old msgId logic
+  # OLD:   <Head ver="2.0" ts="#{Map.get(response_data, :head_ts, get_timestamp())}" orgId="#{Map.get(response_data, :org_id)}" msgId="#{generate_fixed_length_msg_id(Map.get(response_data, :msg_id))}"/>
   # [RespPay <Resp> template] OLD TEMPLATE kept for reference - removed <Merchant>/<Institution> (TSD Table 4 has only <Ref> in <Resp>); Txn / QR / Ref now echo ReqPay (see the tagged lines above)
   # OLD:   xml_body = """
   # OLD: <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
@@ -715,6 +749,21 @@ defmodule UpiCore.UpiXmlSchema do
 
     err_code = ref_resp_code
 
+    # [RespPay-REVERSAL Ref.reversalRespCode / Head.msgId] ADDED: a REVERSAL response carries reversalRespCode (CS = credit stands, 00 = reversed),
+    # equal to Ref.respCode, and a fresh 35 char msgId (NpciFormat.new_msg_id/0)
+    # TSD Table 4: Ref reversalRespCode for Txn type REVERSAL
+    is_reversal = req_val.(:txn_type) == "REVERSAL"
+
+    reversal_resp_code_attr =
+      if is_reversal,
+        do: attr_always.("reversalRespCode", Map.get(response_data, :reversal_resp_code) || ref_resp_code),
+        else: ""
+
+    head_msg_id =
+      if is_reversal,
+        do: NpciFormat.new_msg_id(),
+        else: generate_fixed_length_msg_id(Map.get(response_data, :msg_id))
+
     # Sanitize mandatory Ref fields to meet NPCI validation:
     # seqNum must be numeric; addr must be alphanumeric; approvalNum must be present
     ref_seq_raw = Map.get(response_data, :seq_num) || Map.get(request_source, :seq_num) || ""
@@ -836,7 +885,7 @@ defmodule UpiCore.UpiXmlSchema do
   xml_body = """
 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
 <upi:RespPay xmlns:upi="http://npci.org/upi/schema/">
-  <Head ver="2.0" ts="#{Map.get(response_data, :head_ts, get_timestamp())}" orgId="#{Map.get(response_data, :org_id)}" msgId="#{generate_fixed_length_msg_id(Map.get(response_data, :msg_id))}"/>
+  <Head ver="2.0" ts="#{Map.get(response_data, :head_ts, get_timestamp())}" orgId="#{Map.get(response_data, :org_id)}" msgId="#{head_msg_id}"/>
   <Txn id="#{NpciFormat.xml_attr(txn_id)}"#{attr_always.("note", req_val.(:note))}#{attr_always.("refId", req_val.(:ref_id))}#{attr_always.("custRef", req_val.(:cust_ref))} refUrl="#{get_psp_ref_url()}"#{attr_always.("ts", req_val.(:txn_ts))}#{attr_always.("purpose", req_val.(:purpose))}#{attr_always.("type", req_val.(:txn_type))}#{attr_always.("subType", req_val.(:sub_type))}#{attr_always.("initiationMode", req_val.(:initiation_mode))}#{attr_always.("orgTxnId", req_val.(:org_txn_id))}#{attr_always.("refCategory", req_val.(:ref_category))}>
     <RiskScores>
       <Score provider="NPCI" type="TXNRISK" value="00999"/>
@@ -844,7 +893,7 @@ defmodule UpiCore.UpiXmlSchema do
     <QR#{attr_always.("expireTs", qr_expire_ts)}#{attr_always.("qVer", qr_ver)}#{attr_always.("qrMedium", qr_medium)}#{if qr_ts_attribute not in [nil, ""], do: attr_always.("ts", qr_ts_attribute), else: ""} />
   </Txn>
   <Resp reqMsgId="#{NpciFormat.xml_attr(resp_req_msg_id)}" result="#{NpciFormat.xml_attr(result_final)}"#{if result_final != "SUCCESS", do: attr_always.("errCode", err_code), else: ""}>
-    <Ref type="PAYEE" seqNum="1"#{attr_always.("addr", payee_addr)}#{attr_always.("code", req_val.(:payee_code))} orgAmount="#{NpciFormat.xml_attr(org_amount)}"#{attr_always.("respCode", ref_resp_code)}#{attr_always.("regName", Map.get(request_source, :payee_name) || Map.get(response_data, :reg_name))}#{attr_always.("IFSC", Map.get(request_source, :payee_ifsc) || Map.get(response_data, :ifsc))}#{attr_always.("acNum", Map.get(request_source, :payee_ac_num) || Map.get(response_data, :ac_num))}#{attr_always.("accType", Map.get(request_source, :payee_ac_type) || Map.get(response_data, :acc_type))} approvalNum="#{approval_num_truncated}" settAmount="#{NpciFormat.xml_attr(sett_amount_final)}" settCurrency="INR" />
+    <Ref type="PAYEE" seqNum="1"#{attr_always.("addr", payee_addr)}#{attr_always.("code", req_val.(:payee_code))} orgAmount="#{NpciFormat.xml_attr(org_amount)}"#{attr_always.("respCode", ref_resp_code)}#{reversal_resp_code_attr}#{attr_always.("regName", Map.get(request_source, :payee_name) || Map.get(response_data, :reg_name))}#{attr_always.("IFSC", Map.get(request_source, :payee_ifsc) || Map.get(response_data, :ifsc))}#{attr_always.("acNum", Map.get(request_source, :payee_ac_num) || Map.get(response_data, :ac_num))}#{attr_always.("accType", Map.get(request_source, :payee_ac_type) || Map.get(response_data, :acc_type))} approvalNum="#{approval_num_truncated}" settAmount="#{NpciFormat.xml_attr(sett_amount_final)}" settCurrency="INR" />
   </Resp>
 """
 
diff --git a/apps/upi_core/test/upi_core/resp_pay_reversal_test.exs b/apps/upi_core/test/upi_core/resp_pay_reversal_test.exs
new file mode 100644
index 0000000..bd147f6
--- /dev/null
+++ b/apps/upi_core/test/upi_core/resp_pay_reversal_test.exs
@@ -0,0 +1,191 @@
+defmodule UpiCore.RespPayReversalTest do
+  use ExUnit.Case, async: false
+
+  import SweetXml
+
+  alias UpiCore.UpiXmlSchema
+  alias UpiCore.SpecialHandlers.{AccIp10Scenario, TimeoutSimulationHandler}
+
+  @key_path Path.expand("../../../../private.pem", __DIR__)
+
+  # What parse_req_pay/1 returns for an ACC_IP_10 / ACC_IP_09 REVERSAL ReqPay
+  @reversal %{
+    msg_id: "NPCIREVERSAL000000000000000000001",
+    txn_id: "NPCIREVTXN0001",
+    org_txn_id: "ORGTXN0001",
+    note: "ACC_IP_10 reversal",
+    cust_ref: "CUSTREF10",
+    ref_id: "REFNPCI0010",
+    ref_category: "00",
+    txn_type: "REVERSAL",
+    sub_type: "CREDIT",
+    purpose: "11",
+    initiation_mode: "16",
+    txn_ts: "2026-07-09T14:50:00+05:30",
+    qr_ver: "01",
+    qr_ts: "2026-07-09T14:46:11+05:30",
+    qr_medium: "03",
+    expire_ts: "2026-07-09T15:16:11+05:30",
+    stan: "999999",
+    payee_addr: "accip10@mercury",
+    payee_name: "NPCI Tester",
+    payee_code: "5812",
+    payee_ifsc: "TEST0000001",
+    payee_ac_num: "TESTACNUM0010",
+    payee_ac_type: "CURRENT",
+    payee_amount: "5.00",
+    qr_payload: "upiGlobal://pay?ver=01&mode=16&QRexpire=2026-07-09T15:16:11+05:30&QRts=2026-07-09T14:46:11+05:30"
+  }
+
+  setup do
+    previous = Application.get_env(:upi_core, :xml_signing_priv_key_path)
+    Application.put_env(:upi_core, :xml_signing_priv_key_path, @key_path)
+
+    on_exit(fn ->
+      if previous,
+        do: Application.put_env(:upi_core, :xml_signing_priv_key_path, previous),
+        else: Application.delete_env(:upi_core, :xml_signing_priv_key_path)
+    end)
+
+    :ok
+  end
+
+  defp attr(xml, path), do: xpath(xml, ~x"#{path}"s)
+  @ref "//*[local-name()='Ref']"
+  @txn "//*[local-name()='Txn']"
+  @qr "//*[local-name()='QR']"
+
+  defp assert_reversal_echo(xml, code) do
+    assert attr(xml, @txn <> "/@type") == "REVERSAL"
+    assert attr(xml, @txn <> "/@subType") == "CREDIT"
+    assert attr(xml, @txn <> "/@id") == "NPCIREVTXN0001"
+    assert attr(xml, @txn <> "/@orgTxnId") == "ORGTXN0001"
+    assert attr(xml, @txn <> "/@refId") == "REFNPCI0010"
+    assert attr(xml, @txn <> "/@custRef") == "CUSTREF10"
+    assert attr(xml, @txn <> "/@note") == "ACC_IP_10 reversal"
+    assert attr(xml, @txn <> "/@ts") == "2026-07-09T14:50:00+05:30"
+    assert attr(xml, @txn <> "/@initiationMode") == "16"
+    assert attr(xml, @qr <> "/@expireTs") == "2026-07-09T15:16:11+05:30"
+    assert attr(xml, @qr <> "/@qVer") == "01"
+    assert attr(xml, @qr <> "/@ts") == "2026-07-09T14:46:11+05:30"
+    assert attr(xml, @qr <> "/@stan") == ""
+    assert attr(xml, @ref <> "/@respCode") == code
+    assert attr(xml, @ref <> "/@reversalRespCode") == code
+    assert attr(xml, @ref <> "/@settCurrency") == "INR"
+    assert attr(xml, @ref <> "/@addr") == "accip10@mercury"
+    assert attr(xml, @ref <> "/@code") == "5812"
+    assert attr(xml, @ref <> "/@regName") == "NPCI Tester"
+    assert attr(xml, @ref <> "/@IFSC") == "TEST0000001"
+    assert attr(xml, @ref <> "/@acNum") == "TESTACNUM0010"
+    assert attr(xml, @ref <> "/@orgAmount") == "5.00"
+    assert attr(xml, @ref <> "/@settAmount") == "5.00"
+    assert attr(xml, "//*[local-name()='Resp']/@errCode") == ""
+    assert attr(xml, "//*[local-name()='Resp']/@result") == "SUCCESS"
+    assert attr(xml, "//*[local-name()='Head']/@msgId") =~ ~r/^MER[0-9a-f]{32}$/
+    assert attr(xml, "//*[local-name()='Score']/@value") == "00999"
+    refute xml =~ "AEBK0108766"
+    refute xml =~ "AE123456781"
+    refute xml =~ "Fujairah"
+    refute xml =~ "orgRespCode"
+    refute xml =~ "www.test.co.in"
+  end
+
+  describe "generate_resp_pay/1 with a REVERSAL request" do
+    test "CS = credit stands: reversalRespCode equals respCode" do
+      {:ok, xml} =
+        UpiXmlSchema.generate_resp_pay(%{
+          org_id: "MER101",
+          req_msg_id: @reversal.msg_id,
+          result: "SUCCESS",
+          resp_code: "CS",
+          reversal_resp_code: "CS",
+          request_data: @reversal
+        })
+
+      assert_reversal_echo(xml, "CS")
+    end
+
+    test "00 = reversed" do
+      {:ok, xml} =
+        UpiXmlSchema.generate_resp_pay(%{
+          org_id: "MER101",
+          req_msg_id: @reversal.msg_id,
+          result: "SUCCESS",
+          resp_code: "00",
+          reversal_resp_code: "00",
+          request_data: @reversal
+        })
+
+      assert_reversal_echo(xml, "00")
+    end
+
+    test "reversalRespCode defaults to the respCode" do
+      {:ok, xml} =
+        UpiXmlSchema.generate_resp_pay(%{
+          org_id: "MER101", result: "SUCCESS", resp_code: "00", request_data: @reversal
+        })
+
+      assert attr(xml, @ref <> "/@reversalRespCode") == "00"
+    end
+
+    test "a new msgId every time" do
+      data = %{org_id: "MER101", result: "SUCCESS", resp_code: "CS", request_data: @reversal}
+      {:ok, a} = UpiXmlSchema.generate_resp_pay(data)
+      {:ok, b} = UpiXmlSchema.generate_resp_pay(data)
+      refute attr(a, "//*[local-name()='Head']/@msgId") == attr(b, "//*[local-name()='Head']/@msgId")
+    end
+
+    test "a normal credit RespPay has no reversalRespCode" do
+      req = %{@reversal | txn_type: "CREDIT", sub_type: "PAY"}
+      {:ok, xml} = UpiXmlSchema.generate_resp_pay(%{org_id: "MER101", result: "SUCCESS", resp_code: "00", request_data: req})
+      refute xml =~ "reversalRespCode"
+    end
+  end
+
+  describe "fill_payee_from_stored_req_pay/2" do
+    test "fills only what the request does not carry" do
+      stored = %{
+        payee_addr: "stored@mercury",
+        payee_name: "Stored Name",
+        merchant_category_code: "5411",
+        payee_ifsc: "STOR0000001",
+        payee_account_number: "STOREDACNUM",
+        payee_account_type: "SAVINGS",
+        amount: Decimal.new("7.5")
+      }
+
+      req = %{payee_name: "Request Name", payee_amount: ""}
+      filled = UpiXmlSchema.fill_payee_from_stored_req_pay(req, stored)
+      assert filled.payee_name == "Request Name"
+      assert filled.payee_addr == "stored@mercury"
+      assert filled.payee_code == "5411"
+      assert filled.payee_ifsc == "STOR0000001"
+      assert filled.payee_ac_num == "STOREDACNUM"
+      assert filled.payee_ac_type == "SAVINGS"
+      assert filled.payee_amount == "7.5"
+    end
+
+    test "nothing stored -> request unchanged, nothing invented" do
+      assert UpiXmlSchema.fill_payee_from_stored_req_pay(%{a: 1}, nil) == %{a: 1}
+      assert UpiXmlSchema.fill_payee_from_stored_req_pay(%{}, %{payee_addr: nil}) == %{}
+    end
+  end
+
+  describe "ACC_IP_10 builder (core)" do
+    test "builds the CS reversal RespPay from the ReqPay" do
+      xml = AccIp10Scenario.generate_resp_pay_accip10(@reversal, "<ignored/>")
+      assert_reversal_echo(xml, "CS")
+      assert attr(xml, "//*[local-name()='Head']/@orgId") == "MER101"
+    end
+  end
+
+  describe "ACC_IP_09 builder (timeout simulation reversal, core)" do
+    test "00 = reversed, INR, QR echoed (no generated UTC expiry), Ref from the ReqPay" do
+      {:ok, xml} = TimeoutSimulationHandler.generate_reversal_success_response(@reversal)
+      assert_reversal_echo(xml, "00")
+      refute xml =~ "AEBK0098765"
+      refute xml =~ "Test Merchant"
+      refute xml =~ ~r/expireTs="[^"]*Z"/
+    end
+  end
+end
diff --git a/apps/upi_dynamic/lib/upi_dynamic/special_handlers/acc_ip_10_scenario.ex b/apps/upi_dynamic/lib/upi_dynamic/special_handlers/acc_ip_10_scenario.ex
index 79e7830..15e9637 100644
--- a/apps/upi_dynamic/lib/upi_dynamic/special_handlers/acc_ip_10_scenario.ex
+++ b/apps/upi_dynamic/lib/upi_dynamic/special_handlers/acc_ip_10_scenario.ex
@@ -386,218 +386,276 @@ defmodule UpiDynamic.SpecialHandlers.AccIp10Scenario do
     end
   end
 
-  defp generate_resp_pay_accip10(reversal_data, original_xml) do
-    # Generate ACC_IP_10 specific RespPay XML with exact NPCI format requirements
-    # This follows the strict format for accip10@mercury reversal scenario
-
-    Logger.info("[AccIp10Scenario] 📝 Generating ACC_IP_10 specific RespPay XML")
-
-    # Extract settlement info from QR payload - ensures INR values
-    qr_payload = reversal_data[:qr_payload] || reversal_data["qr_payload"] || ""
-    {settlement_currency, settlement_amount} = extract_settlement_info_from_qr_payload(qr_payload)
-
-    # Extract required data from reversal ReqPay
-    req_msg_id = reversal_data[:msg_id] || reversal_data["msg_id"] || generate_msg_id()
-    txn_id = reversal_data[:txn_id] || reversal_data["txn_id"] || generate_txn_id()
-    org_txn_id = reversal_data[:org_txn_id] || reversal_data["org_txn_id"] || txn_id
-    amount = reversal_data[:amount] || reversal_data["amount"] || settlement_amount || "999.00"
-    cust_ref = reversal_data[:cust_ref] || reversal_data["cust_ref"] || ""
-    ref_url = reversal_data[:ref_url] || reversal_data["ref_url"] || "https://mercurypay.com"
-
-    # Extract QR data from original reversal XML
-    qr_data = extract_qr_data_from_xml(original_xml)
-    qr_expire_ts = qr_data[:expire_ts] || generate_future_timestamp()
-    qr_ts = qr_data[:qr_ts] || generate_npci_timestamp()
-
-    Logger.info("[AccIp10Scenario]   • Request Msg ID: #{req_msg_id}")
-    Logger.info("[AccIp10Scenario]   • Transaction ID: #{txn_id}")
-    Logger.info("[AccIp10Scenario]   • Amount: #{amount} INR")
-    Logger.info("[AccIp10Scenario]   • Type: REVERSAL with subType: CREDIT")
-    Logger.info("[AccIp10Scenario]   • Response Code: CS (SUCCESS)")
-    Logger.info("[AccIp10Scenario]   • Settlement Amount: #{settlement_amount} #{settlement_currency}")
-
-    # Generate ACC_IP_10 compliant RespPay XML
-    resp_xml = """
-    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
-    <upi:RespPay xmlns:upi="http://npci.org/upi/schema/">
-        <Head msgId="#{generate_msg_id()}"
-              orgId="MER101"
-              prodType="UPI"
-              ts="#{generate_npci_timestamp()}"
-              ver="2.0"/>
-        <Txn custRef="#{cust_ref}"
-             id="#{txn_id}"
-             initiationMode="16"
-             note="ACCIP10"
-             orgTxnId="#{org_txn_id}"
-             purpose="11"
-             refCategory="00"
-             refId="#{cust_ref}"
-             refUrl="https://mercurypay.aritic.app"
-             subType="CREDIT"
-             ts="#{generate_npci_timestamp()}"
-             type="REVERSAL">
-            <QR expireTs="#{qr_expire_ts}"
-                qVer="02"
-                qrMedium="03"
-                stan="000125"
-                ts="#{qr_ts}"/>
-        </Txn>
-        <Resp reqMsgId="#{req_msg_id}"
-              result="SUCCESS">
-            <Ref IFSC="AEBK0108766"
-                 acNum="AE123456781"
-                 accType="CURRENT"
-                 addr="#{@target_vpa}"
-                 approvalNum="#{generate_approval_num()}"
-                 code="5932"
-                 orgAmount="#{amount}"
-                 regName="Fujairah Fresh Foods"
-                 respCode="CS"
-                 seqNum="1"
-                 settAmount="#{settlement_amount}"
-                 settCurrency="#{settlement_currency}"
-                 type="PAYEE"/>
-        </Resp>
-        #{generate_signature_section()}
-    </upi:RespPay>
-    """
-
-    Logger.info("[AccIp10Scenario] ✅ Generated ACC_IP_10 RespPay XML successfully")
-    Logger.debug("[AccIp10Scenario] Generated XML (first 500 chars): #{String.slice(resp_xml, 0, 500)}")
-
-    resp_xml
-  end
-
-  defp generate_success_resp_pay(parsed_data, original_xml \\ nil) do
-    # Generate RespPay XML using the standard UpiXmlSchema.generate_resp_pay function
-    # This ensures proper NPCI compliance and formatting
-
-    # Extract settlement info from QR payload - ensures INR values
-    qr_payload = parsed_data[:qr_payload] || parsed_data["qr_payload"] || ""
-    {settlement_currency, settlement_amount} = extract_settlement_info_from_qr_payload(qr_payload)
-
-    # Extract data from the reversal request
-    req_msg_id = parsed_data[:msg_id] || parsed_data["msg_id"] || generate_msg_id()
-    txn_id = parsed_data[:txn_id] || parsed_data["txn_id"] || generate_txn_id()
-    org_txn_id = parsed_data[:org_txn_id] || parsed_data["org_txn_id"] || txn_id
-
-    # Extract amount and payer details from the request
-    amount = parsed_data[:payee_amount] || parsed_data[:amount] || parsed_data["payee_amount"] ||
-             parsed_data["amount"] || settlement_amount || "100.00"
-    payer_addr = parsed_data[:payer_addr] || parsed_data["payer_addr"] || "testpayer@upi"
-    payer_name = parsed_data[:payer_name] || parsed_data["payer_name"] || "Test Payer"
-
-    # Extract QR data from original XML if available
-    qr_data = if original_xml do
-      extract_qr_data_from_xml(original_xml)
-    else
-      %{}
-    end
+  # [RespPay-REVERSAL <Resp> template] OLD FUNCTION kept for reference. It hand-built the XML with hard-coded values: Head msgId "MSG..." (generate_msg_id), prodType, Txn refId=custRef, new Txn ts / QR ts, qVer 02, stan 000125,
+  # Ref IFSC AEBK0108766 / acNum AE123456781 / accType CURRENT / code 5932 / regName "Fujairah Fresh Foods", settAmount from the QR am= and settCurrency from cu=, no reversalRespCode.
+  # [RespPay-REVERSAL Txn.type / subType / refId / ts, QR.expireTs / qVer / ts / stan, Ref.*, Head.msgId, Ref.reversalRespCode] CHANGED: the response is now built by UpiXmlSchema.generate_resp_pay from the reversal ReqPay
+  # (stored original ReqPay fills what the reversal does not carry). TSD Table 4: Txn / QR / Ref echo the request; REVERSAL adds Ref reversalRespCode (CS = credit stands).
+  # OLD:   defp generate_resp_pay_accip10(reversal_data, original_xml) do
+  # OLD:     # Generate ACC_IP_10 specific RespPay XML with exact NPCI format requirements
+  # OLD:     # This follows the strict format for accip10@mercury reversal scenario
+  # OLD:
+  # OLD:     Logger.info("[AccIp10Scenario] 📝 Generating ACC_IP_10 specific RespPay XML")
+  # OLD:
+  # OLD:     # Extract settlement info from QR payload - ensures INR values
+  # OLD:     qr_payload = reversal_data[:qr_payload] || reversal_data["qr_payload"] || ""
+  # OLD:     {settlement_currency, settlement_amount} = extract_settlement_info_from_qr_payload(qr_payload)
+  # OLD:
+  # OLD:     # Extract required data from reversal ReqPay
+  # OLD:     req_msg_id = reversal_data[:msg_id] || reversal_data["msg_id"] || generate_msg_id()
+  # OLD:     txn_id = reversal_data[:txn_id] || reversal_data["txn_id"] || generate_txn_id()
+  # OLD:     org_txn_id = reversal_data[:org_txn_id] || reversal_data["org_txn_id"] || txn_id
+  # OLD:     amount = reversal_data[:amount] || reversal_data["amount"] || settlement_amount || "999.00"
+  # OLD:     cust_ref = reversal_data[:cust_ref] || reversal_data["cust_ref"] || ""
+  # OLD:     ref_url = reversal_data[:ref_url] || reversal_data["ref_url"] || "https://mercurypay.com"
+  # OLD:
+  # OLD:     # Extract QR data from original reversal XML
+  # OLD:     qr_data = extract_qr_data_from_xml(original_xml)
+  # OLD:     qr_expire_ts = qr_data[:expire_ts] || generate_future_timestamp()
+  # OLD:     qr_ts = qr_data[:qr_ts] || generate_npci_timestamp()
+  # OLD:
+  # OLD:     Logger.info("[AccIp10Scenario]   • Request Msg ID: #{req_msg_id}")
+  # OLD:     Logger.info("[AccIp10Scenario]   • Transaction ID: #{txn_id}")
+  # OLD:     Logger.info("[AccIp10Scenario]   • Amount: #{amount} INR")
+  # OLD:     Logger.info("[AccIp10Scenario]   • Type: REVERSAL with subType: CREDIT")
+  # OLD:     Logger.info("[AccIp10Scenario]   • Response Code: CS (SUCCESS)")
+  # OLD:     Logger.info("[AccIp10Scenario]   • Settlement Amount: #{settlement_amount} #{settlement_currency}")
+  # OLD:
+  # OLD:     # Generate ACC_IP_10 compliant RespPay XML
+  # OLD:     resp_xml = """
+  # OLD:     <?xml version="1.0" encoding="UTF-8" standalone="no"?>
+  # OLD:     <upi:RespPay xmlns:upi="http://npci.org/upi/schema/">
+  # OLD:         <Head msgId="#{generate_msg_id()}"
+  # OLD:               orgId="MER101"
+  # OLD:               prodType="UPI"
+  # OLD:               ts="#{generate_npci_timestamp()}"
+  # OLD:               ver="2.0"/>
+  # OLD:         <Txn custRef="#{cust_ref}"
+  # OLD:              id="#{txn_id}"
+  # OLD:              initiationMode="16"
+  # OLD:              note="ACCIP10"
+  # OLD:              orgTxnId="#{org_txn_id}"
+  # OLD:              purpose="11"
+  # OLD:              refCategory="00"
+  # OLD:              refId="#{cust_ref}"
+  # OLD:              refUrl="https://mercurypay.aritic.app"
+  # OLD:              subType="CREDIT"
+  # OLD:              ts="#{generate_npci_timestamp()}"
+  # OLD:              type="REVERSAL">
+  # OLD:             <QR expireTs="#{qr_expire_ts}"
+  # OLD:                 qVer="02"
+  # OLD:                 qrMedium="03"
+  # OLD:                 stan="000125"
+  # OLD:                 ts="#{qr_ts}"/>
+  # OLD:         </Txn>
+  # OLD:         <Resp reqMsgId="#{req_msg_id}"
+  # OLD:               result="SUCCESS">
+  # OLD:             <Ref IFSC="AEBK0108766"
+  # OLD:                  acNum="AE123456781"
+  # OLD:                  accType="CURRENT"
+  # OLD:                  addr="#{@target_vpa}"
+  # OLD:                  approvalNum="#{generate_approval_num()}"
+  # OLD:                  code="5932"
+  # OLD:                  orgAmount="#{amount}"
+  # OLD:                  regName="Fujairah Fresh Foods"
+  # OLD:                  respCode="CS"
+  # OLD:                  seqNum="1"
+  # OLD:                  settAmount="#{settlement_amount}"
+  # OLD:                  settCurrency="#{settlement_currency}"
+  # OLD:                  type="PAYEE"/>
+  # OLD:         </Resp>
+  # OLD:         #{generate_signature_section()}
+  # OLD:     </upi:RespPay>
+  # OLD:     """
+  # OLD:
+  # OLD:     Logger.info("[AccIp10Scenario] ✅ Generated ACC_IP_10 RespPay XML successfully")
+  # OLD:     Logger.debug("[AccIp10Scenario] Generated XML (first 500 chars): #{String.slice(resp_xml, 0, 500)}")
+  # OLD:
+  # OLD:     resp_xml
+  # OLD:   end
+  # [RespPay-REVERSAL generate_resp_pay_accip10] CHANGED: defp -> def (@doc false) so the reversal builder can be unit-tested; callers are unchanged
+  # OLD:   defp generate_resp_pay_accip10(reversal_data, _original_xml) do
+  @doc false
+  def generate_resp_pay_accip10(reversal_data, _original_xml) do
+    Logger.info("[AccIp10Scenario] 📝 Generating ACC_IP_10 REVERSAL RespPay with UpiXmlSchema.generate_resp_pay")
 
-    Logger.info("[AccIp10Scenario] 📝 Generating SUCCESS RespPay using standard UpiXmlSchema:")
-    Logger.info("[AccIp10Scenario]   • Original reqMsgId: #{req_msg_id}")
-    Logger.info("[AccIp10Scenario]   • TxnId: #{txn_id}")
-    Logger.info("[AccIp10Scenario]   • Amount: #{amount} INR")
-    Logger.info("[AccIp10Scenario]   • Type: CREDIT (for accip10@mercury scenario)")
-    Logger.info("[AccIp10Scenario]   • QR ExpireTs: #{qr_data[:expire_ts]}")
-    Logger.info("[AccIp10Scenario]   • Settlement Amount: #{settlement_amount} #{settlement_currency}")
+    # [RespPay-REVERSAL Ref.addr / code / regName / IFSC / acNum / accType] CHANGED: values from the request, else from the stored original ReqPay
+    request_data =
+      UpiXmlSchema.fill_payee_from_stored_req_pay(reversal_data, find_stored_req_pay_for_reversal(reversal_data))
 
-    # Build response data in the format expected by UpiXmlSchema.generate_resp_pay
     response_data = %{
-      # Request identifiers
-      req_msg_id: req_msg_id,
-      msg_id: generate_msg_id(),
-      txn_id: txn_id,
-      org_txn_id: org_txn_id,
-
-      # Response details
+      org_id: "MER101",
+      req_msg_id: reversal_data[:msg_id],
       result: "SUCCESS",
-      err_code: "CS",
+      # [RespPay-REVERSAL Ref.reversalRespCode] ADDED: CS = credit stands (ACC_IP_10); Ref.respCode carries the same value
       resp_code: "CS",
+      reversal_resp_code: "CS",
       approval_num: generate_approval_num(),
-
-      # Transaction details (preserve original note)
-      note: parsed_data[:note] || parsed_data["note"] || "ACCIP10",
-      txn_type: "CREDIT",  # CREDIT type for accip10@mercury scenario
-      org_amount: amount,
-      sett_amount: settlement_amount,  # Use INR amount from QR payload
-      sett_currency: settlement_currency,  # Use INR from QR payload
-
-      # Payer information
-      payer_addr: payer_addr,
-      payer_name: payer_name,
-
-      # Payee information
-      payee_addr: @target_vpa,
-      payee_name: "ACC IP 10 Merchant",
-      payee_code: "0000",
-      reg_name: "ACC IP 10 Merchant",
-      ifsc: "SBIN0000001",
-      ac_num: "1234567890",
-      acc_type: "SAVINGS",
-
-      # QR information from original request
-      expire_ts: qr_data[:expire_ts],
-      qr_ver: qr_data[:qr_ver] || "02",
-      qr_medium: qr_data[:qr_medium] || "03",
-
-      # Timestamps and other metadata
-      head_ts: generate_npci_timestamp(),
-      txn_ts: generate_npci_timestamp(),
-      org_id: "MER101"  # Use PSP org ID per NPCI spec
+      txn_type: "REVERSAL",
+      sub_type: "CREDIT",
+      request_data: request_data
     }
 
-    # Add original request data as request_source for UpiXmlSchema
-    request_source = %{
-      expire_ts: qr_data[:expire_ts],
-      txn_id: txn_id,
-      note: parsed_data[:note] || parsed_data["note"] || "ACCIP10"
-    }
-
-    # Use standard UpiXmlSchema.generate_resp_pay function for ACC_IP_10 scenario
-    Logger.info("[AccIp10Scenario] Using standard UpiXmlSchema.generate_resp_pay for NPCI compliance")
-    case UpiXmlSchema.generate_resp_pay(response_data, request_source) do
-      {:ok, xml} ->
-        Logger.info("[AccIp10Scenario] ✅ Generated standard RespPay XML successfully")
-        xml
-      {:error, reason} ->
-        Logger.error("[AccIp10Scenario] ❌ Failed to generate standard RespPay: #{inspect(reason)}")
-        generate_fallback_resp_pay_xml(response_data)
-    end
+    {:ok, resp_xml} = UpiXmlSchema.generate_resp_pay(response_data)
+    resp_xml
   end
 
-  # Generate proper NPCI-compliant RespPay XML per NPCI Spec v1.7.2
-  defp generate_fallback_resp_pay_xml(data) do
-    Logger.warn("[AccIp10Scenario] Using NPCI v1.7.2 compliant RespPay XML generation")
-
-    """
-    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
-    <ns2:RespPay xmlns:ns2="http://npci.org/upi/schema/">
-      <Head ver="2.0" ts="#{generate_npci_timestamp()}" orgId="MER101" msgId="#{generate_msg_id()}"/>
-      <Txn id="#{data.txn_id}"
-           note="ACC_IP_10 Credit Success"
-           ts="#{generate_npci_timestamp()}"
-           type="CREDIT"
-           orgTxnId="#{data.org_txn_id}"
-           refId="#{data.org_txn_id}"
-           refUrl="">
-      </Txn>
-      <Resp reqMsgId="#{data.req_msg_id}" result="SUCCESS" errCode="CS" approvalNum="#{data.approval_num}"/>
-      <Payer addr="#{data.payer_addr}" name="#{data.payer_name}" seqNum="1" type="PERSON" code="0000"/>
-      <Payee addr="#{data.payee_addr}" name="#{data.payee_name}" seqNum="2" type="ENTITY" code="0000"/>
-      <Amount value="#{data.amount}" curr="INR"/>
-    </ns2:RespPay>
-    """
-  end
+  # [RespPay-REVERSAL Ref.*] ADDED: the stored original ReqPay of a reversal (reversal Txn orgTxnId = original Txn id)
+  defp find_stored_req_pay_for_reversal(reversal_data) do
+    org_txn_id = reversal_data[:org_txn_id]
 
-  defp generate_msg_id do
-    "MSG" <> (:crypto.strong_rand_bytes(8) |> Base.encode16())
-  end
+    if is_binary(org_txn_id) and org_txn_id != "" do
+      from(rp in ReqPay, where: rp.txn_id == ^org_txn_id, order_by: [desc: rp.inserted_at], limit: 1)
+      |> Repo.one()
+    end
+  rescue
+    # [RespPay-REVERSAL Ref.*] CHANGED: also catch :exit - a Repo call without a DB connection / sandbox owner exits instead of raising; the stored ReqPay is optional
+    # OLD:     _ -> nil
+    _ -> nil
+  catch
+    :exit, _ -> nil
+  end
+
+  # [RespPay-REVERSAL generate_resp_pay/2] REMOVED: generate_success_resp_pay (clause) is unused now - dead code since the baseline (never called); its generate_resp_pay/2 call was corrected to /1 above and the reversal is built by generate_resp_pay_accip10
+  # OLD:   defp generate_success_resp_pay(parsed_data, original_xml \\ nil) do
+  # OLD:     # Generate RespPay XML using the standard UpiXmlSchema.generate_resp_pay function
+  # OLD:     # This ensures proper NPCI compliance and formatting
+  # OLD:
+  # OLD:     # Extract settlement info from QR payload - ensures INR values
+  # OLD:     qr_payload = parsed_data[:qr_payload] || parsed_data["qr_payload"] || ""
+  # OLD:     {settlement_currency, settlement_amount} = extract_settlement_info_from_qr_payload(qr_payload)
+  # OLD:
+  # OLD:     # Extract data from the reversal request
+  # OLD:     req_msg_id = parsed_data[:msg_id] || parsed_data["msg_id"] || generate_msg_id()
+  # OLD:     txn_id = parsed_data[:txn_id] || parsed_data["txn_id"] || generate_txn_id()
+  # OLD:     org_txn_id = parsed_data[:org_txn_id] || parsed_data["org_txn_id"] || txn_id
+  # OLD:
+  # OLD:     # Extract amount and payer details from the request
+  # OLD:     amount = parsed_data[:payee_amount] || parsed_data[:amount] || parsed_data["payee_amount"] ||
+  # OLD:              parsed_data["amount"] || settlement_amount || "100.00"
+  # OLD:     payer_addr = parsed_data[:payer_addr] || parsed_data["payer_addr"] || "testpayer@upi"
+  # OLD:     payer_name = parsed_data[:payer_name] || parsed_data["payer_name"] || "Test Payer"
+  # OLD:
+  # OLD:     # Extract QR data from original XML if available
+  # OLD:     qr_data = if original_xml do
+  # OLD:       extract_qr_data_from_xml(original_xml)
+  # OLD:     else
+  # OLD:       %{}
+  # OLD:     end
+  # OLD:
+  # OLD:     Logger.info("[AccIp10Scenario] 📝 Generating SUCCESS RespPay using standard UpiXmlSchema:")
+  # OLD:     Logger.info("[AccIp10Scenario]   • Original reqMsgId: #{req_msg_id}")
+  # OLD:     Logger.info("[AccIp10Scenario]   • TxnId: #{txn_id}")
+  # OLD:     Logger.info("[AccIp10Scenario]   • Amount: #{amount} INR")
+  # OLD:     Logger.info("[AccIp10Scenario]   • Type: CREDIT (for accip10@mercury scenario)")
+  # OLD:     Logger.info("[AccIp10Scenario]   • QR ExpireTs: #{qr_data[:expire_ts]}")
+  # OLD:     Logger.info("[AccIp10Scenario]   • Settlement Amount: #{settlement_amount} #{settlement_currency}")
+  # OLD:
+  # OLD:     # Build response data in the format expected by UpiXmlSchema.generate_resp_pay
+  # OLD:     response_data = %{
+  # OLD:       # Request identifiers
+  # OLD:       req_msg_id: req_msg_id,
+  # OLD:       msg_id: generate_msg_id(),
+  # OLD:       txn_id: txn_id,
+  # OLD:       org_txn_id: org_txn_id,
+  # OLD:
+  # OLD:       # Response details
+  # OLD:       result: "SUCCESS",
+  # OLD:       err_code: "CS",
+  # OLD:       resp_code: "CS",
+  # OLD:       approval_num: generate_approval_num(),
+  # OLD:
+  # OLD:       # Transaction details (preserve original note)
+  # OLD:       note: parsed_data[:note] || parsed_data["note"] || "ACCIP10",
+  # OLD:       txn_type: "CREDIT",  # CREDIT type for accip10@mercury scenario
+  # OLD:       org_amount: amount,
+  # OLD:       sett_amount: settlement_amount,  # Use INR amount from QR payload
+  # OLD:       sett_currency: settlement_currency,  # Use INR from QR payload
+  # OLD:
+  # OLD:       # Payer information
+  # OLD:       payer_addr: payer_addr,
+  # OLD:       payer_name: payer_name,
+  # OLD:
+  # OLD:       # Payee information
+  # OLD:       # [RespPay-REVERSAL Ref.*] REMOVED: invented payee values (ACC IP 10 Merchant, 0000, SBIN0000001, 1234567890, SAVINGS); Ref comes from the request / stored ReqPay
+  # OLD:       # OLD:       payee_addr: @target_vpa,
+  # OLD:       # OLD:       payee_name: "ACC IP 10 Merchant",
+  # OLD:       # OLD:       payee_code: "0000",
+  # OLD:       # OLD:       reg_name: "ACC IP 10 Merchant",
+  # OLD:       # OLD:       ifsc: "SBIN0000001",
+  # OLD:       # OLD:       ac_num: "1234567890",
+  # OLD:       # OLD:       acc_type: "SAVINGS",
+  # OLD:
+  # OLD:       # QR information from original request
+  # OLD:       # [RespPay-REVERSAL QR.expireTs / qVer / qrMedium] CHANGED: no invented 02 / 03 defaults
+  # OLD:       # OLD:       expire_ts: qr_data[:expire_ts],
+  # OLD:       # OLD:       qr_ver: qr_data[:qr_ver] || "02",
+  # OLD:       # OLD:       qr_medium: qr_data[:qr_medium] || "03",
+  # OLD:       expire_ts: qr_data[:expire_ts],
+  # OLD:       qr_ver: qr_data[:qr_ver],
+  # OLD:       qr_medium: qr_data[:qr_medium],
+  # OLD:
+  # OLD:       # Timestamps and other metadata
+  # OLD:       head_ts: generate_npci_timestamp(),
+  # OLD:       txn_ts: generate_npci_timestamp(),
+  # OLD:       org_id: "MER101"  # Use PSP org ID per NPCI spec
+  # OLD:     }
+  # OLD:
+  # OLD:     # [RespPay-REVERSAL generate_resp_pay request] CHANGED: the whole parsed reversal ReqPay is the request (request_source with only expire_ts / txn_id / note is gone)
+  # OLD:     # OLD:     # Add original request data as request_source for UpiXmlSchema
+  # OLD:     # OLD:     request_source = %{
+  # OLD:     # OLD:       expire_ts: qr_data[:expire_ts],
+  # OLD:     # OLD:       txn_id: txn_id,
+  # OLD:     # OLD:       note: parsed_data[:note] || parsed_data["note"] || "ACCIP10"
+  # OLD:     # OLD:     }
+  # OLD:
+  # OLD:     # Use standard UpiXmlSchema.generate_resp_pay function for ACC_IP_10 scenario
+  # OLD:     Logger.info("[AccIp10Scenario] Using standard UpiXmlSchema.generate_resp_pay for NPCI compliance")
+  # OLD:     # [RespPay-REVERSAL generate_resp_pay/2] CHANGED: only generate_resp_pay/1 exists (the /2 call could never compile-run); request goes in as :request_data
+  # OLD:     # OLD:     case UpiXmlSchema.generate_resp_pay(response_data, request_source) do
+  # OLD:     case UpiXmlSchema.generate_resp_pay(Map.put(response_data, :request_data, parsed_data)) do
+  # OLD:       {:ok, xml} ->
+  # OLD:         Logger.info("[AccIp10Scenario] ✅ Generated standard RespPay XML successfully")
+  # OLD:         xml
+  # OLD:       {:error, reason} ->
+  # OLD:         Logger.error("[AccIp10Scenario] ❌ Failed to generate standard RespPay: #{inspect(reason)}")
+  # OLD:         generate_fallback_resp_pay_xml(response_data)
+  # OLD:     end
+  # OLD:   end
 
-  defp generate_txn_id do
-    "TXN" <> (:crypto.strong_rand_bytes(8) |> Base.encode16())
-  end
+  # Generate proper NPCI-compliant RespPay XML per NPCI Spec v1.7.2
+  # [RespPay-REVERSAL generate_resp_pay/2] REMOVED: generate_fallback_resp_pay_xml (clause) is unused now - dead code since the baseline (never called); its generate_resp_pay/2 call was corrected to /1 above and the reversal is built by generate_resp_pay_accip10
+  # OLD:   defp generate_fallback_resp_pay_xml(data) do
+  # OLD:     Logger.warn("[AccIp10Scenario] Using NPCI v1.7.2 compliant RespPay XML generation")
+  # OLD:
+  # OLD:     """
+  # OLD:     <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+  # OLD:     <ns2:RespPay xmlns:ns2="http://npci.org/upi/schema/">
+  # OLD:       <Head ver="2.0" ts="#{generate_npci_timestamp()}" orgId="MER101" msgId="#{generate_msg_id()}"/>
+  # OLD:       <Txn id="#{data.txn_id}"
+  # OLD:            note="ACC_IP_10 Credit Success"
+  # OLD:            ts="#{generate_npci_timestamp()}"
+  # OLD:            type="CREDIT"
+  # OLD:            orgTxnId="#{data.org_txn_id}"
+  # OLD:            refId="#{data.org_txn_id}"
+  # OLD:            refUrl="">
+  # OLD:       </Txn>
+  # OLD:       <Resp reqMsgId="#{data.req_msg_id}" result="SUCCESS" errCode="CS" approvalNum="#{data.approval_num}"/>
+  # OLD:       <Payer addr="#{data.payer_addr}" name="#{data.payer_name}" seqNum="1" type="PERSON" code="0000"/>
+  # OLD:       <Payee addr="#{data.payee_addr}" name="#{data.payee_name}" seqNum="2" type="ENTITY" code="0000"/>
+  # OLD:       <Amount value="#{data.amount}" curr="INR"/>
+  # OLD:     </ns2:RespPay>
+  # OLD:     """
+  # OLD:   end
+
+  # [RespPay-REVERSAL <Resp> template] REMOVED: generate_msg_id (clause) is unused now - the hand-built reversal XML moved to UpiXmlSchema.generate_resp_pay
+  # OLD:   defp generate_msg_id do
+  # OLD:     "MSG" <> (:crypto.strong_rand_bytes(8) |> Base.encode16())
+  # OLD:   end
+
+  # [RespPay-REVERSAL <Resp> template] REMOVED: generate_txn_id (clause) is unused now - the hand-built reversal XML moved to UpiXmlSchema.generate_resp_pay
+  # OLD:   defp generate_txn_id do
+  # OLD:     "TXN" <> (:crypto.strong_rand_bytes(8) |> Base.encode16())
+  # OLD:   end
 
   defp generate_approval_num do
     # Generate 6 character approval number: APP + 3 digits (e.g., APP000, APP123)
@@ -605,48 +663,55 @@ defmodule UpiDynamic.SpecialHandlers.AccIp10Scenario do
     "APP" <> String.pad_leading(Integer.to_string(random_number), 3, "0")
   end
 
-  defp extract_qr_data_from_xml(xml_string) when is_binary(xml_string) do
-    Logger.debug("[AccIp10Scenario] Extracting QR data from original XML")
-
-    # Extract QR expireTs using regex
-    expire_ts = case Regex.run(~r/expireTs="([^"]+)"/, xml_string) do
-      [_, ts] ->
-        Logger.debug("[AccIp10Scenario] Found QR expireTs: #{ts}")
-        ts
-      _ ->
-        Logger.warn("[AccIp10Scenario] QR expireTs not found in XML")
-        nil
-    end
-
-    # Extract QR version
-    qr_ver = case Regex.run(~r/qVer="([^"]+)"/, xml_string) do
-      [_, ver] -> ver
-      _ -> "02"  # Default
-    end
-
-    # Extract QR medium
-    qr_medium = case Regex.run(~r/qrMedium="([^"]+)"/, xml_string) do
-      [_, medium] -> medium
-      _ -> "03"  # Default
-    end
-
-    %{
-      expire_ts: expire_ts,
-      qr_ver: qr_ver,
-      qr_medium: qr_medium
-    }
-  end
-
-  defp extract_qr_data_from_xml(_), do: %{}
-
-  defp generate_npci_timestamp do
-    # Generate NPCI-compliant timestamp with +05:30 offset (IST)
-    # Format: YYYY-MM-DDTHH:MM:SS+05:30
-    DateTime.now!("Asia/Kolkata")
-    |> DateTime.to_iso8601()
-    |> String.replace("Z", "+05:30")
-    |> String.replace(~r/\.\d+\+/, "+")  # Remove microseconds but keep offset
-  end
+  # [RespPay-REVERSAL <Resp> template] REMOVED: extract_qr_data_from_xml (clause) is unused now - the hand-built reversal XML moved to UpiXmlSchema.generate_resp_pay
+  # OLD:   defp extract_qr_data_from_xml(xml_string) when is_binary(xml_string) do
+  # OLD:     Logger.debug("[AccIp10Scenario] Extracting QR data from original XML")
+  # OLD:
+  # OLD:     # Extract QR expireTs using regex
+  # OLD:     expire_ts = case Regex.run(~r/expireTs="([^"]+)"/, xml_string) do
+  # OLD:       [_, ts] ->
+  # OLD:         Logger.debug("[AccIp10Scenario] Found QR expireTs: #{ts}")
+  # OLD:         ts
+  # OLD:       _ ->
+  # OLD:         Logger.warn("[AccIp10Scenario] QR expireTs not found in XML")
+  # OLD:         nil
+  # OLD:     end
+  # OLD:
+  # OLD:     # Extract QR version
+  # OLD:     qr_ver = case Regex.run(~r/qVer="([^"]+)"/, xml_string) do
+  # OLD:       [_, ver] -> ver
+  # OLD:       # [RespPay-REVERSAL QR.qVer] CHANGED: no invented default 02
+  # OLD:       # OLD:       _ -> "02"  # Default
+  # OLD:       _ -> nil
+  # OLD:     end
+  # OLD:
+  # OLD:     # Extract QR medium
+  # OLD:     qr_medium = case Regex.run(~r/qrMedium="([^"]+)"/, xml_string) do
+  # OLD:       [_, medium] -> medium
+  # OLD:       # [RespPay-REVERSAL QR.qrMedium] CHANGED: no invented default 03
+  # OLD:       # OLD:       _ -> "03"  # Default
+  # OLD:       _ -> nil
+  # OLD:     end
+  # OLD:
+  # OLD:     %{
+  # OLD:       expire_ts: expire_ts,
+  # OLD:       qr_ver: qr_ver,
+  # OLD:       qr_medium: qr_medium
+  # OLD:     }
+  # OLD:   end
+
+  # [RespPay-REVERSAL <Resp> template] REMOVED: extract_qr_data_from_xml (clause) is unused now - the hand-built reversal XML moved to UpiXmlSchema.generate_resp_pay
+  # OLD:   defp extract_qr_data_from_xml(_), do: %{}
+
+  # [RespPay-REVERSAL <Resp> template] REMOVED: generate_npci_timestamp (clause) is unused now - the hand-built reversal XML moved to UpiXmlSchema.generate_resp_pay
+  # OLD:   defp generate_npci_timestamp do
+  # OLD:     # Generate NPCI-compliant timestamp with +05:30 offset (IST)
+  # OLD:     # Format: YYYY-MM-DDTHH:MM:SS+05:30
+  # OLD:     DateTime.now!("Asia/Kolkata")
+  # OLD:     |> DateTime.to_iso8601()
+  # OLD:     |> String.replace("Z", "+05:30")
+  # OLD:     |> String.replace(~r/\.\d+\+/, "+")  # Remove microseconds but keep offset
+  # OLD:   end
 
   @doc """
   Send RespPay to NPCI with comprehensive ACK parsing and logging for ACC_IP_10 scenario
@@ -805,36 +870,37 @@ defmodule UpiDynamic.SpecialHandlers.AccIp10Scenario do
     final_url
   end
 
-  defp generate_signature_section do
-    # Generate signature placeholder for ACC_IP_10 RespPay
-    # In production, this would contain actual digital signature
-    signature_value = generate_signature_value()
-
-    """
-        <Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
-            <SignedInfo>
-                <CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>
-                <SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"/>
-                <Reference URI="">
-                    <Transforms>
-                        <Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/>
-                    </Transforms>
-                    <DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/>
-                    <DigestValue>NBY7jHmq6eYQTPTKr5tanMvGPd3HIRXasQYO1gOtSSw=</DigestValue>
-                </Reference>
-            </SignedInfo>
-            <SignatureValue>#{signature_value}</SignatureValue>
-            <KeyInfo>
-                <KeyValue>
-                    <RSAKeyValue>
-                        <Modulus>wWXCG5Wc7AWtDBzyB1ksRITjMy85NMzGbdRdGL3jiB8S2kHq6F7vaAv53svriaRpIF2MexXebInAroX2j7e35e+/zO9EgC8Fcz89GLPrPLAOkAszNw9Ckhbr6vI8ZL8B5/wY2dakv7OFw4w8Z2jo0rPrhMqKxPvXAQDLRTqja0cOeuRh6w0yXDq7vamZKTvrMAGEephhOo0zA4+OqmunJs7eEUcMLINbEghPVfUmoNKVlkV0RnbkLkwEf8Ha+Qy0M0M1xsifnWJYpC5N267unvMIYXnNtg7rl0UTe1wbEElvjoIK6lWW8JBpoIt/5ybxqHBqTG9+IiPcLD2aecYI1Q==</Modulus>
-                        <Exponent>AQAB</Exponent>
-                    </RSAKeyValue>
-                </KeyValue>
-            </KeyInfo>
-        </Signature>
-    """
-  end
+  # [RespPay-REVERSAL <Resp> template] REMOVED: generate_signature_section (clause) is unused now - the hand-built reversal XML moved to UpiXmlSchema.generate_resp_pay
+  # OLD:   defp generate_signature_section do
+  # OLD:     # Generate signature placeholder for ACC_IP_10 RespPay
+  # OLD:     # In production, this would contain actual digital signature
+  # OLD:     signature_value = generate_signature_value()
+  # OLD:
+  # OLD:     """
+  # OLD:         <Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
+  # OLD:             <SignedInfo>
+  # OLD:                 <CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>
+  # OLD:                 <SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"/>
+  # OLD:                 <Reference URI="">
+  # OLD:                     <Transforms>
+  # OLD:                         <Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/>
+  # OLD:                     </Transforms>
+  # OLD:                     <DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/>
+  # OLD:                     <DigestValue>NBY7jHmq6eYQTPTKr5tanMvGPd3HIRXasQYO1gOtSSw=</DigestValue>
+  # OLD:                 </Reference>
+  # OLD:             </SignedInfo>
+  # OLD:             <SignatureValue>#{signature_value}</SignatureValue>
+  # OLD:             <KeyInfo>
+  # OLD:                 <KeyValue>
+  # OLD:                     <RSAKeyValue>
+  # OLD:                         <Modulus>wWXCG5Wc7AWtDBzyB1ksRITjMy85NMzGbdRdGL3jiB8S2kHq6F7vaAv53svriaRpIF2MexXebInAroX2j7e35e+/zO9EgC8Fcz89GLPrPLAOkAszNw9Ckhbr6vI8ZL8B5/wY2dakv7OFw4w8Z2jo0rPrhMqKxPvXAQDLRTqja0cOeuRh6w0yXDq7vamZKTvrMAGEephhOo0zA4+OqmunJs7eEUcMLINbEghPVfUmoNKVlkV0RnbkLkwEf8Ha+Qy0M0M1xsifnWJYpC5N267unvMIYXnNtg7rl0UTe1wbEElvjoIK6lWW8JBpoIt/5ybxqHBqTG9+IiPcLD2aecYI1Q==</Modulus>
+  # OLD:                         <Exponent>AQAB</Exponent>
+  # OLD:                     </RSAKeyValue>
+  # OLD:                 </KeyValue>
+  # OLD:             </KeyInfo>
+  # OLD:         </Signature>
+  # OLD:     """
+  # OLD:   end
 
   # Helper function to build ReqPay attributes from parsed data
   defp build_req_pay_attrs_from_parsed_data(parsed_data) do
@@ -895,37 +961,42 @@ defmodule UpiDynamic.SpecialHandlers.AccIp10Scenario do
     {:ok, resp_pay_xml}
   end
 
-  defp generate_signature_value do
-    # Generate mock signature value for testing
-    # In production, this would be actual cryptographic signature
-    :crypto.strong_rand_bytes(256) |> Base.encode64()
-  end
-
-  defp generate_future_timestamp do
-    # Generate a timestamp 30 minutes in the future for QR expiry
-    DateTime.now!("Asia/Kolkata")
-    |> DateTime.add(30 * 60, :second)  # 30 minutes
-    |> DateTime.to_iso8601()
-    |> String.replace("Z", "+05:30")
-    |> String.replace(~r/\.\d+\+/, "+")  # Remove microseconds but keep offset
-  end
-
-  @doc false
+  # [RespPay-REVERSAL <Resp> template] REMOVED: generate_signature_value (clause) is unused now - the hand-built reversal XML moved to UpiXmlSchema.generate_resp_pay
+  # OLD:   defp generate_signature_value do
+  # OLD:     # Generate mock signature value for testing
+  # OLD:     # In production, this would be actual cryptographic signature
+  # OLD:     :crypto.strong_rand_bytes(256) |> Base.encode64()
+  # OLD:   end
+
+  # [RespPay-REVERSAL <Resp> template] REMOVED: generate_future_timestamp (clause) is unused now - the hand-built reversal XML moved to UpiXmlSchema.generate_resp_pay
+  # OLD:   defp generate_future_timestamp do
+  # OLD:     # Generate a timestamp 30 minutes in the future for QR expiry
+  # OLD:     DateTime.now!("Asia/Kolkata")
+  # OLD:     |> DateTime.add(30 * 60, :second)  # 30 minutes
+  # OLD:     |> DateTime.to_iso8601()
+  # OLD:     |> String.replace("Z", "+05:30")
+  # OLD:     |> String.replace(~r/\.\d+\+/, "+")  # Remove microseconds but keep offset
+  # OLD:   end
+
+  # [RespPay-REVERSAL @doc false] REMOVED: it documented extract_settlement_info_from_qr_payload, which is commented out; left alone it would attach to nothing
+  # OLD:   @doc false
   # Extract settlement currency and amount from QR payload
-  defp extract_settlement_info_from_qr_payload(qr_payload) when is_binary(qr_payload) and qr_payload != "" do
-    # Extract settlement currency - look for cu= parameter (INR)
-    settlement_currency = case Regex.run(~r/[?&]cu=([A-Z]{3})/, qr_payload) do
-      [_, currency] -> currency
-      _ -> "INR"
-    end
-
-    # Extract settlement amount - look for am= parameter (INR debit amount)
-    settlement_amount = case Regex.run(~r/[?&]am=([0-9.]+)/, qr_payload) do
-      [_, amount] -> amount
-      _ -> "0.00"
-    end
-
-    {settlement_currency, settlement_amount}
-  end
-  defp extract_settlement_info_from_qr_payload(_), do: {"INR", "0.00"}
+  # [RespPay-REVERSAL <Resp> template] REMOVED: extract_settlement_info_from_qr_payload (clause) is unused now - the hand-built reversal XML moved to UpiXmlSchema.generate_resp_pay
+  # OLD:   defp extract_settlement_info_from_qr_payload(qr_payload) when is_binary(qr_payload) and qr_payload != "" do
+  # OLD:     # Extract settlement currency - look for cu= parameter (INR)
+  # OLD:     settlement_currency = case Regex.run(~r/[?&]cu=([A-Z]{3})/, qr_payload) do
+  # OLD:       [_, currency] -> currency
+  # OLD:       _ -> "INR"
+  # OLD:     end
+  # OLD:
+  # OLD:     # Extract settlement amount - look for am= parameter (INR debit amount)
+  # OLD:     settlement_amount = case Regex.run(~r/[?&]am=([0-9.]+)/, qr_payload) do
+  # OLD:       [_, amount] -> amount
+  # OLD:       _ -> "0.00"
+  # OLD:     end
+  # OLD:
+  # OLD:     {settlement_currency, settlement_amount}
+  # OLD:   end
+  # [RespPay-REVERSAL <Resp> template] REMOVED: extract_settlement_info_from_qr_payload (clause) is unused now - the hand-built reversal XML moved to UpiXmlSchema.generate_resp_pay
+  # OLD:   defp extract_settlement_info_from_qr_payload(_), do: {"INR", "0.00"}
 end
diff --git a/apps/upi_dynamic/lib/upi_dynamic/special_handlers/timeout_simulation_handler.ex b/apps/upi_dynamic/lib/upi_dynamic/special_handlers/timeout_simulation_handler.ex
index 0646ec5..82b0ab0 100644
--- a/apps/upi_dynamic/lib/upi_dynamic/special_handlers/timeout_simulation_handler.ex
+++ b/apps/upi_dynamic/lib/upi_dynamic/special_handlers/timeout_simulation_handler.ex
@@ -8,7 +8,10 @@ defmodule UpiDynamic.SpecialHandlers.TimeoutSimulationHandler do
   3. ReqPay (REVERSAL) - Send successful RespPay reversal
   """
 
-  alias UpiDynamic.{UpiXmlSchema, UpiTransactionManager}
+  # [RespPay-REVERSAL ACC_IP_09 UpiXmlSchema] CHANGED: UpiDynamic.UpiXmlSchema does not exist, so generate_reversal_success_response crashed (UndefinedFunctionError); the schema module is UpiCore.UpiXmlSchema
+  # OLD:   alias UpiDynamic.{UpiXmlSchema, UpiTransactionManager}
+  alias UpiCore.UpiXmlSchema
+  alias UpiDynamic.UpiTransactionManager
 
   require Logger
 
@@ -171,23 +174,36 @@ defmodule UpiDynamic.SpecialHandlers.TimeoutSimulationHandler do
 
       # Payee details
       seq_num: "1",
-      payee_addr: @timeout_vpa,
-      payee_code: Map.get(parsed_data, :payee_code, "5912"),
+      # [RespPay-REVERSAL Ref.addr / Ref.code] CHANGED: the scenario VPA constant and the dummy MCC 5912 are gone - the request's Payee is echoed by generate_resp_pay
+      # OLD:       payee_addr: @timeout_vpa,
+      # OLD:       payee_code: Map.get(parsed_data, :payee_code, "5912"),
+      payee_addr: Map.get(parsed_data, :payee_addr),
+      payee_code: Map.get(parsed_data, :payee_code),
       org_amount: Map.get(parsed_data, :payee_amount, "0.00"),
       resp_code: "00",  # Success
-      reg_name: Map.get(parsed_data, :payee_name, "Test Merchant"),
-      ifsc: Map.get(parsed_data, :payee_ifsc, "AEBK0098765"),
-      ac_num: Map.get(parsed_data, :payee_ac_num, "AE987654321"),
-      acc_type: Map.get(parsed_data, :payee_ac_type, "CURRENT"),
+      # [RespPay-REVERSAL Ref.regName / IFSC / acNum / accType] CHANGED: no invented Test Merchant / AEBK0098765 / AE987654321 / CURRENT
+      # OLD:       reg_name: Map.get(parsed_data, :payee_name, "Test Merchant"),
+      # OLD:       ifsc: Map.get(parsed_data, :payee_ifsc, "AEBK0098765"),
+      # OLD:       ac_num: Map.get(parsed_data, :payee_ac_num, "AE987654321"),
+      # OLD:       acc_type: Map.get(parsed_data, :payee_ac_type, "CURRENT"),
+      reg_name: Map.get(parsed_data, :payee_name),
+      ifsc: Map.get(parsed_data, :payee_ifsc),
+      ac_num: Map.get(parsed_data, :payee_ac_num),
+      acc_type: Map.get(parsed_data, :payee_ac_type),
       approval_num: generate_approval_number(),
       sett_amount: Map.get(parsed_data, :payee_amount, "0.00"),
-      sett_currency: "AED",
-      initiation_mode: "16",
+      # [RespPay-REVERSAL Ref.settCurrency / Txn.initiationMode / Ref.reversalRespCode] CHANGED: settCurrency INR (was AED); initiationMode is echoed from the request (was fixed 16); reversalRespCode 00 = reversed ADDED
+      # TSD Table 4: settCurrency INR; REVERSAL carries Ref reversalRespCode (00 = reversed)
+      # OLD:       sett_currency: "AED",
+      # OLD:       initiation_mode: "16",
+      sett_currency: "INR",
+      reversal_resp_code: "00",
 
       # QR details
-      qr_ver: "02",
-      qr_medium: "03",
-      expire_ts: DateTime.utc_now() |> DateTime.add(1800, :second) |> DateTime.to_iso8601(),
+      # [RespPay-REVERSAL QR.qVer / QR.qrMedium / QR.expireTs] CHANGED: the generated UTC "...Z" expiry (now+30min) and the fixed 02 / 03 are gone - the ReqPay QR element is echoed
+      # OLD:       qr_ver: "02",
+      # OLD:       qr_medium: "03",
+      # OLD:       expire_ts: DateTime.utc_now() |> DateTime.add(1800, :second) |> DateTime.to_iso8601(),
 
       # Request data for XML generation
       request_data: parsed_data
diff --git a/apps/upi_dynamic/test/upi_dynamic/resp_pay_reversal_test.exs b/apps/upi_dynamic/test/upi_dynamic/resp_pay_reversal_test.exs
new file mode 100644
index 0000000..d16f9cd
--- /dev/null
+++ b/apps/upi_dynamic/test/upi_dynamic/resp_pay_reversal_test.exs
@@ -0,0 +1,80 @@
+defmodule UpiDynamic.RespPayReversalTest do
+  use ExUnit.Case, async: false
+
+  import SweetXml
+
+  @key_path Path.expand("../../../../private.pem", __DIR__)
+
+  @reversal %{
+    msg_id: "NPCIREVERSAL000000000000000000001",
+    txn_id: "NPCIREVTXN0001",
+    org_txn_id: "ORGTXN0001",
+    note: "ACC_IP_10 reversal",
+    cust_ref: "CUSTREF10",
+    ref_id: "REFNPCI0010",
+    ref_category: "00",
+    txn_type: "REVERSAL",
+    sub_type: "CREDIT",
+    purpose: "11",
+    initiation_mode: "16",
+    txn_ts: "2026-07-09T14:50:00+05:30",
+    qr_ver: "01",
+    qr_ts: "2026-07-09T14:46:11+05:30",
+    qr_medium: "03",
+    expire_ts: "2026-07-09T15:16:11+05:30",
+    payee_addr: "accip10@mercury",
+    payee_name: "NPCI Tester",
+    payee_code: "5812",
+    payee_ifsc: "TEST0000001",
+    payee_ac_num: "TESTACNUM0010",
+    payee_ac_type: "CURRENT",
+    payee_amount: "5.00"
+  }
+
+  setup do
+    previous = Application.get_env(:upi_core, :xml_signing_priv_key_path)
+    Application.put_env(:upi_core, :xml_signing_priv_key_path, @key_path)
+
+    on_exit(fn ->
+      if previous,
+        do: Application.put_env(:upi_core, :xml_signing_priv_key_path, previous),
+        else: Application.delete_env(:upi_core, :xml_signing_priv_key_path)
+    end)
+
+    :ok
+  end
+
+  defp attr(xml, path), do: xpath(xml, ~x"#{path}"s)
+  @ref "//*[local-name()='Ref']"
+
+  defp assert_reversal(xml, code) do
+    assert attr(xml, "//*[local-name()='Txn']/@type") == "REVERSAL"
+    assert attr(xml, "//*[local-name()='Txn']/@subType") == "CREDIT"
+    assert attr(xml, "//*[local-name()='Txn']/@refId") == "REFNPCI0010"
+    assert attr(xml, "//*[local-name()='Txn']/@ts") == "2026-07-09T14:50:00+05:30"
+    assert attr(xml, "//*[local-name()='QR']/@expireTs") == "2026-07-09T15:16:11+05:30"
+    assert attr(xml, "//*[local-name()='QR']/@qVer") == "01"
+    assert attr(xml, @ref <> "/@respCode") == code
+    assert attr(xml, @ref <> "/@reversalRespCode") == code
+    assert attr(xml, @ref <> "/@settCurrency") == "INR"
+    assert attr(xml, @ref <> "/@regName") == "NPCI Tester"
+    assert attr(xml, @ref <> "/@acNum") == "TESTACNUM0010"
+    assert attr(xml, "//*[local-name()='Resp']/@errCode") == ""
+    assert attr(xml, "//*[local-name()='Head']/@msgId") =~ ~r/^MER[0-9a-f]{32}$/
+    refute xml =~ "AEBK0108766"
+    refute xml =~ "Fujairah"
+    refute xml =~ "AEBK0098765"
+  end
+
+  test "ACC_IP_10 (dynamic copy) - CS reversal from the ReqPay" do
+    xml = UpiDynamic.SpecialHandlers.AccIp10Scenario.generate_resp_pay_accip10(@reversal, "<ignored/>")
+    assert_reversal(xml, "CS")
+    assert attr(xml, "//*[local-name()='Head']/@orgId") == "MER101"
+  end
+
+  test "ACC_IP_09 (dynamic timeout simulation) - 00 reversal, INR, QR echoed" do
+    {:ok, xml} = UpiDynamic.SpecialHandlers.TimeoutSimulationHandler.generate_reversal_success_response(@reversal)
+    assert_reversal(xml, "00")
+    refute xml =~ ~r/expireTs="[^"]*Z"/
+  end
+end
diff --git a/apps/upi_static/lib/upi_static/special_handlers/static_acc_ip_10_scenario.ex b/apps/upi_static/lib/upi_static/special_handlers/static_acc_ip_10_scenario.ex
index b6c43d4..99c4ffa 100644
--- a/apps/upi_static/lib/upi_static/special_handlers/static_acc_ip_10_scenario.ex
+++ b/apps/upi_static/lib/upi_static/special_handlers/static_acc_ip_10_scenario.ex
@@ -327,101 +327,153 @@ defmodule UpiStatic.SpecialHandlers.StaticAccIp10Scenario do
     _ -> nil
   end
 
-  defp generate_resp_pay_static_accip10(reversal_data, original_xml) do
-    Logger.info("[StaticAccIp10Scenario] 📝 Generating static ACC_IP_10 specific RespPay XML")
-
-    # --- 1. Extract all required data from the reversal_data map ---
-    req_msg_id = reversal_data[:msg_id] || ""
-    txn_id = reversal_data[:txn_id] || ""
-    org_txn_id = reversal_data[:org_txn_id] || ""
-    amount = reversal_data[:amount] || "0.00"
-    initiation_mode = reversal_data[:initiation_mode] || reversal_data[:initiationMode] || "02"
-    cust_ref = validate_and_extract_cust_ref(reversal_data, original_xml)
-
-    # Extract QR data with fallbacks
-    qr_data = extract_qr_data_from_xml(original_xml)
-    qr_expire_ts = qr_data[:expire_ts] || generate_future_timestamp()
-    q_ver = qr_data[:q_ver] || "02"
-    qr_medium = qr_data[:qr_medium] || "03"
-
-    # Extract Payee Account Details
-    payee_details = get_in(reversal_data, [:payees, 0, :ac, :details]) || []
-    payee_ac_num =
-      (Enum.find(payee_details, &(&1[:name] == "ACNUM")) || %{})[:value] || "1234567890"
-    payee_ifsc =
-      (Enum.find(payee_details, &(&1[:name] == "IFSC")) || %{})[:value] || "MERC0000001"
-
-    # --- 2. Log extracted data for debugging ---
-    Logger.info("[StaticAccIp10Scenario]   • Request Msg ID: #{req_msg_id}")
-    Logger.info("[StaticAccIp10Scenario]   • Transaction ID: #{txn_id}")
-    Logger.info("[StaticAccIp10Scenario]   • Amount: #{amount} INR")
-    Logger.info("[StaticAccIp10Scenario]   • Type: REVERSAL with subType: CREDIT")
-    Logger.info("[StaticAccIp10Scenario]   • Response Code: CS (SUCCESS)")
-    Logger.info("[StaticAccIp10Scenario]   • Static OrgId: MER102")
-    Logger.info("[StaticAccIp10Scenario]   • Static NetInstId: MER1020002")
-    Logger.info("[StaticAccIp10Scenario]   • Initiation Mode (from ReqPay): #{initiation_mode}")
-    Logger.info("[StaticAccIp10Scenario]   • Cust Ref (validated from ReqPay): #{cust_ref} (length: #{String.length(cust_ref)})")
-    Logger.info("[StaticAccIp10Scenario]   • Payee AcNum (from ReqPay): #{payee_ac_num}")
-    Logger.info("[StaticAccIp10Scenario]   • Payee IFSC (from ReqPay): #{payee_ifsc}")
-
-    # --- 3. Generate new values for the RespPay ---
-    resp_msg_id = "MSG" <> (:crypto.strong_rand_bytes(8) |> Base.encode16())
-    current_ts = generate_npci_timestamp()
-    approval_num = "APP" <> to_string(:rand.uniform(999))
-
-    # --- 4. Generate the RespPay XML ---
-    resp_pay_xml = """
-    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
-    <upi:RespPay xmlns:upi="http://npci.org/upi/schema/">
-        <Head msgId="#{resp_msg_id}"
-              orgId="MER102"
-              prodType="UPI"
-              ts="#{current_ts}"
-              ver="2.0"/>
-        <Txn custRef="#{cust_ref}"
-             id="#{txn_id}"
-             initiationMode="#{initiation_mode}"
-             note="ACCIP10"
-             orgRespCode="BT"
-             orgTxnId="#{org_txn_id}"
-             purpose="11"
-             refCategory="00"
-             refId="#{cust_ref}"
-             refUrl="www.test.co.in"
-             subType="CREDIT"
-             ts="#{current_ts}"
-             type="REVERSAL">
-            <QR expireTs="#{qr_expire_ts}"
-                qVer="#{q_ver}"
-                qrMedium="#{qr_medium}"
-                stan="000125"
-                ts="#{current_ts}"/>
-        </Txn>
-        <Resp errCode="CS"
-              reqMsgId="#{req_msg_id}"
-              result="SUCCESS">
-            <Ref IFSC="#{payee_ifsc}"
-                 acNum="#{payee_ac_num}"
-                 accType="CURRENT"
-                 addr="accip10@merstatic"
-                 approvalNum="#{approval_num}"
-                 code="5932"
-                 orgAmount="#{amount}"
-                 regName="Static Merchant"
-                 respCode="CS"
-                 seqNum="1"
-                 settAmount="#{amount}"
-                 settCurrency="INR"
-                 type="PAYEE"/>
-        </Resp>
-        #{generate_signature_section()}
-    </upi:RespPay>
-    """
-
-    Logger.info("[StaticAccIp10Scenario] ✅ Generated static ACC_IP_10 RespPay XML successfully")
-    Logger.debug("[StaticAccIp10Scenario] Generated XML (first 500 chars): #{String.slice(resp_pay_xml, 0, 500)}")
-    Logger.debug("[StaticAccIp10Scenario] Generated RespPay XML (first 500 chars):\n#{String.slice(resp_pay_xml, 0, 500)}")
-    {:ok, resp_pay_xml}
+  # [RespPay-REVERSAL <Resp> template] OLD FUNCTION kept for reference. It hand-built the XML with hard-coded values: Txn note ACCIP10, orgRespCode BT, refUrl www.test.co.in, purpose 11, refId=custRef, new Txn ts / QR ts, stan 000125,
+  # Resp errCode CS on SUCCESS, Ref addr accip10@merstatic / code 5932 / regName "Static Merchant" / accType CURRENT / IFSC MERC0000001 / acNum 1234567890, settAmount = amount, no reversalRespCode.
+  # [RespPay-REVERSAL Txn.*, QR.*, Ref.*, Resp.errCode, Head.msgId, Ref.reversalRespCode] CHANGED: the response is now built by UpiXmlSchema.generate_resp_pay from the full reversal ReqPay (+ stored original ReqPay)
+  # TSD Table 4: Txn / QR / Ref echo the request, no errCode on SUCCESS, REVERSAL adds Ref reversalRespCode (CS = credit stands).
+  # OLD:   defp generate_resp_pay_static_accip10(reversal_data, original_xml) do
+  # OLD:     Logger.info("[StaticAccIp10Scenario] 📝 Generating static ACC_IP_10 specific RespPay XML")
+  # OLD:
+  # OLD:     # --- 1. Extract all required data from the reversal_data map ---
+  # OLD:     req_msg_id = reversal_data[:msg_id] || ""
+  # OLD:     txn_id = reversal_data[:txn_id] || ""
+  # OLD:     org_txn_id = reversal_data[:org_txn_id] || ""
+  # OLD:     amount = reversal_data[:amount] || "0.00"
+  # OLD:     initiation_mode = reversal_data[:initiation_mode] || reversal_data[:initiationMode] || "02"
+  # OLD:     cust_ref = validate_and_extract_cust_ref(reversal_data, original_xml)
+  # OLD:
+  # OLD:     # Extract QR data with fallbacks
+  # OLD:     qr_data = extract_qr_data_from_xml(original_xml)
+  # OLD:     qr_expire_ts = qr_data[:expire_ts] || generate_future_timestamp()
+  # OLD:     q_ver = qr_data[:q_ver] || "02"
+  # OLD:     qr_medium = qr_data[:qr_medium] || "03"
+  # OLD:
+  # OLD:     # Extract Payee Account Details
+  # OLD:     payee_details = get_in(reversal_data, [:payees, 0, :ac, :details]) || []
+  # OLD:     payee_ac_num =
+  # OLD:       (Enum.find(payee_details, &(&1[:name] == "ACNUM")) || %{})[:value] || "1234567890"
+  # OLD:     payee_ifsc =
+  # OLD:       (Enum.find(payee_details, &(&1[:name] == "IFSC")) || %{})[:value] || "MERC0000001"
+  # OLD:
+  # OLD:     # --- 2. Log extracted data for debugging ---
+  # OLD:     Logger.info("[StaticAccIp10Scenario]   • Request Msg ID: #{req_msg_id}")
+  # OLD:     Logger.info("[StaticAccIp10Scenario]   • Transaction ID: #{txn_id}")
+  # OLD:     Logger.info("[StaticAccIp10Scenario]   • Amount: #{amount} INR")
+  # OLD:     Logger.info("[StaticAccIp10Scenario]   • Type: REVERSAL with subType: CREDIT")
+  # OLD:     Logger.info("[StaticAccIp10Scenario]   • Response Code: CS (SUCCESS)")
+  # OLD:     Logger.info("[StaticAccIp10Scenario]   • Static OrgId: MER102")
+  # OLD:     Logger.info("[StaticAccIp10Scenario]   • Static NetInstId: MER1020002")
+  # OLD:     Logger.info("[StaticAccIp10Scenario]   • Initiation Mode (from ReqPay): #{initiation_mode}")
+  # OLD:     Logger.info("[StaticAccIp10Scenario]   • Cust Ref (validated from ReqPay): #{cust_ref} (length: #{String.length(cust_ref)})")
+  # OLD:     Logger.info("[StaticAccIp10Scenario]   • Payee AcNum (from ReqPay): #{payee_ac_num}")
+  # OLD:     Logger.info("[StaticAccIp10Scenario]   • Payee IFSC (from ReqPay): #{payee_ifsc}")
+  # OLD:
+  # OLD:     # --- 3. Generate new values for the RespPay ---
+  # OLD:     resp_msg_id = "MSG" <> (:crypto.strong_rand_bytes(8) |> Base.encode16())
+  # OLD:     current_ts = generate_npci_timestamp()
+  # OLD:     approval_num = "APP" <> to_string(:rand.uniform(999))
+  # OLD:
+  # OLD:     # --- 4. Generate the RespPay XML ---
+  # OLD:     resp_pay_xml = """
+  # OLD:     <?xml version="1.0" encoding="UTF-8" standalone="no"?>
+  # OLD:     <upi:RespPay xmlns:upi="http://npci.org/upi/schema/">
+  # OLD:         <Head msgId="#{resp_msg_id}"
+  # OLD:               orgId="MER102"
+  # OLD:               prodType="UPI"
+  # OLD:               ts="#{current_ts}"
+  # OLD:               ver="2.0"/>
+  # OLD:         <Txn custRef="#{cust_ref}"
+  # OLD:              id="#{txn_id}"
+  # OLD:              initiationMode="#{initiation_mode}"
+  # OLD:              note="ACCIP10"
+  # OLD:              orgRespCode="BT"
+  # OLD:              orgTxnId="#{org_txn_id}"
+  # OLD:              purpose="11"
+  # OLD:              refCategory="00"
+  # OLD:              refId="#{cust_ref}"
+  # OLD:              refUrl="www.test.co.in"
+  # OLD:              subType="CREDIT"
+  # OLD:              ts="#{current_ts}"
+  # OLD:              type="REVERSAL">
+  # OLD:             <QR expireTs="#{qr_expire_ts}"
+  # OLD:                 qVer="#{q_ver}"
+  # OLD:                 qrMedium="#{qr_medium}"
+  # OLD:                 stan="000125"
+  # OLD:                 ts="#{current_ts}"/>
+  # OLD:         </Txn>
+  # OLD:         <Resp errCode="CS"
+  # OLD:               reqMsgId="#{req_msg_id}"
+  # OLD:               result="SUCCESS">
+  # OLD:             <Ref IFSC="#{payee_ifsc}"
+  # OLD:                  acNum="#{payee_ac_num}"
+  # OLD:                  accType="CURRENT"
+  # OLD:                  addr="accip10@merstatic"
+  # OLD:                  approvalNum="#{approval_num}"
+  # OLD:                  code="5932"
+  # OLD:                  orgAmount="#{amount}"
+  # OLD:                  regName="Static Merchant"
+  # OLD:                  respCode="CS"
+  # OLD:                  seqNum="1"
+  # OLD:                  settAmount="#{amount}"
+  # OLD:                  settCurrency="INR"
+  # OLD:                  type="PAYEE"/>
+  # OLD:         </Resp>
+  # OLD:         #{generate_signature_section()}
+  # OLD:     </upi:RespPay>
+  # OLD:     """
+  # OLD:
+  # OLD:     Logger.info("[StaticAccIp10Scenario] ✅ Generated static ACC_IP_10 RespPay XML successfully")
+  # OLD:     Logger.debug("[StaticAccIp10Scenario] Generated XML (first 500 chars): #{String.slice(resp_pay_xml, 0, 500)}")
+  # OLD:     Logger.debug("[StaticAccIp10Scenario] Generated RespPay XML (first 500 chars):\n#{String.slice(resp_pay_xml, 0, 500)}")
+  # OLD:     {:ok, resp_pay_xml}
+  # OLD:   end
+  # [RespPay-REVERSAL generate_resp_pay_static_accip10] CHANGED: defp -> def (@doc false) so the reversal builder can be unit-tested; callers are unchanged
+  # OLD:   defp generate_resp_pay_static_accip10(reversal_data, original_xml) do
+  @doc false
+  def generate_resp_pay_static_accip10(reversal_data, original_xml) do
+    Logger.info("[StaticAccIp10Scenario] 📝 Generating static ACC_IP_10 REVERSAL RespPay with UpiXmlSchema.generate_resp_pay")
+
+    # reversal_data is the small map the regex extractor builds; the full ReqPay parse carries ts / custRef / purpose / QR ts / Payee ...
+    full_request =
+      case UpiXmlSchema.parse_req_pay(original_xml) do
+        {:ok, full} -> Map.merge(reversal_data, full)
+        _ -> reversal_data
+      end
+
+    # [RespPay-REVERSAL Ref.addr / code / regName / IFSC / acNum / accType] CHANGED: values from the request, else from the stored original ReqPay
+    request_data =
+      UpiXmlSchema.fill_payee_from_stored_req_pay(full_request, find_stored_req_pay_for_reversal(full_request))
+
+    response_data = %{
+      org_id: "MER102",
+      req_msg_id: full_request[:msg_id],
+      result: "SUCCESS",
+      # [RespPay-REVERSAL Ref.reversalRespCode] ADDED: CS = credit stands (ACC_IP_10); Ref.respCode carries the same value
+      resp_code: "CS",
+      reversal_resp_code: "CS",
+      approval_num: generate_approval_num(),
+      txn_type: "REVERSAL",
+      sub_type: "CREDIT",
+      request_data: request_data
+    }
+
+    UpiXmlSchema.generate_resp_pay(response_data)
+  end
+
+  # [RespPay-REVERSAL Ref.*] ADDED: the stored original ReqPay of a reversal (reversal Txn orgTxnId = original Txn id)
+  defp find_stored_req_pay_for_reversal(reversal_data) do
+    org_txn_id = reversal_data[:org_txn_id]
+
+    if is_binary(org_txn_id) and org_txn_id != "" do
+      from(rp in ReqPay, where: rp.txn_id == ^org_txn_id, order_by: [desc: rp.inserted_at], limit: 1)
+      |> Repo.one()
+    end
+  rescue
+    # [RespPay-REVERSAL Ref.*] CHANGED: also catch :exit - a Repo call without a DB connection / sandbox owner exits instead of raising; the stored ReqPay is optional
+    # OLD:     _ -> nil
+    _ -> nil
+  catch
+    :exit, _ -> nil
   end
 
   defp generate_msg_id do
@@ -442,45 +494,48 @@ defmodule UpiStatic.SpecialHandlers.StaticAccIp10Scenario do
     "APP" <> String.pad_leading(Integer.to_string(random_number), 3, "0")
   end
 
-  defp extract_qr_data_from_xml(xml_string) when is_binary(xml_string) do
-    Logger.debug("[StaticAccIp10Scenario] Extracting QR data from original XML")
-
-    # Extract QR expireTs using regex
-    expire_ts = case Regex.run(~r/expireTs="([^"]+)"/, xml_string) do
-      [_, ts] -> ts
-      _ -> generate_future_timestamp()
-    end
-
-    # Extract QR version
-    qr_ver = case Regex.run(~r/qVer="([^"]+)"/, xml_string) do
-      [_, ver] -> ver
-      _ -> "02"  # Default
-    end
-
-    # Extract QR medium
-    qr_medium = case Regex.run(~r/qrMedium="([^"]+)"/, xml_string) do
-      [_, medium] -> medium
-      _ -> "03"  # Default
-    end
-
-    %{
-      expire_ts: expire_ts,
-      qr_ver: qr_ver,
-      qr_medium: qr_medium,
-      qr_ts: generate_npci_timestamp()
-    }
-  end
-
-  defp extract_qr_data_from_xml(_), do: %{}
-
-  defp generate_npci_timestamp do
-    # Generate NPCI-compliant timestamp with +05:30 offset (IST)
-    # Format: YYYY-MM-DDTHH:MM:SS+05:30
-    DateTime.now!("Asia/Kolkata")
-    |> DateTime.to_iso8601()
-    |> String.replace("Z", "+05:30")
-    |> String.replace(~r/\.\d+\+/, "+")  # Remove microseconds but keep offset
-  end
+  # [RespPay-REVERSAL <Resp> template] REMOVED: extract_qr_data_from_xml (clause) is unused now - the hand-built reversal XML moved to UpiXmlSchema.generate_resp_pay
+  # OLD:   defp extract_qr_data_from_xml(xml_string) when is_binary(xml_string) do
+  # OLD:     Logger.debug("[StaticAccIp10Scenario] Extracting QR data from original XML")
+  # OLD:
+  # OLD:     # Extract QR expireTs using regex
+  # OLD:     expire_ts = case Regex.run(~r/expireTs="([^"]+)"/, xml_string) do
+  # OLD:       [_, ts] -> ts
+  # OLD:       _ -> generate_future_timestamp()
+  # OLD:     end
+  # OLD:
+  # OLD:     # Extract QR version
+  # OLD:     qr_ver = case Regex.run(~r/qVer="([^"]+)"/, xml_string) do
+  # OLD:       [_, ver] -> ver
+  # OLD:       _ -> "02"  # Default
+  # OLD:     end
+  # OLD:
+  # OLD:     # Extract QR medium
+  # OLD:     qr_medium = case Regex.run(~r/qrMedium="([^"]+)"/, xml_string) do
+  # OLD:       [_, medium] -> medium
+  # OLD:       _ -> "03"  # Default
+  # OLD:     end
+  # OLD:
+  # OLD:     %{
+  # OLD:       expire_ts: expire_ts,
+  # OLD:       qr_ver: qr_ver,
+  # OLD:       qr_medium: qr_medium,
+  # OLD:       qr_ts: generate_npci_timestamp()
+  # OLD:     }
+  # OLD:   end
+
+  # [RespPay-REVERSAL <Resp> template] REMOVED: extract_qr_data_from_xml (clause) is unused now - the hand-built reversal XML moved to UpiXmlSchema.generate_resp_pay
+  # OLD:   defp extract_qr_data_from_xml(_), do: %{}
+
+  # [RespPay-REVERSAL <Resp> template] REMOVED: generate_npci_timestamp (clause) is unused now - the hand-built reversal XML moved to UpiXmlSchema.generate_resp_pay
+  # OLD:   defp generate_npci_timestamp do
+  # OLD:     # Generate NPCI-compliant timestamp with +05:30 offset (IST)
+  # OLD:     # Format: YYYY-MM-DDTHH:MM:SS+05:30
+  # OLD:     DateTime.now!("Asia/Kolkata")
+  # OLD:     |> DateTime.to_iso8601()
+  # OLD:     |> String.replace("Z", "+05:30")
+  # OLD:     |> String.replace(~r/\.\d+\+/, "+")  # Remove microseconds but keep offset
+  # OLD:   end
 
   defp send_resp_pay_to_npci_with_ack_parsing(resp_pay_xml, parsed_data) do
     require Logger
@@ -631,28 +686,29 @@ defmodule UpiStatic.SpecialHandlers.StaticAccIp10Scenario do
     final_url
   end
 
-  defp generate_signature_section do
-    """
-    <SignedInfo>
-      <CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
-      <SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/>
-      <Reference URI="">
-        <Transforms>
-          <Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/>
-          <Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
-        </Transforms>
-        <DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
-        <DigestValue>#{generate_signature_value()}</DigestValue>
-      </Reference>
-    </SignedInfo>
-    <SignatureValue>#{generate_signature_value()}</SignatureValue>
-    <KeyInfo>
-      <X509Data>
-        <X509Certificate>#{generate_signature_value()}</X509Certificate>
-      </X509Data>
-    </KeyInfo>
-    """
-  end
+  # [RespPay-REVERSAL <Resp> template] REMOVED: generate_signature_section (clause) is unused now - the hand-built reversal XML moved to UpiXmlSchema.generate_resp_pay
+  # OLD:   defp generate_signature_section do
+  # OLD:     """
+  # OLD:     <SignedInfo>
+  # OLD:       <CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
+  # OLD:       <SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/>
+  # OLD:       <Reference URI="">
+  # OLD:         <Transforms>
+  # OLD:           <Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/>
+  # OLD:           <Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
+  # OLD:         </Transforms>
+  # OLD:         <DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
+  # OLD:         <DigestValue>#{generate_signature_value()}</DigestValue>
+  # OLD:       </Reference>
+  # OLD:     </SignedInfo>
+  # OLD:     <SignatureValue>#{generate_signature_value()}</SignatureValue>
+  # OLD:     <KeyInfo>
+  # OLD:       <X509Data>
+  # OLD:         <X509Certificate>#{generate_signature_value()}</X509Certificate>
+  # OLD:       </X509Data>
+  # OLD:     </KeyInfo>
+  # OLD:     """
+  # OLD:   end
 
   # Helper function to build ReqPay attributes from parsed data
   defp build_req_pay_attrs_from_parsed_data(parsed_data) do
@@ -695,7 +751,9 @@ defmodule UpiStatic.SpecialHandlers.StaticAccIp10Scenario do
     Logger.info("[Static ACC_IP_10 ASYNC] Processing reversal ReqPay with static orgId/netInstId")
 
     # Generate SUCCESS RespPay response with static IDs
-    resp_pay_xml = generate_resp_pay_static_accip10(parsed_data, xml_body)
+    # [RespPay-REVERSAL async RespPay] CHANGED: generate_resp_pay_static_accip10 returns {:ok, xml}; the tuple was being sent as the body
+    # OLD:     resp_pay_xml = generate_resp_pay_static_accip10(parsed_data, xml_body)
+    {:ok, resp_pay_xml} = generate_resp_pay_static_accip10(parsed_data, xml_body)
 
     # Send to NPCI
     case send_resp_pay_to_npci_with_ack_parsing(resp_pay_xml, parsed_data) do
@@ -704,102 +762,107 @@ defmodule UpiStatic.SpecialHandlers.StaticAccIp10Scenario do
     end
   end
 
-  defp generate_signature_value do
-    # Generate a dummy signature value for testing
-    # In production, this should be a proper cryptographic signature
-    :crypto.strong_rand_bytes(256) |> Base.encode64()
-  end
-
-  defp generate_future_timestamp do
-    # Generate a timestamp 1 hour from now in NPCI format
-    DateTime.utc_now()
-    |> DateTime.add(3600, :second)
-    |> DateTime.shift_zone!("Asia/Kolkata")
-    |> DateTime.to_iso8601()
-    |> String.replace("Z", "+05:30")
-    |> String.replace(~r/\.\d+\+/, "+")  # Remove microseconds but keep offset
-  end
-
-  defp validate_and_extract_cust_ref(reversal_data, original_xml) do
-    # Extract custRef from ReqPay with multiple key variations
-    # custRef MUST be exactly 12 numeric digits as per NPCI requirements
-    # Falls back to direct XML extraction if parsed_data fails
-
-    # Step 1: Try to extract from parsed_data (reversal_data map)
-    initial_cust_ref =
-      reversal_data[:custRef] ||
-      reversal_data["custRef"] ||
-      reversal_data[:cust_ref] ||
-      reversal_data["cust_ref"] ||
-      reversal_data[:refId] ||
-      reversal_data["refId"] ||
-      ""
-
-    Logger.info("[StaticAccIp10Scenario] 🔍 custRef Extraction and Validation:")
-    Logger.info("[StaticAccIp10Scenario]   • Reversal data keys: #{inspect(Map.keys(reversal_data))}")
-    Logger.info("[StaticAccIp10Scenario]   • Step 1 - From parsed_data: #{if initial_cust_ref != "", do: initial_cust_ref, else: "(empty)"}")
-
-    # Step 2: If empty from parsed_data, extract directly from XML.
-    # This re-binds `cust_ref` correctly for the rest of the function's scope.
-    cust_ref =
-      if initial_cust_ref == "" do
-        Logger.info("[StaticAccIp10Scenario]   • Step 2 - parsed_data custRef empty, trying direct XML extraction...")
-        xml_cust_ref = extract_custref_from_xml(original_xml)
-        Logger.info("[StaticAccIp10Scenario]   • Step 2 - From XML regex: #{if xml_cust_ref != "", do: xml_cust_ref, else: "(empty)"}")
-        xml_cust_ref
-      else
-        initial_cust_ref
-      end
-
-    # Validate custRef length and content
-    cust_ref_length = String.length(cust_ref)
-    is_numeric = cust_ref != "" && String.match?(cust_ref, ~r/^\d+$/)
-    is_valid_length = cust_ref_length == 12
-
-    # Log extraction and validation details
-    Logger.info("[StaticAccIp10Scenario]   • Final extracted value: #{cust_ref}")
-    Logger.info("[StaticAccIp10Scenario]   • Length: #{cust_ref_length} (required: 12)")
-    Logger.info("[StaticAccIp10Scenario]   • Is numeric: #{is_numeric}")
-
-    # Validate and provide feedback
-    if cust_ref == "" do
-      Logger.error("[StaticAccIp10Scenario] ❌ CRITICAL: custRef not found in ReqPay!")
-      Logger.error("[StaticAccIp10Scenario]   • Could not extract from parsed_data or XML")
-      Logger.error("[StaticAccIp10Scenario]   • This will cause NPCI T12 error: TXN.CUSTREF MUST BE PRESENT; LENGTH 12")
-      ""
-    else
-      if not is_valid_length do
-        Logger.warning("[StaticAccIp10Scenario] ⚠️  custRef length mismatch!")
-        Logger.warning("[StaticAccIp10Scenario]   • Expected: 12 digits")
-        Logger.warning("[StaticAccIp10Scenario]   • Got: #{cust_ref_length} characters")
-      end
-
-      if not is_numeric do
-        Logger.warning("[StaticAccIp10Scenario] ⚠️  custRef contains non-numeric characters!")
-        Logger.warning("[StaticAccIp10Scenario]   • Expected: only digits (0-9)")
-        Logger.warning("[StaticAccIp10Scenario]   • Got: #{cust_ref}")
-      end
-
-      if is_valid_length and is_numeric do
-        Logger.info("[StaticAccIp10Scenario] ✅ custRef validation passed - exactly 12 numeric digits")
-      end
-
-      cust_ref
-    end
-  end
-
-  defp extract_custref_from_xml(xml_string) when is_binary(xml_string) do
-    # Direct XML extraction using regex as fallback
-    # Extracts custRef from: <Txn custRef="532912694270" ... />
-    case Regex.run(~r/custRef="([^"]+)"/, xml_string) do
-      [_, value] ->
-        Logger.debug("[StaticAccIp10Scenario] 📄 custRef extracted from XML: #{value}")
-        value
-      nil ->
-        Logger.warn("[StaticAccIp10Scenario] ⚠️  custRef not found in XML using regex")
-        ""
-    end
-  end
-
-  defp extract_custref_from_xml(_), do: ""
+  # [RespPay-REVERSAL <Resp> template] REMOVED: generate_signature_value (clause) is unused now - the hand-built reversal XML moved to UpiXmlSchema.generate_resp_pay
+  # OLD:   defp generate_signature_value do
+  # OLD:     # Generate a dummy signature value for testing
+  # OLD:     # In production, this should be a proper cryptographic signature
+  # OLD:     :crypto.strong_rand_bytes(256) |> Base.encode64()
+  # OLD:   end
+
+  # [RespPay-REVERSAL <Resp> template] REMOVED: generate_future_timestamp (clause) is unused now - the hand-built reversal XML moved to UpiXmlSchema.generate_resp_pay
+  # OLD:   defp generate_future_timestamp do
+  # OLD:     # Generate a timestamp 1 hour from now in NPCI format
+  # OLD:     DateTime.utc_now()
+  # OLD:     |> DateTime.add(3600, :second)
+  # OLD:     |> DateTime.shift_zone!("Asia/Kolkata")
+  # OLD:     |> DateTime.to_iso8601()
+  # OLD:     |> String.replace("Z", "+05:30")
+  # OLD:     |> String.replace(~r/\.\d+\+/, "+")  # Remove microseconds but keep offset
+  # OLD:   end
+
+  # [RespPay-REVERSAL <Resp> template] REMOVED: validate_and_extract_cust_ref (clause) is unused now - the hand-built reversal XML moved to UpiXmlSchema.generate_resp_pay
+  # OLD:   defp validate_and_extract_cust_ref(reversal_data, original_xml) do
+  # OLD:     # Extract custRef from ReqPay with multiple key variations
+  # OLD:     # custRef MUST be exactly 12 numeric digits as per NPCI requirements
+  # OLD:     # Falls back to direct XML extraction if parsed_data fails
+  # OLD:
+  # OLD:     # Step 1: Try to extract from parsed_data (reversal_data map)
+  # OLD:     initial_cust_ref =
+  # OLD:       reversal_data[:custRef] ||
+  # OLD:       reversal_data["custRef"] ||
+  # OLD:       reversal_data[:cust_ref] ||
+  # OLD:       reversal_data["cust_ref"] ||
+  # OLD:       reversal_data[:refId] ||
+  # OLD:       reversal_data["refId"] ||
+  # OLD:       ""
+  # OLD:
+  # OLD:     Logger.info("[StaticAccIp10Scenario] 🔍 custRef Extraction and Validation:")
+  # OLD:     Logger.info("[StaticAccIp10Scenario]   • Reversal data keys: #{inspect(Map.keys(reversal_data))}")
+  # OLD:     Logger.info("[StaticAccIp10Scenario]   • Step 1 - From parsed_data: #{if initial_cust_ref != "", do: initial_cust_ref, else: "(empty)"}")
+  # OLD:
+  # OLD:     # Step 2: If empty from parsed_data, extract directly from XML.
+  # OLD:     # This re-binds `cust_ref` correctly for the rest of the function's scope.
+  # OLD:     cust_ref =
+  # OLD:       if initial_cust_ref == "" do
+  # OLD:         Logger.info("[StaticAccIp10Scenario]   • Step 2 - parsed_data custRef empty, trying direct XML extraction...")
+  # OLD:         xml_cust_ref = extract_custref_from_xml(original_xml)
+  # OLD:         Logger.info("[StaticAccIp10Scenario]   • Step 2 - From XML regex: #{if xml_cust_ref != "", do: xml_cust_ref, else: "(empty)"}")
+  # OLD:         xml_cust_ref
+  # OLD:       else
+  # OLD:         initial_cust_ref
+  # OLD:       end
+  # OLD:
+  # OLD:     # Validate custRef length and content
+  # OLD:     cust_ref_length = String.length(cust_ref)
+  # OLD:     is_numeric = cust_ref != "" && String.match?(cust_ref, ~r/^\d+$/)
+  # OLD:     is_valid_length = cust_ref_length == 12
+  # OLD:
+  # OLD:     # Log extraction and validation details
+  # OLD:     Logger.info("[StaticAccIp10Scenario]   • Final extracted value: #{cust_ref}")
+  # OLD:     Logger.info("[StaticAccIp10Scenario]   • Length: #{cust_ref_length} (required: 12)")
+  # OLD:     Logger.info("[StaticAccIp10Scenario]   • Is numeric: #{is_numeric}")
+  # OLD:
+  # OLD:     # Validate and provide feedback
+  # OLD:     if cust_ref == "" do
+  # OLD:       Logger.error("[StaticAccIp10Scenario] ❌ CRITICAL: custRef not found in ReqPay!")
+  # OLD:       Logger.error("[StaticAccIp10Scenario]   • Could not extract from parsed_data or XML")
+  # OLD:       Logger.error("[StaticAccIp10Scenario]   • This will cause NPCI T12 error: TXN.CUSTREF MUST BE PRESENT; LENGTH 12")
+  # OLD:       ""
+  # OLD:     else
+  # OLD:       if not is_valid_length do
+  # OLD:         Logger.warning("[StaticAccIp10Scenario] ⚠️  custRef length mismatch!")
+  # OLD:         Logger.warning("[StaticAccIp10Scenario]   • Expected: 12 digits")
+  # OLD:         Logger.warning("[StaticAccIp10Scenario]   • Got: #{cust_ref_length} characters")
+  # OLD:       end
+  # OLD:
+  # OLD:       if not is_numeric do
+  # OLD:         Logger.warning("[StaticAccIp10Scenario] ⚠️  custRef contains non-numeric characters!")
+  # OLD:         Logger.warning("[StaticAccIp10Scenario]   • Expected: only digits (0-9)")
+  # OLD:         Logger.warning("[StaticAccIp10Scenario]   • Got: #{cust_ref}")
+  # OLD:       end
+  # OLD:
+  # OLD:       if is_valid_length and is_numeric do
+  # OLD:         Logger.info("[StaticAccIp10Scenario] ✅ custRef validation passed - exactly 12 numeric digits")
+  # OLD:       end
+  # OLD:
+  # OLD:       cust_ref
+  # OLD:     end
+  # OLD:   end
+
+  # [RespPay-REVERSAL <Resp> template] REMOVED: extract_custref_from_xml (clause) is unused now - the hand-built reversal XML moved to UpiXmlSchema.generate_resp_pay
+  # OLD:   defp extract_custref_from_xml(xml_string) when is_binary(xml_string) do
+  # OLD:     # Direct XML extraction using regex as fallback
+  # OLD:     # Extracts custRef from: <Txn custRef="532912694270" ... />
+  # OLD:     case Regex.run(~r/custRef="([^"]+)"/, xml_string) do
+  # OLD:       [_, value] ->
+  # OLD:         Logger.debug("[StaticAccIp10Scenario] 📄 custRef extracted from XML: #{value}")
+  # OLD:         value
+  # OLD:       nil ->
+  # OLD:         Logger.warn("[StaticAccIp10Scenario] ⚠️  custRef not found in XML using regex")
+  # OLD:         ""
+  # OLD:     end
+  # OLD:   end
+
+  # [RespPay-REVERSAL <Resp> template] REMOVED: extract_custref_from_xml (clause) is unused now - the hand-built reversal XML moved to UpiXmlSchema.generate_resp_pay
+  # OLD:   defp extract_custref_from_xml(_), do: ""
 end
diff --git a/apps/upi_static/lib/upi_static/special_handlers/static_timeout_simulation_handler.ex b/apps/upi_static/lib/upi_static/special_handlers/static_timeout_simulation_handler.ex
index 7d52834..222620d 100644
--- a/apps/upi_static/lib/upi_static/special_handlers/static_timeout_simulation_handler.ex
+++ b/apps/upi_static/lib/upi_static/special_handlers/static_timeout_simulation_handler.ex
@@ -182,29 +182,44 @@ defmodule UpiStatic.SpecialHandlers.StaticTimeoutSimulationHandler do
 
       # Payee details
       seq_num: "1",
-      payee_addr: @timeout_vpa,
-      payee_name: Map.get(parsed_data, :payee_name, "Abu Dhabi Gourmet Static"),
+      # [RespPay-REVERSAL Ref.addr / Ref.regName / Ref.code] CHANGED: the scenario VPA constant, "Abu Dhabi Gourmet Static" and dummy MCC 5912 are gone - the request's Payee is echoed
+      # OLD:       payee_addr: @timeout_vpa,
+      # OLD:       payee_name: Map.get(parsed_data, :payee_name, "Abu Dhabi Gourmet Static"),
+      # OLD:       payee_type: "ENTITY",
+      # OLD:       payee_code: Map.get(parsed_data, :payee_code, "5912"),
+      payee_addr: Map.get(parsed_data, :payee_addr),
+      payee_name: Map.get(parsed_data, :payee_name),
       payee_type: "ENTITY",
-      payee_code: Map.get(parsed_data, :payee_code, "5912"),
+      payee_code: Map.get(parsed_data, :payee_code),
       org_amount: Map.get(parsed_data, :amount) || Map.get(parsed_data, :payee_amount, "0.00"),
       resp_code: "00",  # Success
-      reg_name: Map.get(parsed_data, :payee_name, "Abu Dhabi Gourmet Static"),
+      # [RespPay-REVERSAL Ref.regName] CHANGED: no invented "Abu Dhabi Gourmet Static"
+      # OLD:       reg_name: Map.get(parsed_data, :payee_name, "Abu Dhabi Gourmet Static"),
+      reg_name: Map.get(parsed_data, :payee_name),
 
       # Account details
-      ifsc: Map.get(parsed_data, :payee_ifsc, "AEBK0098765"),
-      ac_num: Map.get(parsed_data, :payee_ac_num, "AE987654321"),
-      acc_type: Map.get(parsed_data, :payee_ac_type, "CURRENT"),
+      # [RespPay-REVERSAL Ref.IFSC / acNum / accType] CHANGED: no invented AEBK0098765 / AE987654321 / CURRENT
+      # OLD:       ifsc: Map.get(parsed_data, :payee_ifsc, "AEBK0098765"),
+      # OLD:       ac_num: Map.get(parsed_data, :payee_ac_num, "AE987654321"),
+      # OLD:       acc_type: Map.get(parsed_data, :payee_ac_type, "CURRENT"),
+      ifsc: Map.get(parsed_data, :payee_ifsc),
+      ac_num: Map.get(parsed_data, :payee_ac_num),
+      acc_type: Map.get(parsed_data, :payee_ac_type),
       approval_num: generate_approval_number(),
 
       # Settlement details
       sett_amount: Map.get(parsed_data, :amount) || Map.get(parsed_data, :payee_amount, "0.00"),
-      sett_currency: Map.get(parsed_data, :currency, "INR"),
+      # [RespPay-REVERSAL Ref.settCurrency / Ref.reversalRespCode] CHANGED: settCurrency always INR; reversalRespCode 00 = reversed ADDED
+      # OLD:       sett_currency: Map.get(parsed_data, :currency, "INR"),
+      sett_currency: "INR",
+      reversal_resp_code: "00",
 
       # Static QR specific
-      initiation_mode: "02",  # Static QR initiation mode
-      qr_ver: "02",
-      qr_medium: "03",
-      expire_ts: DateTime.utc_now() |> DateTime.add(1800, :second) |> DateTime.to_iso8601(),
+      # [RespPay-REVERSAL Txn.initiationMode / QR.qVer / qrMedium / expireTs] CHANGED: echoed from the ReqPay (no fixed 02 / 02 / 03, no generated UTC expiry)
+      # OLD:       initiation_mode: "02",  # Static QR initiation mode
+      # OLD:       qr_ver: "02",
+      # OLD:       qr_medium: "03",
+      # OLD:       expire_ts: DateTime.utc_now() |> DateTime.add(1800, :second) |> DateTime.to_iso8601(),
 
       # Request data for XML generation
       request_data: parsed_data
diff --git a/apps/upi_static/lib/upi_static/static_qr_transaction_manager.ex b/apps/upi_static/lib/upi_static/static_qr_transaction_manager.ex
index ab3e21f..d1632a5 100644
--- a/apps/upi_static/lib/upi_static/static_qr_transaction_manager.ex
+++ b/apps/upi_static/lib/upi_static/static_qr_transaction_manager.ex
@@ -1664,16 +1664,22 @@ defmodule UpiStatic.StaticQrTransactionManager do
     amount = Map.get(parsed_data, :amount, "999.00")
 
     # Extract QR metadata from parsed_data.qr_data (preferred) or fallback to XML extraction
+    # [RespPay-REVERSAL QR.qVer] CHANGED: no invented default 01 (echo of the ReqPay QR)
+    # OLD:     qr_ver = get_in(parsed_data, [:qr_data, :ver]) ||
+    # OLD:              Map.get(parsed_data, :qr_ver) ||
+    # OLD:              "01"
     qr_ver = get_in(parsed_data, [:qr_data, :ver]) ||
-             Map.get(parsed_data, :qr_ver) ||
-             "01"
+             Map.get(parsed_data, :qr_ver)
 
     qr_expire_ts = get_in(parsed_data, [:qr_data, :expire_ts]) ||
                    Map.get(parsed_data, :expire_ts)
 
+    # [RespPay-REVERSAL QR.qrMedium] CHANGED: no invented default 03 (echo of the ReqPay QR)
+    # OLD:     qr_medium = get_in(parsed_data, [:qr_data, :medium]) ||
+    # OLD:                 Map.get(parsed_data, :qr_medium) ||
+    # OLD:                 "03"
     qr_medium = get_in(parsed_data, [:qr_data, :medium]) ||
-                Map.get(parsed_data, :qr_medium) ||
-                "03"
+                Map.get(parsed_data, :qr_medium)
 
     # Fallback: Extract from XML if not in parsed_data
     if is_nil(qr_expire_ts) do
@@ -1697,22 +1703,27 @@ defmodule UpiStatic.StaticQrTransactionManager do
       note: Map.get(parsed_data, :note, "ACCIP10"),
       txn_type: "CREDIT",
       sub_type: "PAY",
-      payee_addr: "accip10@mercury",
-      payee_name: "ACC IP 10 Merchant",
-      payee_code: "0000",
+      # [RespPay-REVERSAL Ref.addr / regName / code] REMOVED: invented accip10@mercury / ACC IP 10 Merchant / 0000; Ref comes from request_data (ReqPay Payee)
+      # OLD:       payee_addr: "accip10@mercury",
+      # OLD:       payee_name: "ACC IP 10 Merchant",
+      # OLD:       payee_code: "0000",
       org_amount: amount,
       resp_code: "CS",
-      reg_name: "ACC IP 10 Merchant",
-      ifsc: "SBIN0000001",
-      ac_num: "1234567890",
-      acc_type: "SAVINGS",
+      # [RespPay-REVERSAL Ref.regName / IFSC / acNum / accType] REMOVED: invented ACC IP 10 Merchant / SBIN0000001 / 1234567890 / SAVINGS; Ref comes from request_data (ReqPay Payee)
+      # OLD:       reg_name: "ACC IP 10 Merchant",
+      # OLD:       ifsc: "SBIN0000001",
+      # OLD:       ac_num: "1234567890",
+      # OLD:       acc_type: "SAVINGS",
       approval_num: generate_approval_number(),
       sett_amount: amount,
       sett_currency: "INR",
       ref_url: Map.get(parsed_data, :ref_url, ""),
       expire_ts: qr_expire_ts,
       qr_ver: qr_ver,
-      qr_medium: qr_medium
+      # [RespPay-REVERSAL request_data] ADDED: the ReqPay is passed so Txn / QR / Ref echo it (TSD Table 4)
+      # OLD:       qr_medium: qr_medium
+      qr_medium: qr_medium,
+      request_data: parsed_data
     }
 
     case UpiXmlSchema.generate_resp_pay(response_data) do
diff --git a/apps/upi_static/test/upi_static/resp_pay_reversal_test.exs b/apps/upi_static/test/upi_static/resp_pay_reversal_test.exs
new file mode 100644
index 0000000..f38e99d
--- /dev/null
+++ b/apps/upi_static/test/upi_static/resp_pay_reversal_test.exs
@@ -0,0 +1,108 @@
+defmodule UpiStatic.RespPayReversalTest do
+  use ExUnit.Case, async: false
+
+  import SweetXml
+
+  @key_path Path.expand("../../../../private.pem", __DIR__)
+
+  @reversal_xml """
+  <upi:ReqPay xmlns:upi="http://npci.org/upi/schema/">
+    <Head ver="2.0" ts="2026-07-09T14:50:00+05:30" orgId="NPCI" msgId="NPCIREVERSAL000000000000000000001"/>
+    <Txn id="NPCIREVTXN0001" note="static reversal" custRef="CUSTREF10" refId="REFNPCI0010" refUrl="http://x" ts="2026-07-09T14:50:01+05:30" type="REVERSAL" subType="CREDIT" initiationMode="02" purpose="11" orgTxnId="ORGTXN0001" refCategory="00">
+      <QR expireTs="2027-04-29T14:45:05+05:30" qVer="01" qrMedium="03" ts="2027-04-29T14:15:05+05:30"/>
+    </Txn>
+    <Payer addr="payer@npci" name="NPCI Payer" seqNum="1" type="PERSON" code="0000"/>
+    <Payees>
+      <Payee addr="accip10@merstatic" name="NPCI Static Tester" seqNum="1" type="ENTITY" code="5812">
+        <Ac addrType="ACCOUNT">
+          <Detail name="IFSC" value="TEST0000002"/>
+          <Detail name="ACTYPE" value="CURRENT"/>
+          <Detail name="ACNUM" value="TESTACNUM0020"/>
+        </Ac>
+        <Amount value="5.00" curr="INR"/>
+      </Payee>
+    </Payees>
+  </upi:ReqPay>
+  """
+
+  setup do
+    previous = Application.get_env(:upi_core, :xml_signing_priv_key_path)
+    Application.put_env(:upi_core, :xml_signing_priv_key_path, @key_path)
+
+    on_exit(fn ->
+      if previous,
+        do: Application.put_env(:upi_core, :xml_signing_priv_key_path, previous),
+        else: Application.delete_env(:upi_core, :xml_signing_priv_key_path)
+    end)
+
+    :ok
+  end
+
+  defp attr(xml, path), do: xpath(xml, ~x"#{path}"s)
+  @ref "//*[local-name()='Ref']"
+
+  test "static ACC_IP_10: CS reversal built from the full ReqPay, no BT / test.co.in / hard-coded Ref" do
+    # the regex extractor of the static manager only keeps a few fields
+    reversal_data = %{msg_id: "NPCIREVERSAL000000000000000000001", txn_id: "NPCIREVTXN0001", org_txn_id: "ORGTXN0001"}
+
+    assert {:ok, xml} =
+             UpiStatic.SpecialHandlers.StaticAccIp10Scenario.generate_resp_pay_static_accip10(reversal_data, @reversal_xml)
+
+    assert attr(xml, "//*[local-name()='Head']/@orgId") == "MER102"
+    assert attr(xml, "//*[local-name()='Head']/@msgId") =~ ~r/^MER[0-9a-f]{32}$/
+    assert attr(xml, "//*[local-name()='Txn']/@type") == "REVERSAL"
+    assert attr(xml, "//*[local-name()='Txn']/@subType") == "CREDIT"
+    assert attr(xml, "//*[local-name()='Txn']/@refId") == "REFNPCI0010"
+    assert attr(xml, "//*[local-name()='Txn']/@ts") == "2026-07-09T14:50:01+05:30"
+    assert attr(xml, "//*[local-name()='Txn']/@initiationMode") == "02"
+    assert attr(xml, "//*[local-name()='QR']/@expireTs") == "2027-04-29T14:45:05+05:30"
+    assert attr(xml, "//*[local-name()='QR']/@ts") == "2027-04-29T14:15:05+05:30"
+    assert attr(xml, "//*[local-name()='Resp']/@errCode") == ""
+    assert attr(xml, @ref <> "/@respCode") == "CS"
+    assert attr(xml, @ref <> "/@reversalRespCode") == "CS"
+    assert attr(xml, @ref <> "/@settCurrency") == "INR"
+    assert attr(xml, @ref <> "/@addr") == "accip10@merstatic"
+    assert attr(xml, @ref <> "/@code") == "5812"
+    assert attr(xml, @ref <> "/@regName") == "NPCI Static Tester"
+    assert attr(xml, @ref <> "/@IFSC") == "TEST0000002"
+    assert attr(xml, @ref <> "/@acNum") == "TESTACNUM0020"
+    assert attr(xml, @ref <> "/@orgAmount") == "5.00"
+    refute xml =~ "orgRespCode"
+    refute xml =~ "www.test.co.in"
+    refute xml =~ "Static Merchant"
+    refute xml =~ "MERC0000001"
+  end
+
+  test "static ACC_IP_09 (timeout simulation): 00 reversal, INR, QR echoed" do
+    req = %{
+      msg_id: "NPCIREVERSAL000000000000000000001",
+      txn_id: "NPCIREVTXN0001",
+      org_txn_id: "ORGTXN0001",
+      cust_ref: "CUSTREF10",
+      ref_id: "REFNPCI0010",
+      txn_type: "REVERSAL",
+      sub_type: "CREDIT",
+      initiation_mode: "02",
+      txn_ts: "2026-07-09T14:50:01+05:30",
+      expire_ts: "2027-04-29T14:45:05+05:30",
+      qr_ver: "01",
+      qr_medium: "03",
+      payee_addr: "gourmet@mercury",
+      payee_name: "NPCI Static Tester",
+      payee_code: "5812",
+      payee_ifsc: "TEST0000002",
+      payee_ac_num: "TESTACNUM0020",
+      payee_ac_type: "CURRENT",
+      payee_amount: "5.00"
+    }
+
+    {:ok, xml} = UpiStatic.SpecialHandlers.StaticTimeoutSimulationHandler.generate_reversal_success_response(req)
+    assert attr(xml, "//*[local-name()='Txn']/@initiationMode") == "02"
+    assert attr(xml, "//*[local-name()='QR']/@expireTs") == "2027-04-29T14:45:05+05:30"
+    assert attr(xml, @ref <> "/@reversalRespCode") == "00"
+    assert attr(xml, @ref <> "/@settCurrency") == "INR"
+    assert attr(xml, @ref <> "/@regName") == "NPCI Static Tester"
+    refute xml =~ "AEBK0098765"
+    refute xml =~ "Abu Dhabi"
+  end
+end
