Tole.
Тіркелу
Agent-ready · integration briefAPI v1 үшін жаңартылған

Агентке контекст беріңіз — жұмыс істейтін интеграция алыңыз

Дайын тапсырма контракт, қауіпсіздік, автошот кестелері, белгісіз нәтиже және вебхук тексеруін бекітеді. Агент API-ді болжамайды.

Raw Markdown ашуOpenAPI 3.1Кабинетті ашу

Тапсырманы толық көшіріңіз

Оны қажетті репозиторий ішінде Codex, Claude Code, Cursor немесе басқа агентке беріңіз. Агент алдымен стекпен танысып, Tole-ді бар архитектураға қосады.

Тапсырма ағылшын тілінде әдейі жазылған: техникалық атаулар OpenAPI-мен сәйкес және өрістердің бұрмалану қаупі аз.

Agent integration brief
Integrate Tole Payments API into this codebase.

Authoritative contract:
- OpenAPI 3.1: https://api.tolepay.kz/v1/openapi.json
- Human guide: https://tolepay.kz/ru/docs
- Raw agent guide: https://tolepay.kz/for-ai.md
- Base URL: https://api.tolepay.kz/v1

Before editing code:
1. Inspect the repository stack, existing HTTP client, env conventions, persistence, background jobs, and test setup.
2. Read the current OpenAPI document. Do not invent fields, SDKs, routes, statuses, or webhook events.
3. Keep all Tole credentials server-side. Add TOLE_API_KEY and optional TOLE_CONNECTION_ID to the existing secret/env system; never expose them to browser bundles or logs.

Implementation requirements:
1. Create a small typed Tole adapter around the repository's existing HTTP client. Use Authorization: Bearer <tole_sk_...>, Content-Type: application/json, and X-Tole-Connection-Id when configured.
2. Implement the requested invoice, QR, or recurring-invoice flow using the exact OpenAPI schemas. For every idempotent mutation send a stable Idempotency-Key derived from the local business operation ID, not a random key generated on each retry.
3. Persist Tole's local resource id and commandId. For recurring invoices also persist recurringInvoiceId, occurrenceId, and the generated paymentIntentId when present. Never treat a private Kaspi identifier as a public operationId.
4. Handle 200/201 as complete. On 202 in_progress, honor Retry-After and poll Location or GET /commands/{commandId}. On 202 outcome_unknown, never auto-repeat the mutation; reconcile command and payment-intent state.
5. Implement webhook verification over the exact raw request body before JSON parsing: v1=hex(HMAC-SHA256(secret, "<webhook-id>.<webhook-timestamp>.<exact_body>")). Reject invalid signatures, guard timestamp replay, deduplicate webhook-id, persist before processing, and return 2xx only after durable acceptance.
6. Use bounded timeouts. Retry safe reads with exponential backoff. Do not blindly retry payment mutations, 4xx responses, or unknown outcomes.
7. Add structured redacted logs. Never log API keys, webhook secrets, phone numbers, raw provider payloads, QR tokens, or payment URLs.
8. If recurring invoices are requested, model them as automatic invoice issuance, never as an automatic charge. Use a typed monthly, interval, weekly, or once schedule plus an IANA timezone; preview upcoming runs before create/update. Retry delays apply only when Tole could not issue the invoice. Never create a replacement merely because an issued invoice is unpaid, and never retry an outcome_unknown occurrence.
9. Add tests for success, validation error, 401/403, 409 idempotency or revision conflict, 429 Retry-After, 202 in_progress, 202 outcome_unknown, webhook valid/invalid signature, duplicate event, and timeout. Recurring flows also need timezone, short-month, pause/resume, missed-run, retry, and duplicate-occurrence tests.
10. Exercise immediate payment flows against /v1/sandbox/* with a test API key and required X-Tole-Connection-Id before enabling live mode. Recurring invoices are live-only until OpenAPI explicitly documents a sandbox mirror; do not invent one or simulate success inside production code.

Deliverables:
- production adapter and domain mapping;
- environment-variable documentation without real secrets;
- webhook endpoint and signature verification;
- automated tests and a copy-pasteable sandbox smoke command for supported immediate payment routes;
- for recurring invoices: a human-readable schedule summary, previewed next runs, lifecycle controls, and occurrence-to-payment correlation;
- a short handoff listing changed files, test results, and any remaining live-only verification.

If a required credential, connection ID, webhook URL, timezone, or business mapping is missing, finish all safe local work first and then ask for only that missing value. Never ask the user to paste a secret into chat.

Контракт картасы

Кез келген іске асыруда осы ережелер сақталуы керек.

Серверлік авторизация

tole_sk_* Bearer кілті клиент JavaScript-іне түспейді.

Тұрақты идемпотенттік

Бір бизнес-операция network retry кезінде де бір Idempotency-Key қолданады.

Автошот — есептен шығару емес

Кесте әдеттегі шот шығарады; клиент төлеуді өзі шешеді.

202 — сәтті де, бас тарту да емес

in_progress сұралады, outcome_unknown автоматты қайталанбайды.

Вебхук raw body

HMAC JSON.parse-тан бұрын есептеледі; event id идемпотентті өңделеді.

Алдымен sandbox

Test key және sandbox connection live Kaspi-ден оқшауланған; автошоттар контракт пайда болғанша live-only.

Provider ID жоқ

Интеграция Tole UUID сақтайды және Kaspi ішкі өрістерін болжамайды.

Агентті іске қоспас бұрын не дайындау керек

Құпияларды промптқа салмаңыз. Оларды жобаның қорғалған жергілікті ортасына орналастырыңыз.

  • TOLE_API_KEY айнымалысындағы test API key.
  • TOLE_CONNECTION_ID ішіндегі sandbox қосылым UUID-і.
  • Болашақ webhook endpoint-тің public HTTPS URL-і.
  • Тұрақты Idempotency-Key құратын жергілікті тапсырыс/төлем ID-і.
  • Алдымен нені қосамыз: телефон шоты, QR немесе live автошот.
  • Автошот үшін: IANA timezone, кесте ережесі және техникалық қайталау саясаты.

Live кілтті чат арқылы агентке бермеңіз. Агент мәнді тек env/secret manager-ден оқып, кодта placeholder қолдануы керек.

Интеграция қашан шынымен дайын

Агенттен осы тексерулерден кейін ғана жұмысты аяқтауын сұраңыз.

  • Sandbox mutation ресурс жасап, id + commandId сақтайды.
  • Сол business ID қайталанса, екінші төлем жасалмайды.
  • 202 in_progress Retry-After сақтайды; outcome_unknown mutation қайталамайды.
  • Автошот күндердің preview-ын көрсетеді, recurringInvoiceId/occurrenceId сақтайды және шығарылған, бірақ төленбеген шотты қайталамайды.
  • Дұрыс webhook қабылданады, қате қолтаңба қайтарылады, event id дубль қауіпсіз.
  • Git diff, browser bundle және логтарда құпия жоқ.
  • Тесттер өтеді; live Kaspi acceptance орындалмаса, бөлек қадам ретінде көрсетіледі.

Агент оқуы тиіс дереккөздер

WhatsApp-қа жазу