Skip to main content

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 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.

AttributeTypeDescription
idstringUnique identifier for the price object.
product_idstringThe ID of the product this price is associated with.
productobjectThe expanded Product object.
activebooleanWhether the price can be used for new purchases.
currency_idstringThe ID of the default currency for this price.
currencyobjectThe expanded PaymentCurrency object.
nicknamestringA brief description of the price, displayed to customers.
typestringOne of one_time or recurring.
unit_amountstringThe price in the smallest currency unit (e.g., cents for USD).
recurringobjectFor recurring prices, this hash contains billing interval information. See details below.
lookup_keystringA unique, user-defined key to retrieve the price.
metadataobjectA set of key-value pairs that you can attach to an object.
currency_optionsarraySpecifies different pricing for multiple currencies.
quantity_availablenumberThe total available quantity for this price. 0 means unlimited.
quantity_soldnumberThe number of units sold.
quantity_limit_per_checkoutnumberThe maximum quantity a customer can purchase in a single checkout. 0 means no limit.
upsellobjectConfiguration for upselling to another price.

The recurring Object Properties

AttributeTypeDescription
intervalstringThe frequency at which a subscription is billed. One of day, week, month, or year.
interval_countnumberThe number of intervals between subscription billings.
meter_idstringThe ID of the meter used for usage-based billing.

Create a Price

Creates a new price for an existing product.

Create a Price

javascript
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,
        usage_type: 'licensed'
      },
      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

NameTypeDescription
product_idstringRequired. The ID of the product this price belongs to.
unit_amountnumberRequired. The amount to be charged, in the smallest currency unit.
currency_idstringRequired. The ID of the currency for this price.
typestringThe type of pricing. Can be one_time or recurring. Defaults to one_time.
activebooleanWhether the price is active. Defaults to true.
nicknamestringAn internal name for the price.
lookup_keystringA unique string to reference the price.
recurringobjectAn object containing recurring billing information. Required if type is recurring.
currency_optionsarrayAn array of objects to specify prices in different currencies.
metadataobjectKey-value data to store with the price.
quantity_availablenumberThe total available quantity. Defaults to 0 (unlimited).
quantity_limit_per_checkoutnumberThe maximum quantity per checkout. Defaults to 0 (no limit).

Returns

Returns the newly created Price object.

Response

json
{
  "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

javascript
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

NameTypeDescription
idstringRequired. The unique identifier of the price to retrieve. Can also be a lookup_key.

Returns

Returns the requested Price object.

Update a Price

Updates an existing price by setting the values of the parameters passed.

Update a Price

javascript
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

NameTypeDescription
idstringRequired. The ID of the price to update. Can also be a lookup_key.
updatesobjectAn object containing the fields to update. See the create method for a list of updatable fields. Note: Core attributes like unit_amount and recurring cannot be changed if the price has been used (locked).

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

javascript
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

NameTypeDescription
activebooleanOnly return prices with this active status.
typestringOnly return prices of this type, e.g., recurring.
currency_idstringOnly return prices for this currency ID.
product_idstringOnly return prices for this product ID.
lookup_keystringOnly return the price with this lookup key.
pagenumberThe page number for pagination. Defaults to 1.
pageSizenumberThe number of items per page. Defaults to 20.

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

javascript
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

NameTypeDescription
querystringThe search query string.
pagenumberThe page number for pagination. Defaults to 1.
pageSizenumberThe number of items per page. Defaults to 20.

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

javascript
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

NameTypeDescription
idstringRequired. The ID of the price to archive. Can also be a lookup_key.

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

javascript
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

NameTypeDescription
idstringRequired. The ID of the price to delete. Can also be a lookup_key.

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

javascript
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

NameTypeDescription
idstringRequired. The ID of the price.
paramsobjectAn object containing inventory adjustment details.

params Object Properties

NameTypeDescription
quantitynumberRequired. The amount to adjust the sold quantity by.
actionstringRequired. The adjustment action. Must be increment or decrement.

Returns

Returns the updated Price object with the new quantity_sold value.