Building an eCommerce Store 1/3: Managing Products & Prices (with examples in Ruby)
Tags: ruby, products, prices, stripe
Published: 2022-03-25 14:38:33

## Introduction

Creating an online store requires the management of a lot of moving parts such as product and price management, checkout flows for your customers, and order fulfillment to name a few. 

In this article you’ll learn about modeling your product catalog on Stripe and also about the many options that are available to you. You can also watch this video with Sia Karamalegos ([@TheGreenGreek](https://twitter.com/thegreengreek)) and me ([@mattling_dev]( https://twitter.com/mattling_dev)) to learn how to manage a product catalog using [11ty](https://www.11ty.dev/), the Stripe [dashboard](https://dashboard.stripe.com/dashboard), and the [Stripe-node](https://github.com/stripe/stripe-node) client library.

{% embed https://www.youtube.com/watch?v=N7qSVXyHlCA %}

## Products and Prices

Two of the core objects that underpin your business model on Stripe are [Products and Prices](https://stripe.com/docs/products-prices/how-products-and-prices-work). You can think of the Product as the “what” you’re selling. That might be a book, coffee cup, or access to a subscription service on a monthly cadence. The Price is the “how” you’re selling your product, meaning a Price describes the amount, the currency, its tax behavior, or whether it’s a one-time or recurring charge among other things. A Product can have many Prices to model that you can sell your Products in different ways. An example is that you may sell your T-Shirts in the US for a certain dollar amount, but decide to sell that same T-Shirt in the EU for another amount of euros.

Products and Prices are the core resources that are the foundation of several Stripe integrations such as Checkout, Payment Links, Subscriptions and Invoicing, and Orders. So it’s essential to understand how to create your pricing model as you start building.

You can manage your Products and Prices both through the Stripe [dashboard](https://dashboard.stripe.com/dashboard) or the [API](https://stripe.com/docs/api/products). In this article I’ll provide Ruby code snippets to illustrate how to create certain pricing models via the API but you can use one of our official client libraries in one of our seven supported programming languages.

## One-time Prices vs recurring Prices

One time Prices are for single sales of your Product. Recurring Prices are ones that reoccur at a predefined cadence. A monthly charge to access your video streaming platform would be a perfect example of a recurring Price.

```Ruby
product = Stripe::Product.create({name: 'Coffee'})
# product.id -> prod_123
```

```Ruby
# Create a one time price for 20 dollars
Stripe::Price.create({
  unit_amount: 2000,
  currency: 'usd',
  product: 'prod_123',
})
```

```Ruby
# Create a recurring price for 20 dollars per month
Stripe::Price.create({
  unit_amount: 2000,
  currency: 'usd',
  recurring: {
    interval: 'month'
  },
  product: 'prod_123',
})
```

## Pricing models

There are multiple pricing models that you can leverage to model your business on Stripe.

### [Standard pricing](https://stripe.com/docs/products-prices/pricing-models#package-standard-pricing)

This is a very common pricing model where a business sells one unit of a Product at a flat rate.

```Ruby
# Create a one time price for 20 dollars
Stripe::Price.create({
  unit_amount: 2000,
  currency: 'usd',
  product: 'prod_123',
})
```

### [Package pricing](https://stripe.com/docs/products-prices/pricing-models#package-standard-pricing)

This pricing model is for when you charge by the package or group of units. For example, say you charge 10 euros for every 5 units. Purchases are rounded up by default so a customer buying 8 units would pay 20 euros. The number of packages that are sold is determined by the quantity specified at the time of purchase.

### [Graduated pricing](https://stripe.com/docs/products-prices/pricing-models#graduated-pricing)

Graduated pricing can be used if you would like to have pricing tiers that may result in a different price for differing amounts of units in an order. For example, you might charge 10 euros per unit for the first 100 units and then 5 euros  per unit for the next 50.

```Ruby
Stripe::Price.create({
  nickname: 'Per-minute pricing',
  product: 'prod_123',
  currency: 'usd',
  recurring: {
    interval: 'month',
    usage_type: 'metered',
  },
  billing_scheme: 'tiered',
  tiers_mode: 'graduated',
  tiers: [
    {
      unit_amount: 1000,
      up_to: '100',
    },
    {
      unit_amount: 500,
      up_to: '150',
    },
    {
      unit_amount: 015,
      up_to: 'inf',
    },
  ],
})
```

### [Volume pricing](https://stripe.com/docs/products-prices/pricing-models#volume-based-pricing)

Volume pricing allows you to charge the same price for each unit based on the total number of units sold. For example, you might charge 10 euros per unit for 50 units, and 4 euros  per unit for 100 units.

```Ruby
Stripe::Price.create({
  nickname: 'Project Volume Pricing',
  product: 'prod_123',
  currency: 'usd',
  recurring: {
    interval: 'month',
    usage_type: 'metered',
  },
  billing_scheme: 'tiered',
  tiers_mode: 'volume',
  tiers: [
    {
      unit_amount: 1000,
      up_to: '50',
    },
    {
      unit_amount: 400,
      up_to: '100',
    },
    {
      unit_amount: 300,
      up_to: 'inf',
    },
  ],
})
```

### [Metering](https://stripe.com/docs/products-prices/pricing-models#metered)

If your pricing model is recurring and is based on the customer’s usage of your service it’s also possible to report usage of your service during the billing period and then bill the user at the end of the billing period. This is known as metered billing. A good example of a metered pricing model would be if you charge your customers on a per-megabyte usage for a digital service. So for every megabyte used of your service you would report that usage and it will be billed at the end of the period.

```Ruby
Stripe::Price.create({
  nickname: 'Per-megabyte pricing',
  product: 'prod_123',
  currency: 'usd',
  recurring: {
    interval: 'month',
    usage_type: 'metered',
  },
  billing_scheme: 'tiered',
  tiers_mode: 'graduated',
  tiers: [
    {
      unit_amount: 025,
      up_to: '1024',
    },
    {
      unit_amount: 020,
      up_to: '2048',
    },
    {
      unit_amount: 015,
      up_to: 'inf',
    },
  ],
})
```

## Using Products and Prices

When you have your pricing  model setup you can use Products and Prices with:

* [Checkout](https://stripe.com/docs/checkout/quickstart)
* [Payment Links](https://stripe.com/docs/payments/payment-links/overview)
* [Quotes](https://stripe.com/docs/quotes/create?testing-method=with-code)
* [Billing](https://stripe.com/docs/billing/quickstart)
* [Invoices](https://stripe.com/docs/invoicing/quickstart-guide)

Compatibility with these Stripe products depends on your business model.

In the next blog post on building an eCommerce store, you’ll learn how to use Checkout and Payment Links to use your product catalog to build a checkout flow for your customers.

## Summary

Stripe allows you to create sophisticated product and pricing models that accurately model your business. Designing and choosing that model is an important early step in building your integration with Stripe. If you’d like support, please don’t hesitate to reach out to our developers at [@StripeDev](https://twitter.com/StripeDev) on twitter or join in the conversion on our [Discord server](https://stripe.com/go/developer-chat).

### About the author

![Matthew Ling](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c8rpgkqr91ivs8sxr73g.png) 

Matthew Ling ([@mattling_dev](@mattling_dev)) is a Developer Advocate at Stripe. Matt loves to tinker with new technology, adores Ruby and coffee and also moonlighted as a pro music photographer. His photo site is at [matthewling.com](https://matthewling.com) and developer site is at [mattling.dev](https://mattling.dev).


### Stay connected

In addition, you can stay up to date with Stripe in a few ways:

📣 Follow us on [Twitter](https://twitter.com/StripeDev)
💬 Join the official [Discord server](https://stripe.com/go/developer-chat)
📺 Subscribe to our [Youtube channel](https://www.youtube.com/StripeDevelopers)
📧 Sign up for the [Dev Digest](https://go.stripe.global/dev-digest)