Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/1amageek/firestore-commerce
firestore-commerce is a framework that links Firestore and Stripe. By manipulating the Ballcap data model, you can sell immediately.
https://github.com/1amageek/firestore-commerce
cloudfirestore cloudfunctions firebase payment stripe
Last synced: about 1 month ago
JSON representation
firestore-commerce is a framework that links Firestore and Stripe. By manipulating the Ballcap data model, you can sell immediately.
- Host: GitHub
- URL: https://github.com/1amageek/firestore-commerce
- Owner: 1amageek
- Created: 2019-11-12T08:04:20.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2020-02-15T04:34:58.000Z (almost 5 years ago)
- Last Synced: 2024-11-20T06:14:28.639Z (about 1 month ago)
- Topics: cloudfirestore, cloudfunctions, firebase, payment, stripe
- Language: TypeScript
- Homepage:
- Size: 1.33 MB
- Stars: 16
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# firestore-commerce
`firestore-commerce` is a framework that links Firestore and Stripe.
By manipulating the [Ballcap](https://github.com/1amageek/ballcap.ts) 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:
```typescript:index.ts
import * as Commerce from '@1amageek/firestore-commerce'
export const commerce = { ...Commerce }
```To start selling, first create a `Product` and create a`SKU` 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.
```typescript
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
```typescript
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
```typescript
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](https://github.com/1amageek/firestore-commerce/blob/master/DB-scheme.png)
## 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
```