Skip to content

Idempotency

Download .md

Network calls fail. When you retry POST /gateway/sessions/, you must not create a second payment for the same order. Paymee makes session creation idempotent through the merchant_reference field.

merchant_reference is your unique identifier for a payment (an order id, a cart id, an invoice number — whatever is stable on your side).

  • The first request with a given merchant_reference creates the session and returns 201 Created.
  • A subsequent request with the same merchant_reference returns the existing session with 200 OK — no duplicate is created.
Terminal window
# First call → 201 Created, new session
curl https://api.paymee.online/api/v1/gateway/sessions/ \
-H "Authorization: Bearer sk_live_…" -H "Content-Type: application/json" \
-d '{ "amount": "10.500", "merchant_reference": "order-0001", "first_name": "Aymen", "last_name": "Ben Salah", "email": "aymen@example.com" }'
# Same merchant_reference → 200 OK, the same session is returned
  • Generate merchant_reference once per order, before the first attempt, and reuse it on every retry of that order.
  • Use a new merchant_reference only when you genuinely want a new payment (e.g. the buyer is paying again after a failure that closed the session).
  • Keep it unique per merchant account.

If a request conflicts with the current state of an existing session, you receive 409 Conflict as an RFC 9457 problem document, which may include an existing_session_id.