Commerce for Cloud Firestore

Usage no npm install needed!

<script type="module">
  import 1amageekFirestoreCommerce from 'https://cdn.skypack.dev/@1amageek/firestore-commerce';



firestore-commerce is a framework that links Firestore and Stripe. By manipulating the Ballcap data model, you can sell immediately.


Set Stripe API Key

firebase functions:config:set stripe.api_key="YOUR_STRIPE_API_KEY"

Quick start


npm add @1amageek/firestore-commerce

Add the following to CloudFunctions index.ts:

import * as Commerce from '@1amageek/firestore-commerce'
export const commerce = { ...Commerce }

To start selling, first create a Product and create aSKU or Plan in its SubCollection. SKU is an object for selling Good, and Plan is an object for Subscription.

When you save Product, SKU, Plan, an object with the same ID is automatically created. If an error occurs in Stripe, the data in Firestore is updated with isAvailable = false.

Create Product

When you save Product, a Stripe Product with a common ID is automatically created.

const user: User = new User("USER_ID")
const product: Product = new Product(user.products.collectionReference.doc())
product.type = "service"
product.name = "test-product"

Create SKU

const sku: SKU = new SKU(product.SKUs.collectionReference.doc())
sku.inventory = { type: StockType.finite, quantity: 1 }
sku.currency = Currency.JPY
sku.amount = 1000

Create Plan

const plan: Plan = new Plan(product.plans.collectionReference.doc())
plan.interval = Interval.month
plan.intervalCount = 1
plan.currency = Currency.JPY
plan.amount = 1000
plan.isAvailable = true

DB scheme

DB scheme


Create /test/config.ts and secret.json


export default {
    stripe: {
        api_key: "",
        customer_id: "",
        cord_id: ""


    "type": "service_account",
    "project_id": "",
    "private_key_id": "",
    "private_key": "",
    "client_email": "",
    "client_id": "",
    "auth_uri": "",
    "token_uri": "",
    "auth_provider_x509_cert_url": "",
    "client_x509_cert_url": ""

Run tests

npm run test