# Events

## Transaction success event

When a user has reached the end of a buy/swap/sell process, you can listen for the following postMessage event:

```
{ type: 'paymentSubmitted', data: { paymentType, paymentId } }

paymentType: bankTransfer|card|crypto
```

This can be used to trigger a navigation to the desired post-transaction screen or page.

Documentation: <https://developer.mozilla.org/en-US/docs/Web/API/Window/message_event>

## Order creation event

This event is emitted when a new order is created in our system. It includes all the relevant information needed to display or process the order on your side.

```
{ "type": "orderCreated", "data": Order }
```

Depending on the order type (“buy”, “sell”, or “swap”), the `Order` payload may include different fields. Below are examples for each case.

### Buy order example

```
{
  "id": "123456789",
  "expirationDate": "2025-06-30T12:38:32.887Z",
  "cryptoAddress": "bc1ql…..",
  "currencyIn": "CHF",
  "currencyOut": "BTC",
  "marketRate": "85854.9",
  "network": "bitcoin_mainnet",
  "paymentMode": "bank",
  "type": "buy",
  "valueIn": "100",
  "valueOut": "0.001165"
}
```

### Sell order (Lightning) example

```
{
  "id": "123456789",
  "expirationDate": "2025-06-30T12:38:32.887Z",
  "offRampAddress": "mtpelerin@ln.mtpelerin.com",
  "lnInvoice": "lnbc4…",
  "cryptoAddress": "",
  "currencyIn": "sat",
  "currencyOut": "CHF",
  "marketRate": "0.00085931",
  "network": "lightning_mainnet",
  "paymentMode": "bank",
  "type": "sell",
  "valueIn": "44444",
  "valueOut": "38.19"
}
```

### Swap order example

```
{
  "id": "123456789",
  "expirationDate": "2025-06-30T12:38:32.887Z",
  "offRampAddress": "3LgdKdB9x42m4ujae78NcwUXjYW3z45KrX",
  "cryptoAddress": "",
  "cryptoAddressIn": "bc1qlu…..",
  "cryptoAddressOut": "0xee21c7…….",
  "currencyIn": "BTC",
  "currencyOut": "USDT",
  "marketRate": "107891.95",
  "network": "mainnet",
  "paymentMode": "bank",
  "type": "swap",
  "valueIn": "0.001",
  "valueOut": "106.892119",
  "networkIn": "bitcoin_mainnet",
  "networkOut": "mainnet"
}
```


---

# 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://developers.mtpelerin.com/integration-guides/events.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.
