# Stage: Confirm Payment & Failure Handling

Upon the PMM's payment via `makePayment()`, including a `paymentTxId`, the trade enters the `CONFIRM_PAYMENT` phase. The `MPC`, acting as the payment verifier, must confirm the payment meets protocol specifications, checking amounts, destination chain, and `paymentTxId` accuracy.

### <mark style="color:orange;">Steps in This Phase</mark>

* **Successful Payment**: The `MPC` calls `confirmPayment()`, transitioning the trade to `CONFIRM_SETTLEMENT`, and emits a `PaymentConfirmed` event for traceability. Once confirmed, the payment is immutable.
* **Failed Payment**: If discrepancies like an incorrect amount or malformed `paymentTxId` occur, the trade moves to the `WARNING` stage. Here, the `PMM` can resubmit correct payments within the `scriptTimeout`.

### <mark style="color:orange;">Actionable Functions</mark>

* **confirmPayment()**

  ```solidity
  function confirmPayment(bytes32 tradeId, bytes calldata signature) external;
  ```

  * **Execution**: Through the `Router` by authorized `MPC Node`.
  * **Verification**: Ensures the trade is in the correct stage and within `scriptTimeout`.
  * **State Transition**: Advances trade to `CONFIRM_SETTLEMENT`, logs confirmed `paymentTxId`, and emits `PaymentConfirmed`.
* **report()**

  ```solidity
  function report(bytes32 tradeId, bytes calldata msgError, bytes calldata signature) external;
  ```

  * **Execution**: Through the `Router` by authorized `MPC Node`.
  * **Verification**: Ensures trade is not yet finalized.
  * **State Transition**: Logs failure, moves trade to `WARNING`, and emits `FailureReported`.

#### <mark style="color:orange;">Trade Data Query</mark>

* **On Success**: Access trade stages and finalization details through relevant view functions.

  ```solidity
  function getCurrentStage(bytes32 tradeId) external view returns (uint256);
  function getTradeFinalization(bytes32 tradeId) external view returns (TradeFinalization memory);
  ```
* **On Failure**: Retrieve error metadata with details for resolution.

  ```solidity
  function getCurrentStage(bytes32 tradeId) external view returns (uint256);
  function getFailureInfo(bytes32 tradeId) external view returns (FailureDetails memory);
  ```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.optimex.com/optimex-revolutionizing-bitcoin-finance/optimex-swap/optimex-swap-how-it-work/trade-life-cycle/optimex-l2-network/stage-confirm-payment-and-failure-handling.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
