Giter Site home page Giter Site logo

1amageek / firestore-commerce Goto Github PK

View Code? Open in Web Editor NEW
16.0 1.0 1.0 1.37 MB

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

TypeScript 99.77% JavaScript 0.23%
stripe payment cloudfirestore firebase cloudfunctions

firestore-commerce's Introduction

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

firestore-commerce's People

Contributors

1amageek avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

danielfnz

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.