> ## Documentation Index
> Fetch the complete documentation index at: https://docs.paymove.io/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> ## paymove integration rules for AI agents
>
> These rules are verified against the live API. Follow them exactly.
>
> 1. Amounts are INTEGERS in grosze (minor units). `1000` means 10.00 PLN. PLN is the only supported currency and there is no currency field in the API.
> 2. A float `price` (e.g. `12.99`) is SILENTLY TRUNCATED to 12 grosze and still returns HTTP 200. Always send an integer: `Math.round(pln * 100)`.
> 3. Authenticate with the `X-API-KEY` header. Never `Authorization: Bearer`. Sandbox keys start with `sk_test_`, production keys with `sk_live_`.
> 4. Server-side only. A call from a merchant page is rejected. Never put the key in frontend code.
> 5. Unknown request fields are silently ignored and still return HTTP 200 — a wrong body shape looks like success. Match the documented shape exactly.
> 6. A missing `externalId` returns HTTP 500 `Something went wrong`, not 400. A missing `price` or `details.returnUrl` returns HTTP 200 and a usable `redirectUrl` — no error at all. Validate the body yourself before sending it.
> 7. Always verify the `X-Paymove-Signature` header on incoming webhooks before trusting them: https://docs.paymove.io/en/webhook-signature.md
> 8. Errors are `{"status": <int>, "message": "<text>"}`. Branch on the HTTP status only — never on `message`, which is unstable and leaks internal class names.
> 9. There is no rate limiting, no HTTP 429, no HTTP 422, no `Idempotency-Key` header and no API versioning. Do not write code that handles them.
> 10. Re-POSTing an `externalId` that already exists returns HTTP 200 with the ORIGINAL `redirectUrl` and silently discards EVERY field you send — the new price, description and details are all ignored. Use `PATCH /api/pay/product/{productId}/subproduct/{externalId}` to change a price.
> 11. Webhooks fire only on `COMPLETED` by default, and `retries` defaults to `0` (no retries) unless you set it explicitly. Delivery counts as successful when the HTTP status equals `expectedCode` — the response body is never inspected.
> 12. Never fulfil an order on the `returnUrl` redirect. The checkout does not redirect there by itself: the customer has to click "back to shop", and inside the widget modal that redirect never happens. Fulfil only in the webhook handler, after verifying the signature.
> 13. Do not pin a version of `@paymove-io/sdk` — install the latest.
> 14. Full documentation index: https://docs.paymove.io/llms.txt · Copy-paste quickstart: https://docs.paymove.io/en/quickstart.md · Agent skill: https://docs.paymove.io/skill.md

# DocPay: webhooki

> Dodaj webhook do DocPay i otrzymuj automatyczne powiadomienia o każdej zakończonej płatności.

Webhook automatycznie powiadamia Twój system o zakończonej płatności. Konfiguracja składa się z dwóch kroków: **rejestrujesz webhook**, a następnie **przypisujesz go do produktu**. Od tego momentu zdarzenia (np. udana płatność) dla tego produktu trafiają na wskazany przez Ciebie endpoint.

Wszystkie żądania autoryzujesz kluczem API przekazywanym w nagłówku `X-API-KEY`.

<Info>
  Przykłady używają środowiska sandbox: `https://gateway-api.sandbox.paymove.io`. Potrzebujesz `partnerId` oraz `productId` produktu utworzonego w tutorialu [DocPay: podstawowa integracja](/products/docpay/tutorial).
</Info>

## Krok 1: Rejestracja webhooka

```bash theme={"theme":{"light":"one-light","dark":"one-dark-pro"}}
curl --request POST \
  --url https://gateway-api.sandbox.paymove.io/api/pay/plugin/webhook \
  --header 'Content-Type: application/json' \
  --header 'X-API-KEY: sk_test_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' \
  --data '{
    "name": "PaymentSuccessHook",
    "endpoint": "https://example.com/webhooks/payment-success",
    "method": "POST",
    "requestTemplate": {
      "productId": "productId",
      "event": "event"
    },
    "responseTemplate": {
      "status": "ok"
    },
    "expectedCode": 200,
    "expectedResponse": "{ \"status\": \"ok\" }",
    "retries": 3,
    "partnerId": "78562c79-2f5c-4415-8af4-c871eea92ef2",
    "type": "PAYMENT",
    "headers": {
      "Authorization": ["Bearer abc123"],
      "Content-Type": ["application/json"]
    }
  }'
```

| Pole               | Opis                                                                 |
| ------------------ | -------------------------------------------------------------------- |
| `name`             | Nazwa webhooka (widoczna w konfiguracji).                            |
| `endpoint`         | URL, na który Paymove wysyła żądanie.                                |
| `method`           | Metoda HTTP (np. `POST`).                                            |
| `requestTemplate`  | Szablon body żądania (zmienne podstawiane przez Paymove).            |
| `responseTemplate` | Oczekiwana struktura odpowiedzi od partnera.                         |
| `expectedCode`     | Oczekiwany kod HTTP odpowiedzi (np. 200).                            |
| `expectedResponse` | Oczekiwana treść odpowiedzi (np. `{ "status": "ok" }`).              |
| `retries`          | Liczba ponownych prób przy niepowodzeniu.                            |
| `partnerId`        | Identyfikator partnera (nadawany przez Paymove).                     |
| `type`             | Typ zdarzenia - dla powiadomień o płatności: `PAYMENT`.              |
| `headers`          | Nagłówki dołączane do żądania (np. `Authorization`, `Content-Type`). |

**Odpowiedź (200):**

```json theme={"theme":{"light":"one-light","dark":"one-dark-pro"}}
{
  "id": "18e19688-bdda-4843-8777-0f04d0143c77",
  "name": "PaymentSuccessHook",
  "endpoint": "https://example.com/webhooks/payment-success",
  "method": "POST",
  "requestTemplate": {
    "productId": "productId",
    "event": "event"
  },
  "responseTemplate": {
    "status": "ok"
  },
  "expectedCode": 200,
  "expectedResponse": "{ \"status\": \"ok\" }",
  "retries": 3,
  "type": "PAYMENT",
  "headers": {
    "Authorization": ["Bearer abc123"],
    "Content-Type": ["application/json"]
  },
  "signingSecret": "whsec_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
}
```

Pole `id` z odpowiedzi to identyfikator webhooka (`webhookId`), którego użyjesz w kroku 2.

<Warning>
  Odpowiedź zawiera `signingSecret` - sekret do weryfikacji podpisu żądań przychodzących od Paymove. Zapisz go bezpiecznie po stronie swojego systemu i nie udostępniaj publicznie.
</Warning>

## Krok 2: Przypisanie webhooka do produktu

Webhook zacznie działać dopiero po powiązaniu z produktem. W URL podmień `webhookId` (z kroku 1) oraz `productId`.

```bash theme={"theme":{"light":"one-light","dark":"one-dark-pro"}}
curl --request POST \
  --url https://gateway-api.sandbox.paymove.io/api/pay/plugin/webhook/18e19688-bdda-4843-8777-0f04d0143c77/products/d0a834f9-94a4-4b3a-aa10-27d911e3633f \
  --header 'X-API-KEY: sk_test_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
```

**Odpowiedź (200):** obiekt webhooka (taki sam jak w kroku 1), potwierdzający powiązanie.

Od tego momentu zdarzenia płatności dla tego produktu są wysyłane na Twój `endpoint`.

## Weryfikacja konfiguracji

Listę produktów powiązanych z webhookiem sprawdzisz wywołaniem:

```bash theme={"theme":{"light":"one-light","dark":"one-dark-pro"}}
curl --url https://gateway-api.sandbox.paymove.io/api/pay/plugin/webhook/18e19688-bdda-4843-8777-0f04d0143c77/products \
  --header 'X-API-KEY: sk_test_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
```

**Odpowiedź (200):** tablica produktów powiązanych z webhookiem:

```json theme={"theme":{"light":"one-light","dark":"one-dark-pro"}}
[
  {
    "id": "d0a834f9-94a4-4b3a-aa10-27d911e3633f",
    "name": "Testowy Produkt",
    "productType": "PAY",
    "status": "ACTIVE"
  }
]
```

## Jak Paymove wywołuje Twój endpoint?

Po zakończonej płatności Paymove wysyła na Twój `endpoint` żądanie zgodne z `requestTemplate` i skonfigurowanymi `headers`. Twój system powinien odpowiedzieć kodem `expectedCode` (zwyczajowo `200` i body `{ "status": "ok" }`, choć treść odpowiedzi nie jest sprawdzana). W przypadku niepowodzenia Paymove ponowi próbę tyle razy, ile wskazuje `retries`.

## Co dalej?

<CardGroup cols={1}>
  <Card title="REST API" icon="code" href="/products/docpay/rest-api">
    Pełna dokumentacja endpointów webhooków: lista, szczegóły, aktualizacja.
  </Card>
</CardGroup>
