Build with AI

Working with Claude, ChatGPT, Copilot, or another assistant? Copy the prompt below into your AI tool of choice to scaffold your direct POSLink API integration.

Feed it the full docs
Every page on this portal has a "Copy as Markdown" button in the top right. Paste the pages the prompt references into your AI's context for the best results, or point it at the OpenAPI specs on the Downloads page.
You are helping me integrate my ePOS application directly with the Teya POSLink API.
My platform has no Teya SDK available, so my application must handle authentication,
token refresh, and the payment flow itself over REST.

My stack: [describe your backend language/framework]

Key facts:
- OAuth 2.0 against https://id.teya.com/oauth/v2/ using either Code Flow with PKCE
  (browser-capable devices) or Device Code Flow (QR scan for limited-input devices).
  The merchant logs in with their Teya account email; my backend receives access and
  refresh tokens for their store. Refresh tokens are single use - refresh proactively.
- I need a Client ID and Client Secret from the Teya Developer Portal (partner.teya.xyz for
  development, partner.teya.com for production). This is one set for my whole application,
  not one per merchant - merchants authenticate separately with their own Teya ID.
- API base: https://api.teya.com
- List merchant stores: GET /poslink/v1/stores (bearer token)
- List card machines for a store: GET /poslink/v1/stores/{store_id}/terminals (bearer token)
- Create a payment request: POST /poslink/v3/payment-requests with store_id,
  terminal_id, requested_amount {amount, currency}, transaction_type "SALE",
  merchant_reference, epos_instance_id, and an Idempotency-Key header.
- Track results over Server-Sent Events: GET /v2/payment-requests/{payment_request_id}
  with Accept: text/event-stream. Events are "full" (complete snapshot, sent first and last)
  and "diff" (incremental updates while IN_PROGRESS). The final "full" event with a terminal
  status (SUCCESSFUL, FAILED, CANCELLED) is authoritative; reconnect if the stream closes
  before a terminal status is reached.

Documentation to follow (read these before writing code):
- https://docs.teya.com/poslink/authenticate
- https://docs.teya.com/poslink/develop/connect-terminal
- https://docs.teya.com/poslink/develop/send-payment-request
- https://docs.teya.com/poslink/develop/transaction-updates
- Full endpoint schemas: https://docs.teya.com/apis/poslink/apis
  (OpenAPI spec download available on that page)

Task: implement merchant authentication with one OAuth flow, store/card machine
pairing, payment request creation, and SSE status tracking. Use the exact endpoints
and fields from the documentation - do not invent fields or endpoints. If unsure,
tell me to check the docs rather than guessing.