Prices
A Price object defines how much and how often to charge for a specific product. It associates a price amount and currency with a Product. For example, a product might have multiple prices, each in a different currency or with a different billing interval.
This document details how to manage Price objects using the SDK.
The Price Object#
A Price object contains all the details about the pricing model for a product.
Attribute | Type | Description |
|---|---|---|
| string | Unique identifier for the price object. |
| string | The ID of the product this price is associated with. |
| object | The expanded Product object. |
| boolean | Whether the price can be used for new purchases. |
| string | The ID of the default currency for this price. |
| object | The expanded PaymentCurrency object. |
| string | A brief description of the price, displayed to customers. |
| string | One of |
| string | The price in the smallest currency unit (e.g., cents for USD). |
| object | For recurring prices, this hash contains billing interval information. See details below. |
| string | A unique, user-defined key to retrieve the price. |
| object | A set of key-value pairs that you can attach to an object. |
| array | Specifies different pricing for multiple currencies. |
| number | The total available quantity for this price. |
| number | The number of units sold. |
| number | The maximum quantity a customer can purchase in a single checkout. |
| object | Configuration for upselling to another price. |
The recurring Object Properties
Attribute | Type | Description |
|---|---|---|
| string | The frequency at which a subscription is billed. One of |
| number | The number of intervals between subscription billings. |
| string | The ID of the meter used for usage-based billing. |
Create a Price#
Creates a new price for an existing product.
Create a Price
async function createPrice() {
try {
const price = await payment.prices.create({
product_id: 'prod_xxxxxxxxxxxxxx',
unit_amount: 1500, // e.g., $15.00
currency_id: 'usd_xxxxxxxxxxxxxx',
type: 'recurring',
recurring: {
interval: 'month',
interval_count: 1,
},
nickname: 'Monthly Pro Plan',
lookup_key: 'pro_monthly_usd',
});
console.log('Price created:', price);
} catch (error) {
console.error('Error creating price:', error.message);
}
}
createPrice();Parameters#
Name | Type | Description |
|---|---|---|
| string | Required. The ID of the product this price belongs to. |
| number | Required. The amount to be charged, in the smallest currency unit. |
| string | Required. The ID of the currency for this price. |
| string | The type of pricing. Can be |
| boolean | Whether the price is active. Defaults to |
| string | An internal name for the price. |
| string | A unique string to reference the price. |
| object | An object containing recurring billing information. Required if |
| array | An array of objects to specify prices in different currencies. |
| object | Key-value data to store with the price. |
| number | The total available quantity. Defaults to |
| number | The maximum quantity per checkout. Defaults to |
Returns#
Returns the newly created Price object.
Response
{
"id": "price_xxxxxxxxxxxxxx",
"product_id": "prod_xxxxxxxxxxxxxx",
"active": true,
"currency_id": "usd_xxxxxxxxxxxxxx",
"nickname": "Monthly Pro Plan",
"type": "recurring",
"unit_amount": "1500",
"recurring": {
"interval": "month",
"interval_count": 1,
"meter_id": null
},
"lookup_key": "pro_monthly_usd",
"metadata": {},
"product": {
"id": "prod_xxxxxxxxxxxxxx",
"name": "Pro Plan"
},
"currency": {
"id": "usd_xxxxxxxxxxxxxx",
"name": "United States Dollar"
}
}Retrieve a Price#
Retrieves the details of an existing price.
Retrieve a Price
async function retrievePrice(priceId) {
try {
const price = await payment.prices.retrieve(priceId);
console.log('Price retrieved:', price);
} catch (error) {
console.error('Error retrieving price:', error.message);
}
}
retrievePrice('price_xxxxxxxxxxxxxx');Parameters#
Name | Type | Description |
|---|---|---|
| string | Required. The unique identifier of the price to retrieve. Can also be a |
Returns#
Returns the requested Price object.
Update a Price#
Updates an existing price by setting the values of the parameters passed.
Update a Price
async function updatePrice(priceId) {
try {
const price = await payment.prices.update(priceId, {
nickname: 'Updated Pro Plan Nickname',
metadata: { order_id: '6735' },
});
console.log('Price updated:', price);
} catch (error) {
console.error('Error updating price:', error.message);
}
}
updatePrice('price_xxxxxxxxxxxxxx');Parameters#
Name | Type | Description |
|---|---|---|
| string | Required. The ID of the price to update. Can also be a |
| object | An object containing the fields to update. See the create method for a list of updatable fields. Note: Core attributes like |
Returns#
Returns the updated Price object.
List all Prices#
Returns a list of your prices. The prices are returned sorted by creation date, with the most recently created prices appearing first.
List Prices
async function listPrices() {
try {
const prices = await payment.prices.list({
product_id: 'prod_xxxxxxxxxxxxxx',
active: true,
limit: 5,
});
console.log('Retrieved prices:', prices.list);
} catch (error) {
console.error('Error listing prices:', error.message);
}
}
listPrices();Parameters#
Name | Type | Description |
|---|---|---|
| boolean | Only return prices with this active status. |
| string | Only return prices of this type, e.g., |
| string | Only return prices for this currency ID. |
| string | Only return prices for this product ID. |
| string | Only return the price with this lookup key. |
| number | The page number for pagination. Defaults to |
| number | The number of items per page. Defaults to |
Returns#
Returns a paginated object containing a list of Price objects, the total count, and paging information.
Search Prices#
Searches for prices matching a query string.
Search Prices
async function searchPrices() {
try {
const prices = await payment.prices.search({ query: 'Pro Plan' });
console.log('Search results:', prices.list);
} catch (error) {
console.error('Error searching prices:', error.message);
}
}
searchPrices();Parameters#
Name | Type | Description |
|---|---|---|
| string | The search query string. |
| number | The page number for pagination. Defaults to |
| number | The number of items per page. Defaults to |
Returns#
Returns a paginated object containing a list of matching Price objects.
Archive a Price#
Archives a price, preventing it from being used in new checkouts. If a price has been used, it's generally better to archive it than to delete it.
Archive a Price
async function archivePrice(priceId) {
try {
const price = await payment.prices.archive(priceId);
console.log('Price archived:', price.id, 'Active:', price.active);
} catch (error) {
console.error('Error archiving price:', error.message);
}
}
archivePrice('price_xxxxxxxxxxxxxx');Parameters#
Name | Type | Description |
|---|---|---|
| string | Required. The ID of the price to archive. Can also be a |
Returns#
Returns the archived Price object with active set to false.
Delete a Price#
Permanently deletes a price. This action cannot be undone. A price cannot be deleted if it has been used in a transaction or is otherwise locked.
Delete a Price
async function deletePrice(priceId) {
try {
const deletedPrice = await payment.prices.del(priceId);
console.log('Price deleted:', deletedPrice.id);
} catch (error) {
console.error('Error deleting price:', error.message);
}
}
deletePrice('price_xxxxxxxxxxxxxx');Parameters#
Name | Type | Description |
|---|---|---|
| string | Required. The ID of the price to delete. Can also be a |
Returns#
Returns the deleted Price object.
Update Inventory#
Manually adjusts the quantity_sold for a price. This is useful for tracking inventory outside of the standard checkout flow.
Update Inventory
async function updateInventory(priceId) {
try {
// Increment sold quantity by 2
const price = await payment.prices.inventory(priceId, {
quantity: 2,
action: 'increment',
});
console.log('Inventory updated. New quantity sold:', price.quantity_sold);
} catch (error) {
console.error('Error updating inventory:', error.message);
}
}
updateInventory('price_xxxxxxxxxxxxxx');Parameters#
Name | Type | Description |
|---|---|---|
| string | Required. The ID of the price. |
| object | An object containing inventory adjustment details. |
params Object Properties
Name | Type | Description |
|---|---|---|
| number | Required. The amount to adjust the sold quantity by. |
| string | Required. The adjustment action. Must be |
Returns#
Returns the updated Price object with the new quantity_sold value.