DEV Community

mattling_dev for Stripe

Posted on • Updated on

Building an eCommerce Store 1/3: Managing Products & Prices (with examples in Ruby)

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) and me (@mattling_dev) to learn how to manage a product catalog using 11ty, the Stripe dashboard, and the Stripe-node client library.

Products and Prices

Two of the core objects that underpin your business model on Stripe are Products and Prices. 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 or the API. 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.

product = Stripe::Product.create({name: 'Coffee'})
# product.id -> prod_123
Enter fullscreen mode Exit fullscreen mode
# Create a one time price for 20 dollars
Stripe::Price.create({
  unit_amount: 2000,
  currency: 'usd',
  product: 'prod_123',
})
Enter fullscreen mode Exit fullscreen mode
# Create a recurring price for 20 dollars per month
Stripe::Price.create({
  unit_amount: 2000,
  currency: 'usd',
  recurring: {
    interval: 'month'
  },
  product: 'prod_123',
})
Enter fullscreen mode Exit fullscreen mode

Pricing models

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

Standard pricing

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

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

Package 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

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.

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',
    },
  ],
})
Enter fullscreen mode Exit fullscreen mode

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

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',
    },
  ],
})
Enter fullscreen mode Exit fullscreen mode

Metering

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.

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',
    },
  ],
})
Enter fullscreen mode Exit fullscreen mode

Using Products and Prices

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

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 on twitter or join in the conversion on our Discord server.

Stay connected

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

📣 Follow us on Twitter
💬 Join the official Discord server
📺 Subscribe to our Youtube channel
📧 Sign up for the Dev Digest

Discussion (0)