Payments API
Process payments, manage transactions, and handle payment methods through the PaymentFlow API.
Authentication
All API requests must include an API key in the Authorization header. You can obtain your
API key from the Dashboard under Settings → API Keys.
curl https://api.paymentflow.com/v2/payments \
-H "Authorization: Bearer pk_live_abc123xyz" \
-H "Content-Type: application/json"
Create a Payment
Create a new payment transaction to charge a customer's payment method.
/v2/payments
Request Parameters
| Parameter | Type | Description |
|---|---|---|
amount required |
integer | Payment amount in cents (e.g., 1000 for $10.00) |
currency required |
string | Three-letter ISO currency code (e.g., "usd", "eur", "gbp") |
payment_method required |
string | ID of the payment method to charge |
customer optional |
string | ID of an existing customer |
description optional |
string | Description of the payment (max 500 characters) |
metadata optional |
object | Set of key-value pairs for storing additional information |
capture optional |
boolean | Whether to immediately capture the payment. Default is true |
Example Request
{
"amount": 2500,
"currency": "usd",
"payment_method": "pm_1JXvZ2H3M5nN6oP7",
"customer": "cus_abc123",
"description": "Order #12345",
"metadata": {
"order_id": "12345",
"product": "Premium Plan"
}
}
Example Response
{
"id": "pay_1JXw8LH3M5nN6oP7",
"object": "payment",
"amount": 2500,
"currency": "usd",
"status": "succeeded",
"payment_method": "pm_1JXvZ2H3M5nN6oP7",
"customer": "cus_abc123",
"description": "Order #12345",
"metadata": {
"order_id": "12345",
"product": "Premium Plan"
},
"created": 1678901234,
"receipt_url": "https://paymentflow.com/receipts/pay_1JXw8LH3M5nN6oP7"
}
Retrieve a Payment
Retrieve the details of an existing payment transaction.
/v2/payments/:id
Path Parameters
| Parameter | Type | Description |
|---|---|---|
id required |
string | The unique identifier of the payment |
Example Request
curl https://api.paymentflow.com/v2/payments/pay_1JXw8LH3M5nN6oP7 \
-H "Authorization: Bearer pk_live_abc123xyz"
.
List All Payments
Returns a list of payments. Results are paginated and sorted by creation date, with the most recent payments appearing first.
/v2/payments
Query Parameters
| Parameter | Type | Description |
|---|---|---|
limit optional |
integer | Number of results to return (1-100). Default is 10 |
starting_after optional |
string | Cursor for pagination. Returns results after this payment ID |
customer optional |
string | Filter by customer ID |
status optional |
string | Filter by status: succeeded, pending, failed, canceled |
Cancel a Payment
Cancel a payment that has not yet been captured. Once a payment is captured, it cannot be canceled— you must create a refund instead.
/v2/payments/:id
Payment Statuses
A payment can have one of the following statuses throughout its lifecycle:
| Status | Description |
|---|---|
pending |
Payment has been created but not yet processed |
requires_action |
Additional authentication required (e.g., 3D Secure) |
processing |
Payment is being processed by the payment network |
succeeded |
Payment was successful and funds have been captured |
failed |
Payment failed due to an error or declined by the bank |
canceled |
Payment was canceled before capture |
Error Handling
PaymentFlow uses conventional HTTP response codes to indicate the success or failure of an API request. Codes in the 2xx range indicate success, 4xx indicate an error with the request, and 5xx indicate an error with PaymentFlow's servers.
Common Error Codes
| Code | Error Type | Description |
|---|---|---|
| 400 | Bad Request | The request was malformed or missing required parameters |
| 401 | Unauthorized | Invalid or missing API key |
| 402 | Payment Required | The payment method was declined |
| 404 | Not Found | The requested resource does not exist |
| 429 | Rate Limit Exceeded | Too many requests in a short period |
| 500 | Internal Server Error | Something went wrong on PaymentFlow's end |
Error Response Format
{
"error": {
"type": "card_error",
"code": "card_declined",
"message": "Your card was declined",
"param": "payment_method"
}
}
Need help? Contact our support team at support@paymentflow.com or join our developer community.