# Setting up your Database

You can see my full recommended database setup in the [demo app.](https://bubble.io/page?type=page\&name=checkout\&id=shopping-cart-demo-67649\&tab=tabs-3\&subtab=Data+Types\&type_id=cart_item)

{% hint style="info" %}
Please note that database set up I describe on this page is merely my own recommendation. It is absolutely possible to use the plugin with various different database configurations.
{% endhint %}

I recommend creating the below 3 data types in order to utilise the Stripe Checkout (Shopping Cart) plugin.

1. [Cart Item](#cart-item)
2. [Product](#product)
3. [Transaction](#transaction)

There are also some additional fields I recommend adding to the [User](#user) data type.

<div align="left"><figure><img src="https://2484116937-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5veFxRNePefac6Z9yAnL%2Fuploads%2FFVyN8OJOKHXnQhpgP5w5%2FScreenshot%202023-07-21%20at%2010.37.07.png?alt=media&#x26;token=ede87696-d960-43d8-819b-e1c0ed169ce4" alt="" width="375"><figcaption></figcaption></figure></div>

#### Cart Item

The Cart Item data type will be used to represent the items that are in a User's shopping cart. It will also be used with the plugin to send data to Stripe and ultimately create the Stripe Checkout Session where the products/services are purchased.

<figure><img src="https://2484116937-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5veFxRNePefac6Z9yAnL%2Fuploads%2Fd2YdcF9p7uIcJgo8nd7a%2FScreenshot%202023-07-21%20at%2010.39.31.png?alt=media&#x26;token=c3356ab4-824d-4760-a930-094bf19a1cb0" alt=""><figcaption></figcaption></figure>

The Cart Item data type has the following fields:

* **frequency:** Used for subscription products to determine how often a subscription is charged. Value should be "day", "week", "month" or "year" for subscription products. Can be left blank for one-time purchases.
* **product:** Linked to the "Product" data type (see below)
* **quantity:** The number of each product that is to be purchased
* **subscription:** A "Yes/No" field that indicates whether the product is a subscription product ("Yes") or a one-off purchase ("No")
* **total cost:** The total value (in cents) of each line item of product purchased (quantity \* price)

#### Product

The Product data type is used to represent the actual products/services that are for sale on the platform. These will typically be created by the platform who are selling the products/services.

<figure><img src="https://2484116937-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5veFxRNePefac6Z9yAnL%2Fuploads%2F1Ko1Vqc1lXZzIbESwYLc%2FScreenshot%202023-07-21%20at%2011.11.18.png?alt=media&#x26;token=f7858c1c-d6d8-4387-afd4-ed5683cb22ad" alt=""><figcaption></figcaption></figure>

The Product data yype has the following fields:

* **description (optional):** A text description of what the product is
* **frequency (necessary):** Used for subscription products to determine how often a subscription is charged. Value should be "day", "week", "month" or "year" for subscription products. Can be left blank for one-time purchases.
* **image (optional):** An image that represents the product/service. You'll see how this is used on [my demo app](https://shopping-cart-demo-67649.bubbleapps.io/version-test/product/1688737812511x697129325935356800?debug_mode=true).
* **name (necessary):** The name of the product/service.
* **price (cents) (necessary):** The price of the product/service in cents. If it's for a subcription product, it will be the price charged per day, week, month or year.
* **subscription? (necessary):** A "Yes/No" field that indicates whether the product is a subscription product ("Yes") or a one-off purchase ("No")

#### Transaction

The transaction data type is used to record details of transactions that occur on your platform.

<figure><img src="https://2484116937-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5veFxRNePefac6Z9yAnL%2Fuploads%2F8YjDhM8iOCjejRXNCyRI%2FScreenshot%202023-07-21%20at%2011.23.49.png?alt=media&#x26;token=4f778633-ce50-436a-9c01-d9fe1fbc6138" alt=""><figcaption></figcaption></figure>

The Transaction data type has the following fields:

* **checkout session id:** The ID of the Stripe Checkout Session that was used for the transaction
* **currency:** The currency that was used for the transaction
* **payment status:** Indicates whether the payment was successful or not
* **total amount:** The total value of the transaction (in cents)

#### User

<figure><img src="https://2484116937-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5veFxRNePefac6Z9yAnL%2Fuploads%2FzobHxOB7raaSKswQ1m1Y%2FScreenshot%202023-07-21%20at%2011.32.49.png?alt=media&#x26;token=3f9fb6ae-ea0d-47f9-ba56-bf49cbda4f08" alt=""><figcaption></figcaption></figure>

The User data type has the following custom fields:

* **customer id:** The Stripe Customer ID associated with the customer
* **shopping cart:** A list of Cart Items. This is used to indicate which items are currently in the User's shopping cart.
