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
Podfile:
pod 'Orderable' 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.
Deploy orderable.ts to Cloud Functions.
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 functionsWhen 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. } }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.
MIT
