Accept payments
Payments
Create one-time payments, refund them in full or in part, and handle 3D Secure.
Overview
A Payment represents a single charge against a customer. PaymentHooks routes the payment through one of your connected gateways using your routing rules (currency, amount, the customer's country, payment method, card brand or metadata), skips gateways that are currently failing, and retries a soft decline or an unreachable gateway on your next gateway (never a hard decline, see Gateway Routing). The Payment's gatewayId is the gateway that actually charged it. The REST API returns one Payment object (id prefix ph_pay_) with camelCase fields; there are no separate intent or charge objects. List responses include a top-level livemode flag that reflects your merchant mode setting.
Payments created by Checkout Sessions and Payment Links appear here too. For a customer-facing payment page, use Checkout Sessions.
Took a payment on another service (another gateway, PayPal, a bank transfer, cash)? Record it with External Transactions so it counts here too. Such payments have source: "external" and gatewayId: "external"; POST /v1/payments/:id/refund refuses them with 422 EXTERNAL_PAYMENT_REFUND.
Create a payment
curl -X POST https://paymenthooks.com/api/v1/payments \
-H "Authorization: Bearer phk_live_..." \
-H "Content-Type: application/json" \
-d '{"transactionLocalCurrencyAmount": 5000, "customerId": "ph_cus_8d2f6a1c3e5b7d9f0a2c4e6b8d1f3a5c", "transactionLocalCurrency": "USD", "description": "Order #1234", "idempotencyKey": "order_1234"}'Parameters
| Field | Type | Description |
|---|---|---|
transactionLocalCurrencyAmount | integer | Amount to charge in the smallest unit of transactionLocalCurrency (cents for USD). Must be a positive integer. transactionAmountUsdCents is converted at the live rate. |
customerId | string | ID of one of your customers (max 100 chars). A customer that does not exist or belongs to another merchant returns 404 NOT_FOUND. The customer's country is used for routing. |
transactionLocalCurrency | string | Three-letter ISO currency code to charge in, e.g. USD. Uppercased before routing and storage. There is no default. |
gatewayId | string | Force a specific gateway: a catalog gateway id (e.g. gw_stripe) or one of your connection ids (max 100 chars). The payment is sent only to that connection, never rerouted; if you have no active connection for it in your current mode, or it cannot take the payment, the response is 422 GATEWAY_NOT_CONNECTED. |
paymentMethod | stringDefault: | Payment method type, e.g. card (max 50 chars). |
description | string | Description for the payment (max 500 chars). |
metadata | object | Key-value pairs; values must be strings. |
idempotencyKey | string | Body field (not a header) that prevents duplicate payments (max 255 chars). Reusing a key with the same body replays the stored response with X-Idempotent-Replayed: true; reusing it with a different body returns 409 IDEMPOTENCY_CONFLICT. |
| Code | HTTP | Meaning |
|---|---|---|
| VALIDATION_ERROR | 400 | The body failed validation; error.fields maps each invalid field to a message |
| INSUFFICIENT_SCOPE | 403 | The API key lacks payments:write |
| NOT_FOUND | 404 | customerId does not exist or belongs to another merchant |
| IDEMPOTENCY_CONFLICT | 409 | idempotencyKey was reused with a different body |
| GATEWAY_NOT_CONNECTED | 422 | gatewayId was sent but no usable active connection for it exists in your current mode |
| INTERNAL_ERROR | 500 | The payment could not be created |
Endpoints & Responses
Request and response examples for each payments endpoint, using the { data, error } envelope. Some examples are abridged.
/v1/paymentsCreate a payment and route it to a gateway using your routing rules, or to the connection named by gatewayId. Returns 201. Scope: payments:write. If the gateway needs a redirect, redirectUrl is included.{
"transactionLocalCurrencyAmount": 5000,
"customerId": "ph_cus_8d2f6a1c3e5b7d9f0a2c4e6b8d1f3a5c",
"transactionLocalCurrency": "USD",
"description": "Order #1234",
"metadata": { "orderId": "1234" },
"idempotencyKey": "order_1234"
}{
"data": {
"id": "ph_pay_0c1d2e3f4a5b6c7d8e9f0a1b2c3d4e5f",
"merchantId": "ph_mrc_c9f0f895fb98ab9159f51fd0297e236d",
"customerId": "ph_cus_8d2f6a1c3e5b7d9f0a2c4e6b8d1f3a5c",
"gatewayId": "gw_stripe",
"gatewayTransactionId": "ch_3Nq2x...",
"transactionLocalCurrency": "USD",
"transactionLocalCurrencyAmount": 5000,
"transactionAmountUsdCents": 5000,
"transactionUsdToLocalCurrencyRate": 1,
"transactionFeeAmountUsdCents": 175,
"transactionNetAmountUsdCents": 4825,
"transactionRefundedAmountUsdCents": null,
"status": "success",
"paymentMethod": "card",
"description": "Order #1234",
"metadata": { "orderId": "1234" },
"createdAt": "2026-05-16T10:30:00.000Z",
"updatedAt": "2026-05-16T10:30:00.000Z"
},
"error": null,
"livemode": true
}/v1/payments?page=1&pageSize=10&status=successList payments, newest first. Filters: status, search (payment ID, customer ID, name or email, description, card last 4), customerId, dateFrom and dateTo (YYYY-MM-DD, inclusive), businessEntityId (one of your businesses; a business-scoped key sees only its own), sortField (id, amount or transactionAmountUsdCents, status, paymentMethod, createdAt; any other value sorts newest first), sortDirection. meta.total counts every match. pageSize max 100; an unknown parameter is 400 VALIDATION_ERROR. Scope: payments:read.{
"data": [
{
"id": "ph_pay_0c1d2e3f4a5b6c7d8e9f0a1b2c3d4e5f",
"transactionLocalCurrency": "INR",
"transactionLocalCurrencyAmount": 150000,
"transactionAmountUsdCents": 1575,
"transactionUsdToLocalCurrencyRate": 95.2253,
"transactionFeeAmountUsdCents": 37,
"transactionNetAmountUsdCents": 1538,
"transactionRefundedAmountUsdCents": null,
"status": "success",
"customerId": "ph_cus_8d2f6a1c3e5b7d9f0a2c4e6b8d1f3a5c",
"gatewayId": "gw_stripe",
"description": "Order #1234",
"subscriptionId": null,
"createdAt": "2026-05-16T10:30:00.000Z"
}
],
"meta": { "total": 42, "page": 1, "pageSize": 10 },
"error": null,
"livemode": true
}/v1/payments/:idRetrieve a payment, including its event timeline and customer. Scope: payments:read.{
"data": {
"id": "ph_pay_0c1d2e3f4a5b6c7d8e9f0a1b2c3d4e5f",
"merchantId": "ph_mrc_c9f0f895fb98ab9159f51fd0297e236d",
"customerId": "ph_cus_8d2f6a1c3e5b7d9f0a2c4e6b8d1f3a5c",
"gatewayId": "gw_stripe",
"gatewayTransactionId": "ch_3Nq2x...",
"transactionLocalCurrency": "USD",
"transactionLocalCurrencyAmount": 5000,
"transactionAmountUsdCents": 5000,
"transactionUsdToLocalCurrencyRate": 1,
"transactionFeeAmountUsdCents": 175,
"transactionNetAmountUsdCents": 4825,
"transactionRefundedAmountUsdCents": null,
"status": "success",
"paymentMethod": "card",
"cardLast4": null,
"cardBrand": null,
"description": "Order #1234",
"metadata": { "orderId": "1234" },
"disputeId": null,
"payoutId": null,
"subscriptionId": null,
"events": [],
"customer": { "id": "ph_cus_8d2f6a1c3e5b7d9f0a2c4e6b8d1f3a5c", "name": "Jane Doe", "email": "[email protected]" },
"createdAt": "2026-05-16T10:30:00.000Z",
"updatedAt": "2026-05-16T10:30:05.000Z"
},
"error": null
}/v1/payments/:idUpdate description and/or metadata. Only these two fields are editable: any other field, or a body with neither, returns 400 VALIDATION_ERROR. Scope: payments:write. Returns the same camelCase payment as GET.{
"description": "Updated order description",
"metadata": { "orderId": "1234", "note": "VIP customer" }
}{
"data": {
"id": "ph_pay_0c1d2e3f4a5b6c7d8e9f0a1b2c3d4e5f",
"customerId": "ph_cus_8d2f6a1c3e5b7d9f0a2c4e6b8d1f3a5c",
"transactionLocalCurrency": "USD",
"transactionLocalCurrencyAmount": 5000,
"transactionAmountUsdCents": 5000,
"transactionUsdToLocalCurrencyRate": 1,
"status": "success",
"gatewayId": "gw_stripe",
"gatewayTransactionId": "ch_3Nq2x...",
"description": "Updated order description",
"metadata": { "orderId": "1234", "note": "VIP customer" },
"createdAt": "2026-05-16T10:30:00.000Z",
"updatedAt": "2026-05-16T11:00:00.000Z"
},
"error": null
}/v1/payments/:id/refundRefund all or part of a payment through its gateway. transactionAmountUsdCents is in USD cents; the gateway is refunded the pro-rata share in the currency it charged (transactionLocalCurrency). Returns 201 with the Refund record. Scope: payments:write. Supports the Idempotency-Key header: the key is claimed before the gateway call, so a second request with the same key while the first is still running gets 409 IDEMPOTENCY_IN_PROGRESS; a successful refund is replayed for 24 hours, a failed one releases the key for a retry.{
"transactionAmountUsdCents": 2500,
"reason": "Customer requested partial refund"
}{
"data": {
"id": "ph_rfd_5e6f7a8b9c0d1e2f3a4b5c6d7e8f9a0b",
"paymentId": "ph_pay_0c1d2e3f4a5b6c7d8e9f0a1b2c3d4e5f",
"merchantId": "ph_mrc_c9f0f895fb98ab9159f51fd0297e236d",
"transactionLocalCurrency": "USD",
"transactionLocalCurrencyAmount": 2500,
"transactionAmountUsdCents": 2500,
"transactionUsdToLocalCurrencyRate": 1,
"reason": "Customer requested partial refund",
"status": "processed",
"gatewayRefundId": "re_3Nq2y...",
"failureReason": null,
"createdAt": "2026-05-16T12:00:00.000Z",
"processedAt": "2026-05-16T12:00:01.000Z"
},
"error": null
}Refunds
transactionAmountUsdCentsis required: a positive integer in USD cents. To refund in full, pass the remaining balance (transactionAmountUsdCents - transactionRefundedAmountUsdCents). The gateway is refunded the pro-rata share oftransactionLocalCurrencyAmount, intransactionLocalCurrency.reasonis an optional string.- Only payments with status
successordisputedcan be refunded. Adispute_lostpayment cannot: the disputed amount was already returned to the customer and is counted in its refunded total. - The refund is sent to the gateway synchronously. On success the response is
201withstatus: "processed"and the gateway'sgatewayRefundId. When the gateway accepts the refund but completes it later (for example a Stripe refund inpending), the response is201withstatus: "pending"and thegatewayRefundId; the amount stays counted intransactionRefundedAmountUsdCents, and the gateway's refund webhook later moves it toprocessed(the customer is emailed then) orfailed(the amount is released). - Concurrent refunds of one payment are serialized: together they can never exceed
transactionAmountUsdCents, and the gateway is never asked for more thantransactionLocalCurrencyAmount. A request that no longer fits gets400 EXCEEDS_REFUNDABLE. - A partial refund increases the payment's
transactionRefundedAmountUsdCentsand leaves its status unchanged. When it reachestransactionAmountUsdCents, the payment status becomesrefunded. - A
payment.refundedwebhook is sent to your registered endpoints after every refund the gateway accepts (processed or pending), and again when a pending refund is settled by the gateway.
| Code | HTTP | Meaning |
|---|---|---|
| VALIDATION_ERROR | 400 | Body is not JSON, transactionAmountUsdCents is missing, or it is not a positive integer |
| EXCEEDS_REFUNDABLE | 400 | transactionAmountUsdCents is larger than the payment's transactionAmountUsdCents minus transactionRefundedAmountUsdCents |
| INSUFFICIENT_SCOPE | 403 | The API key lacks payments:write |
| NOT_FOUND | 404 | Payment does not exist or belongs to another merchant |
| GATEWAY_NOT_CONNECTED | 409 | No active connection to the payment's gateway; refund from the gateway dashboard instead |
| INVALID_STATE | 422 | Payment status is not success or disputed, or it has no gateway transaction id |
| EXTERNAL_PAYMENT_REFUND | 422 | The payment was recorded from another service (source external): refund it there and record it with POST /v1/external-transactions/:id/refunds |
| GATEWAY_REJECTED | 502 | The gateway refused the refund; the message carries its reason and nothing was refunded |
Capture
Payments created with POST /v1/payments are captured automatically; authorize-now, capture-later is not available through this endpoint, and no connected gateway supports it. POST /v1/payments/:id/capture exists only for requires_capture payments simulated in test mode. For a live payment it returns:
{
"data": null,
"error": {
"code": "CAPTURE_NOT_SUPPORTED",
"message": "Manual capture is not supported for gateway \"gw_stripe\". Capture the authorization from the gateway dashboard."
}
}3D Secure (step-up authentication)
Hosted checkout runs 3D Secure for you: when a card payment needs a challenge, the payment is stored with status action_required and the checkout pay response includes requiresAction: true, actionType: "3ds", and actionUrl. If the session has a webhookUrl, it also receives payment.requires_action.
For server-side integrations, two endpoints expose the 3DS engine directly (any authenticated key):
POST /v1/payments/:id/3dsevaluates whether the payment needs 3DS and records the result. Body:cardBin,customerEmail,customerCountry,browserInfo,returnUrl(all optional). Returns202whenstatusischallenge_required, otherwise200.- If a
challengeUrlis returned, send the customer to it to complete authentication. GET /v1/payments/:id/3dsreturns the most recent 3DS record:status,version,eci,authenticationValue(CAVV/AAV),dsTransId,challengeUrl, andexemption.- When the challenge completes, the payment status becomes
successif authenticated, otherwisefailed. Confirm the outcome withGET /v1/payments/:id.
3DS status values: not_required, required (resubmit with browserInfo), challenge_required, authenticated, failed, error. exemption is one of low_value, trusted_beneficiary, transaction_risk_analysis, recurring_payment, secure_corporate_payment, none.
curl -X POST https://paymenthooks.com/api/v1/payments/ph_pay_0c1d2e3f4a5b6c7d8e9f0a1b2c3d4e5f/3ds \
-H "Authorization: Bearer phk_live_..." \
-H "Content-Type: application/json" \
-d '{"cardBin":"424242","customerEmail":"[email protected]","customerCountry":"DE","returnUrl":"https://yoursite.com/payments/complete"}'{
"data": {
"status": "challenge_required",
"version": "2.2",
"challengeUrl": "https://paymenthooks.com/api/v1/payments/ph_pay_0c1d2e3f4a5b6c7d8e9f0a1b2c3d4e5f/3ds/challenge?gateway=gw_stripe&returnUrl=...",
"challengeToken": "...",
"exemption": "none"
},
"error": null
}Payment statuses
pendingCreated; the gateway has not confirmed the outcome yetaction_requiredAwaiting customer authentication (3D Secure). See the 3D Secure sectionrequires_captureAuthorized but not captured. Not produced by POST /v1/payments; see CapturesuccessPayment completed successfullyfailedPayment was declined or failedrefundedFully refunded (transactionRefundedAmountUsdCents equals transactionAmountUsdCents)disputedA dispute (chargeback) was opened against the payment. When it is won the payment returns to success (or refunded if it was already fully refunded)dispute_lostA dispute was lost: the disputed amount went back to the customer and is counted in transactionRefundedAmountUsdCents (capped at the charge). Final; cannot be refunded