Payment Intents
A Payment Intent is an object that represents your intent to collect payment from a customer and tracks the lifecycle of the payment process. It is a central object in the PaymentKit API, controlling the flow of funds from the customer to you. A Payment Intent can be associated with a Checkout Session for a user-facing payment flow or used directly for server-side operations.
This document details how to manage Payment Intent objects using the SDK.
The Payment Intent Object#
A Payment Intent object contains detailed information about a transaction. When expanded, it can also include related objects.
Object Properties
Property | Type | Description |
|---|---|---|
|
| Unique identifier for the object. |
|
| The status of the payment intent. Possible values are |
|
| The amount intended to be collected. |
|
| The amount received so far. |
|
| The ID of the currency for this payment. |
|
| The ID of the Customer this Payment Intent is for, if one exists. |
|
| The ID of the Invoice this Payment Intent is for, if one exists. |
|
| The ID of the PaymentMethod used for this Payment Intent. |
|
| A set of key-value pairs that you can attach to an object. |
|
| Timestamp of when the object was created. |
Expanded Objects
When retrieved, the Payment Intent object can include the following expanded objects:
customer: The fullCustomerobject.paymentCurrency: The fullPaymentCurrencyobject.paymentMethod: The fullPaymentMethodobject.invoice: The fullInvoiceobject (when applicable).subscription: The fullSubscriptionobject (when applicable).checkoutSession: TheCheckoutSessionthat created this payment intent.
Retrieve a Payment Intent#
Retrieves the details of a Payment Intent that has previously been created. Client-side retrieval using a publishable key is allowed when the client_secret is provided.
Retrieve a Payment Intent
const paymentIntent = await payment.paymentIntents.retrieve(
'pi_123456789'
);
console.log(paymentIntent);Parameters
Name | Type | Description |
|---|---|---|
|
| Required. The ID of the Payment Intent to retrieve. |
Returns
Returns a PaymentIntent object if a valid ID was provided. Throws an error otherwise.
Response Example
{
"id": "pi_123456789",
"status": "succeeded",
"amount": "1000",
"amount_received": "1000",
"currency_id": "cur_xxxxxxxx",
"customer_id": "cus_xxxxxxxx",
"invoice_id": "in_xxxxxxxx",
"payment_method_id": "pm_xxxxxxxx",
"metadata": {},
"created_at": "2023-10-27T10:00:00.000Z",
"paymentCurrency": {
/* ... payment currency details ... */
},
"paymentMethod": {
/* ... payment method details ... */
},
"customer": {
/* ... customer details ... */
},
"invoice": {
/* ... invoice details ... */
},
"subscription": null,
"checkoutSession": {See all 3 lines
Update a Payment Intent#
Updates a Payment Intent object by setting the values of the parameters passed. Any parameters not provided will be left unchanged. Note that only the metadata can be updated via this method.
Update a Payment Intent
const paymentIntent = await payment.paymentIntents.update(
'pi_123456789',
{
metadata: { order_id: '6735' }
}
);
console.log(paymentIntent);Parameters
Name | Type | Description |
|---|---|---|
|
| Required. The ID of the Payment Intent to update. |
|
| A set of key-value pairs to store on the object. |
Returns
Returns the updated PaymentIntent object.
Response Example
{
"id": "pi_123456789",
"status": "succeeded",
"amount": "1000",
"metadata": {
"order_id": "6735"
},
// ... other properties
}List all Payment Intents#
Returns a list of your Payment Intents. The intents are returned sorted by creation date, with the most recent intents appearing first.
List Payment Intents
const paymentIntents = await payment.paymentIntents.list({
limit: 5,
status: 'succeeded'
});
console.log(paymentIntents);Parameters
Name | Type | Description |
|---|---|---|
|
| Optional. A comma-separated string of statuses to filter by (e.g., |
|
| Optional. Only return Payment Intents for the given invoice. |
|
| Optional. Only return Payment Intents for the given customer ID. |
|
| Optional. Only return Payment Intents for the given customer DID. |
|
| Optional. Filter by a specific metadata key-value pair. |
|
| Optional. The page number for pagination, starting from 1. Default is |
|
| Optional. A limit on the number of objects to be returned, between 1 and 100. Default is |
Returns
A paginated object containing a list of PaymentIntent objects and pagination details.
Response Example
{
"count": 15,
"list": [
{
"id": "pi_123456789",
"status": "succeeded",
// ... other properties
},
{
"id": "pi_987654321",
"status": "succeeded",
// ... other properties
}
// ... more payment intents
],
"paging": {
"page": 1,
"pageSize": 5
}
}Search Payment Intents#
Searches for Payment Intents matching a specific query.
Search Payment Intents
const results = await payment.paymentIntents.search({
query: 'cus_xxxxxxxx'
});
console.log(results);Parameters
Name | Type | Description |
|---|---|---|
|
| Required. The search query string. |
|
| Optional. The page number for pagination, starting from 1. Default is |
|
| Optional. The number of items per page. Default is |
Returns
A paginated object containing a list of PaymentIntent objects that match the search query.
Response Example
{
"count": 1,
"list": [
{
"id": "pi_123456789",
"customer_id": "cus_xxxxxxxx",
// ... other properties
}
],
"paging": {
"page": 1,
"pageSize": 20
}
}Refund a Charge#
When a Payment Intent is successful, you can create a refund for the charge. This will create a Refund object and attempt to reverse the charge.
Refund a Charge
const refund = await payment.paymentIntents.refund(
'pi_123456789',
{
amount: '500',
reason: 'requested_by_customer',
description: 'Refund for item not received.'
}
);
console.log(refund);Parameters
Name | Type | Description |
|---|---|---|
|
| Required. The ID of the Payment Intent to refund. |
|
| Required. A positive string representing how much of this charge to refund. Can refund up to the total amount of the original charge. |
|
| Required. String indicating the reason for the refund. Valid values are: |
|
| Required. An explanation of the refund. |
Returns
Returns a new Refund object.
Response Example
{
"id": "re_abcdef123",
"type": "refund",
"livemode": false,
"amount": "500",
"description": "Refund for item not received.",
"status": "pending",
"reason": "requested_by_customer",
"currency_id": "cur_xxxxxxxx",
"customer_id": "cus_xxxxxxxx",
"payment_intent_id": "pi_123456789",
// ... other refund properties
}