@bates-solutions/stripe API Reference - v2.2.1
    Preparing search index...

    Class PricesService

    Prices service wrapping Stripe Prices.

    Prices are immutable once created: to change an amount, create a new price and deactivate the old one. PricesService.replace does both.

    // List active prices with their product expanded (read product metadata)
    const { data } = await stripe.prices.list({ active: true, expandProduct: true });
    for (const price of data) {
    const product = price.product as Stripe.Product;
    console.log(product.metadata.tier, price.unit_amount, price.recurring?.interval);
    }

    // Create a price, then change it later
    const price = await stripe.prices.create({ product: 'prod_123', unitAmount: 899, currency: 'usd' });
    const { price: newPrice } = await stripe.prices.replace(price.id, { unitAmount: 949 });
    Index
    • Deactivate a price (active: false) so it can't be used for new purchases. Existing subscriptions on it keep working.

      Parameters

      • priceId: string
      • Optionaloptions: { idempotencyKey?: string }

      Returns Promise<Price>

      When priceId is missing

    • Create a price for a product.

      Parameters

      Returns Promise<Price>

      When product or currency is missing, or unitAmount is not a non-negative integer

      // One-time price
      await stripe.prices.create({ product: 'prod_123', unitAmount: 899, currency: 'usd' });

      // Monthly price
      await stripe.prices.create({
      product: 'prod_123',
      unitAmount: 2900,
      currency: 'usd',
      recurring: { interval: 'month' },
      });
    • Retrieve a price by ID, optionally expanding its product.

      Parameters

      • priceId: string
      • Optionaloptions: { expandProduct?: boolean }

      Returns Promise<Price>

    • Change a price by replacing it: create a new price on the same product, then deactivate the old one.

      Exactly these are copied from the old price unless you override them: currency, recurring.interval and recurring.interval_count, nickname, metadata and tax_behavior. recurring.trial_period_days is always carried over. Its lookup_key is moved to the new price. The returned price is the new price's current state (lookup key included), also on a retry. If the old price was the product's default price, the new price becomes the default first, since Stripe won't deactivate a default price. Nothing else is copied.

      Only plain per-unit prices in one currency can be replaced. These are refused with StripeValidationError rather than silently simplified: tiered prices, metered prices (usage_type: 'metered' or a meter), customer-chooses-the-amount prices (custom_unit_amount), prices with transform_quantity, and prices with extra currency_options.

      Retry a failed call with the same idempotencyKey: each step uses a key derived from it and sends the same parameters on every attempt, so a retry finishes the remaining steps without creating a second price.

      Parameters

      Returns Promise<ReplacePriceResult>

      When priceId is missing, unitAmount is not a non-negative integer, or the old price is one of the kinds above

      const { price, previous } = await stripe.prices.replace('price_old', {
      unitAmount: 949,
      idempotencyKey: `reprice-${sku}-${version}`,
      });