> For the complete documentation index, see [llms.txt](https://kollect.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://kollect.gitbook.io/docs/introduction/architecture-and-data-flow.md). Agents can also search and read this documentation through its [MCP server](https://kollect.gitbook.io/docs/~gitbook/mcp).

# Architecture and data flow

This page explains how the **merchant backend**, **Kollect API**, **Smart Contract**, and **your Webhook endpoint** interact during a payment.

***

## System context

```mermaid
flowchart LR
  subgraph Merchant
    BE[Merchant backend]
    WH[Merchant HTTPS webhook]
  end
  subgraph Kollect
    API[Kollect REST API]
    SCWH[Kollect SC webhook receiver]
    DB[(Invoice & payment data)]
  end
  subgraph External
    SC[Smart Contract]
    Payer[Customer]
  end
  BE -->|S2S create payment| API
  API --> DB
  API --> SC
  Payer -->|Hosted payment UI| API
  SC -->|payment.confirmed / failed| SCWH
  SCWH --> DB
  DB -->|Outbound POST| WH
```

**Key idea:** You implement **two** integration surfaces:

1. **Outbound from you:** authenticated calls to Kollect to create payments.
2. **Inbound to you:** HTTP POST from Kollect to your registered `webhookUrl` (optional but recommended for automation).

***

## Sequence diagram

```mermaid
sequenceDiagram
  participant Merchant as Merchant backend
  participant Kollect as Kollect API
  participant SC as Smart Contract
  participant Payer as Customer
  participant MW as Merchant webhook

  Merchant->>Kollect: POST /sdk/server/create-payment (auth + signature + idempotency)
  Kollect->>SC: Create payout (Smart Contract API)
  Kollect-->>Merchant: paymentUrl, paymentId, invoiceId
  Note over Kollect,Payer: Invoice email may be sent to the payer
  Payer->>Kollect: Complete payment (hosted UI)
  SC->>Kollect: POST /smart-contract-webhook/payment-status (internal infrastructure)
  Kollect->>Kollect: Verify SC signature, update invoice & payment
  Kollect->>MW: POST webhook (x-kollect-signature), if kollect-server + active invoice_settlement webhook
  MW-->>Kollect: 2xx response (else retried up to 4x with backoff)
```

***

## Component responsibilities

| Component                       | Responsibility                                                                                                                               |
| ------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
| **Merchant backend**            | Holds API key and secret; signs requests; stores idempotency keys; enqueues fulfillment on webhook.                                          |
| **Kollect API**                 | Authenticates S2S requests; creates invoice and payment records; initiates Smart Contract payout; sends payer communications as implemented. |
| **Smart Contract**              | Settles the on-chain payment and notifies Kollect.                                                                                           |
| **Kollect SC webhook receiver** | Validates `X-Smart-Contract-Signature`, maps events to internal payments, updates database.                                                  |
| **Merchant webhook**            | Verifies `x-kollect-signature`, returns 2xx quickly, updates your order or billing system.                                                   |

***

## Integration surfaces (`interface`)

Payments created via `POST /sdk/server/create-payment` default to `interface: kollect-server`. **Outbound webhooks to your server are only sent** when this integration type applies and your [webhook is registered and active](https://kollect.gitbook.io/docs/webhook-overview.md).

***

## Related pages

* [Getting started](https://kollect.gitbook.io/docs/introduction/getting-started.md)
* [Create payment URL](https://kollect.gitbook.io/docs/api-reference/create-payment.md)
* [Webhooks overview](https://kollect.gitbook.io/docs/webhook-overview.md)
