# Create a payment

`POST /payments`

Creates a payment and attempts to charge the given payment method.
Use an `Idempotency-Key` header to safely retry.

Base URL: https://api.acme.dev/v1

Authentication: bearer token in Authorization header

## Header parameters

| Name | Type | Required | Description |
|---|---|---|---|
| `Idempotency-Key` | UUID | no | A unique key to make the request idempotent. |

## Request body

Content type: `application/json`

| Field | Type | Required | Description |
|---|---|---|---|
| `amount` | integer | yes | Amount in the smallest currency unit. |
| `currency` | string | yes | Three-letter ISO currency code. |
| `customer` | string | no | ID of an existing customer. |
| `description` | string | no |  |
| `metadata` | map from strings to strings | no | Up to 50 key/value pairs. |
| `payment_method` | union | no |  |

## Example request

```bash
curl -X POST https://api.acme.dev/v1/payments \
  -H "Content-Type: application/json" \
  -d '{"amount":2500,"currency":"usd","customer":"cus_8f3k2","description":"Pro plan — June"}'
```

## Responses

- **201**: The created payment.
- **400**: The request was malformed.
- **402**: The card was declined.

### Example response (201)

```json
{
  "id": "pay_3Jk2Lm",
  "object": "payment",
  "amount": 2500,
  "currency": "usd",
  "status": "requires_payment_method",
  "customer": {
    "id": "cus_8f3k2",
    "email": "user@example.com",
    "name": "Ada Lovelace",
    "address": {
      "line1": "string",
      "city": "string",
      "country": "US"
    }
  },
  "created_at": "2024-01-15T09:30:00Z",
  "refunds": [
    {
      "id": "string",
      "amount": 1
    }
  ]
}
```
