New in 2.4: Test runs you can trust See what's new →

Create a payment

POSThttps://api.testingapis.com/api/Payments

Create a payment. Requires an Idempotency-Key header.

Header: Idempotency-Key: <unique value, e.g. a UUID> (max 255 characters, remembered for 24 hours).

Same key and same body: the original response is replayed with Idempotent-Replayed: true. Bodies are compared after canonicalizing, so key order and whitespace don't matter. Same key and a different body: 422. Same key while the first request is still processing: 409. A request that fails validation isn't remembered, so its key can be reused. Test data: cardLast4 0002 is always declined (status failed, still 201). bank_transfer payments start as pending.

Note: Retrying with the same Idempotency-Key and body replays the stored response (Idempotent-Replayed: true). A card ending 0002 is always declined.

Parameters 2

NameTypeDescription
processingSecondsquery · integer (int32)Hold the request open for this many seconds (max 5) so a duplicate can be sent while it is in flight. Default: 0.
Idempotency-Keyrequiredheader · stringUnique key per logical payment. Same key + same body replays the stored response; a different body returns 422.

Request body

Optional. application/json, text/json, application/*+json, application/xml, text/xml, application/*+xml. userId, orderId (optional), amount (greater than 0, max 1,000,000), currency (3-letter code), method (card, upi, paypal or bank_transfer), description, cardLast4 (4 digits, required for card).

Example body
{
  "userId": 101,
  "amount": 49.99,
  "currency": "usd",
  "method": "card",
  "cardLast4": "4242",
  "description": "Order #1001"
}

Responses

200
OK
201
Payment created, or the original response replayed.
400
Idempotency-Key missing or too long, or the body is invalid.
409
A request with the same key is still being processed.
422
The key was already used with a different body.

Example

Request
curl -X POST "https://api.testingapis.com/api/Payments" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: {{uuid}}" \
  -d '{"userId": 101, "amount": 49.99, "currency": "usd", "method": "card", "cardLast4": "4242", "description": "Order #1001"}'
Run in Studio
Response201 Created
{
  "message": "Payment created successfully",
  "idempotencyKey": "cda26651-04d6-4941-8323-2fcaffd05efa",
  "data": {
    "id": 14,
    "userId": 101,
    "orderId": null,
    "amount": 49.99,
    "currency": "USD",
    "method": "card",
    "status": "succeeded",
    "description": "Order #1001",
    "cardLast4": "4242",
    "createdAt": "2026-09-30T18:26:45Z",
… (3 more lines)

Code examples

JavaScript (fetch)
const response = await fetch("https://api.testingapis.com/api/Payments", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "Idempotency-Key": "{{uuid}}",
  },
  body: "{\"userId\": 101, \"amount\": 49.99, \"currency\": \"usd\", \"method\": \"card\", \"cardLast4\": \"4242\", \"description\": \"Order #1001\"}",
});
console.log(response.status, await response.text());
Python (requests)
import requests

response = requests.request(
    "POST",
    "https://api.testingapis.com/api/Payments",
    headers={
        "Content-Type": "application/json",
        "Idempotency-Key": "{{uuid}}",
    },
    data="{\"userId\": 101, \"amount\": 49.99, \"currency\": \"usd\", \"method\": \"card\", \"cardLast4\": \"4242\", \"description\": \"Order #1001\"}".encode("utf-8"),
    allow_redirects=False,
)
print(response.status_code, response.text)
Java (HttpClient)
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

public class Main {
    public static void main(String[] args) throws Exception {
        HttpClient client = HttpClient.newBuilder()
            .followRedirects(HttpClient.Redirect.NEVER)
            .build();

        HttpRequest request = HttpRequest.newBuilder()
            .uri(URI.create("https://api.testingapis.com/api/Payments"))
            .header("Content-Type", "application/json")
            .header("Idempotency-Key", "{{uuid}}")
            .method("POST", HttpRequest.BodyPublishers.ofString("{\"userId\": 101, \"amount\": 49.99, \"currency\": \"usd\", \"method\": \"card\", \"cardLast4\": \"4242\", \"description\": \"Order #1001\"}"))
            .build();

        HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
        System.out.println(response.statusCode() + " " + response.body());
    }
}