Set up usage-based billing with rate cardsPrivate preview
Charge customers based on usage of your products or services with rate cards.
You can subscribe customers to many different rates for usage-based services through one rate card. You can add new rates to the rate card and immediately apply those new rates to customers. Rate cards are versioned, so you can adjust rates for new customers while keeping existing customers at an older rate.
Private preview
Rate cards are currently in private preview and could change in functionality and integration path before they’re generally available to all Stripe users. Contact here to request access.
Before you begin
Rate cards /v2
API endpoints, such as Rate card subscriptions. Learn more about the /v2 and /v1 namespaces.
You can only use sandboxes with /v2
APIs.
Create a rate card
Use the Stripe Dashboard or API to create a rate card that can include multiple rates and pricing option.
For each rate card, you can configure:
- Service interval: Monthly, annual, weekly, or custom.
- Currency
- Include tax in prices
For each item in a rate card, you can configure:
- Meter: Which meter to use to record usage.
- Price type: Fixed rate, volume, or graduated.
- Sell as: Charge by individual units or by a packaged group of units. If you use packages, you specify the number of units per package and how to round (up or down) for partial packages.
- Advanced settings: You can optionally specify the product tax code. You can also add a unit label, a lookup key, metadata, and rate settings metadata.
You need to associate each rate in a rate card with a meter.
Subscribe your customer to a rate card
Before you create a subscription, you need to create a Customer object and provide billing information. You can do this in the Dashboard, with the API, or by using Stripe Checkout.
Record customer usage
After you subscribe a customer to a rate card, you can record their usage of your service, by sending meter events to a meter.
Create a preview invoice
Create a preview invoice to see a preview of a customer’s invoice that includes details such as the meter price and usage quantity.
Monitor servicing events
Rate card subscriptions emit event notifications whenever the state of servicing changes. Learn more about how the service interval works.
Listen for these events and use them to construct your business logic:
v2. | Sent when a customer activates a subscription for the first time. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
v2. | Sent when a customer pauses a subscription. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
v2. | Sent when a customer cancels a subscription. |
To handle these v2 Events, configure an Event Destination and point it at your webhook endpoint. You can either:
- Create the Event Destination from Workbench.
- Create the Event Destination through the Stripe API.
After you’ve created a destination, you can set up your webhook endpoint to handle these events:
require 'stripe' post '/v2_webhook_endpoint' do payload = request.body.read sig_header = request.env['HTTP_STRIPE_SIGNATURE'] event = nil begin event = Stripe::Webhook.construct_event( payload, sig_header, endpoint_secret ) rescue JSON::ParserError => e status 400 return rescue Stripe::SignatureVerificationError => e status 400 return end client = Stripe::StripeClient(
) case event.type when 'v2.billing.rate_card_subscription.servicing_activated' # The customer clicked Pay on Stripe Checkout, which activates the service. subscription_id = event.related_object.id subscription = client.v2.billing.rate_card_subscriptions .retrieve(subscription_id) # Look up your user in the database using the metadata passed into # Checkout Session create user_id = subscription.metadata["my_user_id"] user = User.find_by_id(user_id) # Fill in your logic here: mark_subscription_active(user, subscription) when 'v2.billing.rate_card_subscription.servicing_paused' # The customer paused the subscription. subscription_id = event.related_object.id subscription = client.v2.billing.rate_card_subscriptions .retrieve(subscription_id) # Look up your user in the database using the metadata passed into # Checkout Session create user_id = subscription.metadata["my_user_id"] user = User.find_by_id(user_id) # Fill in your logic here: mark_subscription_paused(user, subscription) when 'v2.billing.rate_card_subscription.servicing_canceled' # The customer canceled the subscription. subscription_id = event.related_object.id subscription = client.v2.billing.rate_card_subscriptions .retrieve(subscription_id) # Look up your user in the database using the metadata passed into # Checkout Session create user_id = subscription.metadata["my_user_id"] user = User.find_by_id(user_id) # Fill in your logic here: mark_subscription_canceled(user, subscription) end status 200 end"sk_test_BQokikJOvBiI2HlWgH4olfQ2"