Skip to content

Cancel a payment intent

POST
/v1/payment_intents/{id}/cancel
curl --request POST \
--url https://api.example.com/v1/payment_intents/example/cancel \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--header 'Idempotency-Key: order-1042-attempt-1' \
--data '{ "cancellation_reason": "duplicate" }'

Cancels an intent the customer has not paid: one that is requires_payment_method, requires_confirmation or requires_action. Canceling one already canceled answers it unchanged. Once it is processing or succeeded, or while a confirm is still reaching the payment method, it cannot be canceled: that is a conflict.

id
required
string

The object’s id.

Idempotency-Key
required
string
<= 255 characters

A value unique to this operation, such as your order number and attempt, of 1 to 255 characters. A retry with the same key and body is done at most once; see Idempotency.

Example
order-1042-attempt-1
Media typeapplication/json
object
cancellation_reason

Why you are canceling it. Optional.

string
Allowed values: requested_by_customer duplicate fraudulent abandoned
Examples
Exampleduplicate
{
"cancellation_reason": "duplicate"
}

The intent, in canceled, with canceled_at and cancellation_reason.

Media typeapplication/json
object
id
required
string
object
required
string
Allowed value: payment_intent
amount
required

In the currency’s minor unit.

integer
amount_received
required

The amount paid: amount once succeeded, and 0 until then.

integer
currency
required

A three-letter ISO 4217 code, in lower case.

string
/^[a-z]{3}$/
payment_method_types
required

The chosen method, such as [qrph], once there is one. Until then, the methods that can take this payment now: confirm with one. In an event for an intent with no method, the methods you allowed at creation, or null if you allowed any.

Array<string> | null
channel
required

Where the payment is taken: ecommerce for every intent your server creates. Payments taken on terminals will say pos (Pending).

string
status
required
string
Allowed values: requires_payment_method requires_confirmation requires_action processing succeeded canceled
next_action
required
One of:
object
type
required
string
Allowed value: qrph_display_qr_code
qrph_display_qr_code
required
object
data
required

The QR payload. Render it as a QR code for the customer to scan with their banking app.

string
expires_at
required

When the code stops being payable, as a Unix timestamp.

integer | null
last_payment_error
required
One of:
object
code
required

card_declined: the card was declined. expired_card: the card has expired (test mode only today). payment_intent_authentication_failure: the customer did not complete the card’s authentication. payment_intent_payment_attempt_failed: the attempt failed, or the customer left without paying. payment_intent_payment_attempt_expired: the customer did not pay in time.

string
Allowed values: card_declined expired_card payment_intent_authentication_failure payment_intent_payment_attempt_failed payment_intent_payment_attempt_expired
decline_code

Why the card was declined, when the decline names a reason. Test mode only today: it appears when you simulate a decline with a decline_reason (see Simulate a payment’s outcome), and a live decline does not carry it yet, so never depend on it there.

string
Allowed values: insufficient_funds do_not_honor expired_card
message
required

Words you can show the customer. May be reworded, so never branch on it.

string
cancellation_reason
required

The reason given when it was canceled, if any.

string | null
Allowed values: requested_by_customer duplicate fraudulent abandoned
canceled_at
required

When it was canceled, as a Unix timestamp.

integer | null
description
required
string | null
metadata
required

The metadata you gave it. {} if none.

object
key
additional properties
string
livemode
required
boolean
created
required

When it was created, as a Unix timestamp.

integer
Example
{
"id": "pi_01j9x2m8k4q7r5t3v6w8y0z2a4",
"object": "payment_intent",
"currency": "php",
"payment_method_types": [
"card",
"qrph"
],
"channel": "ecommerce",
"status": "requires_payment_method",
"next_action": {
"type": "qrph_display_qr_code"
},
"last_payment_error": {
"code": "card_declined",
"decline_code": "insufficient_funds"
},
"cancellation_reason": "requested_by_customer",
"created": 1790411400
}
X-Request-ID
string

This request’s id. Quote it when you contact support.

validation_failure: invalid_parameter for a parameter missing or not valid, named in param; invalid_json for a body that is not JSON; unsupported_media_type for a body that is not sent as JSON; not_acceptable when the request will not accept JSON; method_not_allowed for an HTTP method the path does not take.

Media typeapplication/json
object
error
required
object
type
required
string
Allowed values: validation_failure authentication_failure authorization_failure not_found conflict timeout_or_in_progress policy_rejection invariant_violation rate_limited dependency_failure
code
required

A stable name for this refusal. Branch on this, never on message.

string
message
required

For the developer reading a log. May be reworded.

string
param
required

The field or parameter at fault, when there is one.

string | null
request_id
required
string | null
Example
{
"error": {
"type": "validation_failure",
"code": "invalid_parameter",
"message": "A whole number of minor units, from 1 to 999999999999999999.",
"param": "amount",
"request_id": "req_4f1c0b2e9a7d"
}
}

authentication_failure: access_token_required when no token was sent, invalid_access_token when it is not valid, has expired, or is a client secret. Sent with a WWW-Authenticate: Bearer header, which adds error="invalid_token" when a token was sent.

Media typeapplication/json
object
error
required
object
type
required
string
Allowed values: validation_failure authentication_failure authorization_failure not_found conflict timeout_or_in_progress policy_rejection invariant_violation rate_limited dependency_failure
code
required

A stable name for this refusal. Branch on this, never on message.

string
message
required

For the developer reading a log. May be reworded.

string
param
required

The field or parameter at fault, when there is one.

string | null
request_id
required
string | null
Example
{
"error": {
"type": "validation_failure"
}
}

authorization_failure with merchant_mismatch: a Merchant-Id header, query parameter or body field names a merchant or tenant other than the key’s.

Media typeapplication/json
object
error
required
object
type
required
string
Allowed values: validation_failure authentication_failure authorization_failure not_found conflict timeout_or_in_progress policy_rejection invariant_violation rate_limited dependency_failure
code
required

A stable name for this refusal. Branch on this, never on message.

string
message
required

For the developer reading a log. May be reworded.

string
param
required

The field or parameter at fault, when there is one.

string | null
request_id
required
string | null
Example
{
"error": {
"type": "validation_failure"
}
}

not_found: resource_missing for an id this key cannot see, route_missing for a path that does not exist.

Media typeapplication/json
object
error
required
object
type
required
string
Allowed values: validation_failure authentication_failure authorization_failure not_found conflict timeout_or_in_progress policy_rejection invariant_violation rate_limited dependency_failure
code
required

A stable name for this refusal. Branch on this, never on message.

string
message
required

For the developer reading a log. May be reworded.

string
param
required

The field or parameter at fault, when there is one.

string | null
request_id
required
string | null
Example
{
"error": {
"type": "validation_failure"
}
}

conflict: intent_state when the intent is not in a state that allows this; idempotency_key_reused when the Idempotency-Key was used for a different request. timeout_or_in_progress with idempotency_key_in_use while a request with the same key is still running, or with refund_in_progress for a refund while another refund of the same payment is still being processed.

Media typeapplication/json
object
error
required
object
type
required
string
Allowed values: validation_failure authentication_failure authorization_failure not_found conflict timeout_or_in_progress policy_rejection invariant_violation rate_limited dependency_failure
code
required

A stable name for this refusal. Branch on this, never on message.

string
message
required

For the developer reading a log. May be reworded.

string
param
required

The field or parameter at fault, when there is one.

string | null
request_id
required
string | null
Example
{
"error": {
"type": "validation_failure"
}
}

dependency_failure with service_unavailable: something on our side, or a payment network behind it, did not answer, or failed part-way. Whether the call took effect is not known, so do not assume it did not. Retry the same request with the same Idempotency-Key, and never make a new key for the retry: if the first call took effect, you are answered with its result (the payment intent or refund it made, or the intent as it now is) and nothing is done a second time. A retry refused with conflict and intent_state means the intent is no longer in a state that allows the call: the first call may have taken effect, or the customer may have acted since. Read the intent. If the failure came while the answer was being stored, the key is held for five minutes and a retry in that time answers 409 with idempotency_key_in_use: retry shortly. See When a write answers 503.

Media typeapplication/json
object
error
required
object
type
required
string
Allowed values: validation_failure authentication_failure authorization_failure not_found conflict timeout_or_in_progress policy_rejection invariant_violation rate_limited dependency_failure
code
required

A stable name for this refusal. Branch on this, never on message.

string
message
required

For the developer reading a log. May be reworded.

string
param
required

The field or parameter at fault, when there is one.

string | null
request_id
required
string | null
Example
{
"error": {
"type": "validation_failure"
}
}