Stripe.Price (stripity_stripe v2.17.2) View Source

Work with Stripe price objects.

The Prices API adds more flexibility to how you charge customers.

It also replaces the Plans API, so Stripe recommends migrating your existing integration to work with prices.

To migrate, you need to identify how you use plans, products, and payment flows and then update these parts of your integration to use the Prices API.

Migrating to Prices guide: https://stripe.com/docs/billing/migration/migrating-prices

You can:

  • Create a price
  • Retrieve a price
  • Update a price
  • List all prices
  • Search prices

Stripe API reference: https://stripe.com/docs/api/prices

Example:

{
  "id": "plan_HJ8MK9HTYgniMM",
  "object": "price",
  "active": true,
  "billing_scheme": "per_unit",
  "created": 1589897226,
  "currency": "usd",
  "livemode": false,
  "lookup_key": null,
  "metadata": {},
  "nickname": null,
  "product": "prod_HJ8MOtuM1vD2jd",
  "recurring": {
    "aggregate_usage": null,
    "interval": "month",
    "interval_count": 1,
    "trial_period_days": null,
    "usage_type": "licensed"
  },
  "tax_behavior": "unspecified",
  "tiers": null,
  "tiers_mode": null,
  "transform_lookup_key": false,
  "transform_quantity": null,
  "type": "recurring",
  "unit_amount": 999,
  "unit_amount_decimal": "999"
}

Link to this section Summary

Link to this section Types

Specs

price_tier() :: %{
  flat_amount: integer(),
  flat_amount_decimal: String.t(),
  unit_amount: integer(),
  unit_amount_decimal: String.t(),
  up_to: integer()
}

Specs

product_data() :: %{
  :name => String.t(),
  optional(:active) => boolean(),
  optional(:metadata) => map(),
  optional(:statement_descriptor) => String.t(),
  optional(:tax_code) => String.t(),
  optional(:unit_label) => String.t()
}

Specs

recurring() :: %{
  optional(:aggregate_usage) => String.t(),
  optional(:interval) => String.t(),
  optional(:interval_count) => pos_integer(),
  optional(:trial_period_days) => pos_integer(),
  optional(:usage_type) => String.t()
}

Specs

t() :: %Stripe.Price{
  active: boolean(),
  billing_scheme: String.t(),
  created: Stripe.timestamp(),
  currency: String.t(),
  id: Stripe.id(),
  livemode: boolean(),
  lookup_key: String.t(),
  metadata: Stripe.Types.metadata(),
  nickname: String.t(),
  object: String.t(),
  product: Stripe.id() | Stripe.Product.t(),
  recurring: recurring(),
  tax_behavior: String.t(),
  tiers: [price_tier()],
  tiers_mode: String.t(),
  transform_lookup_key: boolean(),
  transform_quantity: transform_quantity(),
  type: String.t(),
  unit_amount: pos_integer(),
  unit_amount_decimal: String.t()
}

Specs

transform_quantity() :: %{divide_by: pos_integer(), round: String.t()}

Link to this section Functions

Link to this function

create(params, opts \\ [])

View Source

Specs

create(params, Stripe.options()) :: {:ok, t()} | {:error, Stripe.Error.t()}
when params:
       %{
         :currency => String.t(),
         optional(:unit_amount) => pos_integer(),
         optional(:active) => boolean(),
         optional(:metadata) => Stripe.Types.metadata(),
         optional(:nickname) => String.t(),
         optional(:product) => Stripe.id() | Stripe.Product.t(),
         optional(:product_data) => product_data(),
         optional(:recurring) => recurring(),
         optional(:tax_behavior) => String.t(),
         optional(:tiers) => [price_tier()],
         optional(:tiers_mode) => String.t(),
         optional(:billing_scheme) => String.t(),
         optional(:lookup_key) => String.t(),
         optional(:transfer_lookup_key) => boolean(),
         optional(:transform_quantity) => transform_quantity(),
         optional(:unit_amount_decimal) => String.t()
       }
       | %{}

Create a price.

Link to this function

list(params \\ %{}, opts \\ [])

View Source

Specs

list(params, Stripe.options()) ::
  {:ok, Stripe.List.t(t())} | {:error, Stripe.Error.t()}
when params:
       %{
         optional(:active) => boolean(),
         optional(:currency) => String.t(),
         optional(:product) => Stripe.Product.t() | Stripe.id(),
         optional(:type) => String.t(),
         optional(:created) => Stripe.timestamp(),
         optional(:ending_before) => t() | Stripe.id(),
         optional(:limit) => 1..100,
         optional(:lookup_keys) => [String.t()],
         optional(:recurring) => recurring() | nil,
         optional(:starting_after) => t() | Stripe.id()
       }
       | %{}

List all prices.

Link to this function

retrieve(id, opts \\ [])

View Source

Specs

retrieve(Stripe.id() | t(), Stripe.options()) ::
  {:ok, t()} | {:error, Stripe.Error.t()}

Retrieve a price.

Link to this function

search(params, opts \\ [])

View Source

Specs

search(params, Stripe.options()) ::
  {:ok, Stripe.SearchResult.t(t())} | {:error, Stripe.Error.t()}
when params: %{
       :query => Stripe.search_query(),
       optional(:limit) => 1..100,
       optional(:page) => String.t()
     }

Search prices

Link to this function

update(id, params, opts \\ [])

View Source

Specs

update(Stripe.id() | t(), params, Stripe.options()) ::
  {:ok, t()} | {:error, Stripe.Error.t()}
when params:
       %{
         optional(:active) => boolean(),
         optional(:metadata) => Stripe.Types.metadata(),
         optional(:nickname) => String.t(),
         optional(:recurring) => recurring(),
         optional(:lookup_key) => String.t(),
         optional(:transfer_lookup_key) => boolean()
       }
       | %{}

Update a price.

Takes the id and a map of changes.