Coder Social home page Coder Social logo

starhoshi / orderable Goto Github PK

View Code? Open in Web Editor NEW
12.0 3.0 1.0 24.34 MB

An order processing framework works with Cloud Functions for Firebase

License: MIT License

Ruby 26.74% Objective-C 2.15% Swift 71.11%
firebase firestore cloud-function-for-firebase cloud-functions cocoapods ios swift

orderable's Introduction

Orderable

⚠️ Orderable is currently under development. ⚠️

for japanese: README.ja.md

Orderable is a CocoaPods library that works with Cloud Functions for Firebase and can easily execute payment.

EC requires a lot of processing. For example, check number of stocks, payment process, create history, and so on. Orderable exec these troublesome tasks.

For Server Side (Cloud Functions for Firebase): starhoshi/orderable.ts

Installation

Podfile:

pod 'Orderable'

Usage

1. Protocol

You need to define the necessary Model in your project.

Required protocol is here, sample model definition is here.

  • User
    • Buyer
  • Shop
    • Seller
  • Product
    • Product concept.
  • SKU
    • Entity of the product. Have inventory and price etc.
  • Order
    • Order have payment amount and payment method etc.
  • OrderShop
    • Order information for each shop.
  • OrderSKU
    • The item ordered. Have quantity etc.

2. Deploy

Deploy orderable.ts to Cloud Functions.

3. Pay an order

Sample code is here. orderable.ts starts when order.paymentStatus = OrderPaymentStatus.paymentRequested and update is done.

let order = Order()
order.amount = 1000
let stripe = Stripe()
stripe.customerID = "new_cus"
stripe.cardID = "new_card"
order.stripe = stripe
order.paymentStatus = OrderPaymentStatus.created
order.save()

...

// functions trigger
order.paymentStatus = OrderPaymentStatus.paymentRequested
order.update() // start cloud functions

4. Result

When purchase processing is completed, order.neoTask.status === 1 will be set. That is a sign of success. Observe the order and wait for the process to complete.

import Pring

var disposer: Disposer<Order>?
self?.disposer = Order.listen(order.id) { order, error in
  if order.neoTask.status === 1, order.stripeChargeID != nil {
    // stripe charge completed.
  }
}

Error

Detailed errors are listed here. You need to handle error by each error type.

On the client side, handle the following two errors.

  • invalid
    • Need to fix properties on the client side.
  • fatal
    • Have to check and correct the data directly.

LICENSE

MIT

orderable's People

Contributors

miup avatar starhoshi avatar

Stargazers

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

Watchers

 avatar  avatar  avatar

Forkers

miup

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.