# Stripe billing

## The Stripe schema

To help understand subscriptions, it's useful to know how Stripe structures its data.

<figure><img src="/files/4d8bGfEY0rI3ACmcyslh" alt=""><figcaption><p>The Stripe schema</p></figcaption></figure>

As we can see, a Subscription comprises several SubscriptionItems, which each match to a Price. This allows you a large amount of flexibility in constructing your subscription plans. Think of a plan in terms of a collection of Prices.

Thus, when you want to define plans for your users to buy, you:

* Create a Product in Stripe
* For that product, you create any number of prices - usually a monthly and yearly price
* You copy the Price IDs and add them to your Petal Pro config as `items`:

<figure><img src="/files/uDcX78ig380MVpAzeplL" alt=""><figcaption><p>In config.exs, you can add your plans</p></figcaption></figure>

Usually, you will only have one "item" in there. But sometimes you may want to add two - eg. you might have a once-off price as well as a monthly price.

Quantity will also mostly stay the same - 1. If your plans have a number of seats - then `quantitiy` would represent that variable.

The other info in the config is mainly for your front-end UI. The Stripe Prices are the main thing you want to copy across from Stripe.&#x20;

### How our config is used to create checkout sessions

* Explain what a checkout session is, how our items are passed in as line items and how it generates a hosted checkout page Stripe
* Explain how webhooks work and how we use Oban

These docs are a work in progress. Expect more soon! For now follow the ["Adding a subscription" guide](/petal-pro-documentation/v1.7.0/guides/adding-a-subscription.md).


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.petal.build/petal-pro-documentation/v1.7.0/fundamentals/stripe-billing.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
