@1amageek/firestore-commerce 中文文档教程

发布于 5年前 浏览 32 项目主页 更新于 3年前

firestore-commerce

firestore-commerce 是一个连接 Firestore 和 Stripe 的框架。 通过操纵 Ballcap 数据模型,您可以立即出售。

Usage

Set Stripe API Key

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

Quick start

setup

npm add @1amageek/firestore-commerce

将以下内容添加到 CloudFunctions index.ts:

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

要开始销售,首先创建一个 Product 并在其 SubCollection 中创建一个SKUPlanSKU是销售Good的对象,PlanSubscription的对象。

当您保存 ProductSKUPlan 时,会自动创建一个具有相同 ID 的对象。 如果 Stripe 中发生错误,Firestore 中的数据将更新为 isAvailable = false

Create Product

当您保存 Product 时,会自动创建一个具有通用 ID 的 Stripe 产品。

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

Test

创建 /test/config.tssecret.json

/test/config.ts

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

/secret.json

{
    "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": ""
}

运行测试

npm run test

firestore-commerce

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

Usage

Set Stripe API Key

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

Quick start

setup

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

Test

Create /test/config.ts and secret.json

/test/config.ts

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

/secret.json

{
    "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
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文