Skip to main content
This recipe creates a cash-on-delivery order with POST /api/v1/orders and sends the very same body, under the same partner_reference, on every retry, so a retry can never create a second order. After no answer, a 429 or a 5xx, it waits Retry-After, or 1, 2, 4, then 8 seconds with jitter, at most five times. Those numbers are the recipe’s choice: change them, but keep a limit and a pause. The Next.js, FastAPI, Laravel and Spring forms take the reference from your own order_id. Never open such a route to your shop’s visitors: anyone who can call it places orders on your account. Each form refuses a call without the secret in INTERNAL_ROUTE_SECRET (sent as X-Internal-Secret); keep the route behind your app’s own authentication too. It returns the reference, the status and the replay flag, never the order’s money.

Prerequisites

  • MART_API_KEY: your API key, with the orders:write scope.
  • MART_API_BASE: https://sandbox.mart.ps while you build, https://mart.ps when you go live.
  • MART_PRODUCT_ID and MART_STATE_ID: a product your key is offered and a town’s states[].id.
  • MART_PARTNER_REFERENCE: your own id for this order, up to 64 letters, digits, dots, underscores or hyphens. Keep it with the order.
One runtime: cURL 7.84 or later with jq; Node 22.18 or later, which runs the .ts file as it is; Python 3.9 or later with httpx; PHP 7.4 or later with its curl extension; Go 1.22 or later; or Java 17 or later with Jackson (jackson-databind). Each file reads its variables from the environment and sets a timeout on every call. Run it on your own server: a browser or an app never holds the key.

Run the recipe

Verify the result

Run it twice with the same MART_PARTNER_REFERENCE:
The second run prints the same lines with replay: true: the same order, as a retry after a lost answer receives it. A retry first prints a line on stderr, for example retry: attempt 1 answered 429, waiting 2.0 s.

Troubleshooting

Every other code is in the error catalog.