# @1amageek/firestore-commerce

> Commerce for Cloud Firestore

Latest version **0.6.1** (published 2020-02-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install @1amageek/firestore-commerce
pnpm add @1amageek/firestore-commerce
yarn add @1amageek/firestore-commerce
bun add @1amageek/firestore-commerce
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.6.1 |
| Published | 2020-02-15 |
| First published | 2019-11-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | 8 |
| Dependencies | 0 |
| Unpacked size | 199.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 16 |
| Author | 1amageek |
| Maintainers | 1amageek |
| Keywords | firestore, firebase, tradestore, model, typescript |

## Links

- npm: https://www.npmjs.com/package/@1amageek/firestore-commerce
- Repository: https://github.com/1amageek/firestore-commerce
- Homepage: https://github.com/1amageek/firestore-commerce#readme
- Issues: https://github.com/1amageek/firestore-commerce/issues
- npm.io page: https://npm.io/package/@1amageek/firestore-commerce

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 0.6.1 (latest) — 2020-02-15
- 0.6.0 — 2020-02-10
- 0.5.15 — 2020-02-05
- 0.5.14 — 2020-02-05
- 0.5.13 — 2020-02-04
- 0.5.12 — 2020-02-04
- 0.5.11 — 2020-02-03
- 0.5.10 — 2020-01-27
- 0.5.9 — 2020-01-27
- 0.5.8 — 2020-01-19
- 0.5.7 — 2020-01-17
- 0.5.6 — 2020-01-17
- 0.5.5 — 2020-01-17
- 0.5.4 — 2020-01-16
- 0.5.3 — 2020-01-13
- … 33 more at https://npm.io/package/@1amageek/firestore-commerce/versions

## 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
```

---
_Source: https://npm.io/package/@1amageek/firestore-commerce · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
