Ejemplo n.º 1
0
func makeJsonHandler(f func(token, tokenType string, json rj.RawJsonObject) s.Result) func(w http.ResponseWriter, req *http.Request) {
	return makeHandler(func(token, tokenType string, req *http.Request) s.Result {
		// to json
		json, _ := rj.ObjectFromString(readBody(req))
		return f(token, tokenType, json)
	})
}
Ejemplo n.º 2
0
func (o *Verifier) parse(src string) (Receipt, error) {
	json, err := rj.ObjectFromString(src)
	if err != nil {
		return Receipt{}, err
	}
	orderId, err := json.String("orderId")
	if err != nil {
		return Receipt{}, err
	}
	packageName, err := json.String("packageName")
	if err != nil {
		return Receipt{}, err
	}
	productId, err := json.String("productId")
	if err != nil {
		return Receipt{}, err
	}
	developerPayload := ""
	if _, ok := json["developerPayload"]; ok {
		developerPayload, err = json.String("developerPayload")
		if err != nil {
			return Receipt{}, err
		}
	}
	purchaseState, err := json.Int("purchaseState")
	if err != nil {
		return Receipt{}, err
	}
	purchaseTime, err := json.Long("purchaseTime")
	if err != nil {
		return Receipt{}, err
	}
	purchaseToken, err := json.String("purchaseToken")
	if err != nil {
		return Receipt{}, err
	}
	return Receipt{
		OrderId:          orderId,
		PackageName:      packageName,
		ProductId:        productId,
		DeveloperPayload: developerPayload,
		PurchaseState:    purchaseState,
		PurchaseTime:     purchaseTime,
		PurchaseToken:    purchaseToken,
	}, nil
}