-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathorder.go
49 lines (40 loc) · 1.54 KB
/
order.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package huaweistore
import (
"context"
"encoding/json"
"fmt"
)
const (
// OrderSiteChina site Information for China
OrderSiteChina = "https://orders-drcn.iap.hicloud.com"
// OrderSiteGermany site Information for China
OrderSiteGermany = "https://orders-dre.iap.hicloud.com"
// OrderSiteSingapore site Information for China
OrderSiteSingapore = "https://orders-dra.iap.hicloud.com"
// OrderSiteRussia site Information for China
OrderSiteRussia = "https://orders-drru.iap.hicloud.com"
// OrderSiteAppTouch site Information for China
OrderSiteAppTouch = "https://orders-at-dre.iap.dbankcloud.com"
)
// VerifyToken purchase Token Verification for the Order Service
func (c *Client) VerifyToken(ctx context.Context, reqBody IAPRequest) (*InappPurchaseData, error) {
url := c.OrderSiteURL + "/applications/purchases/tokens/verify"
body, err := c.sendRequest(ctx, url, reqBody)
if err != nil {
return nil, err
}
var orderResponse IAPOrderResponse
if err := json.Unmarshal(body, &orderResponse); err != nil {
return nil, err
}
if orderResponse.ResponseCode != IAPResponseResultOK {
//TODO parse api result codes
// https://developer.huawei.com/consumer/en/doc/development/HMS-References/iap-api-specification-related-v4#API-ErrorCode
return nil, fmt.Errorf("response code: %s, response message: %s", orderResponse.ResponseCode, orderResponse.ResponseMessage)
}
var purchaseData InappPurchaseData
if err := json.Unmarshal([]byte(orderResponse.PurchaseTokenData), &purchaseData); err != nil {
return nil, err
}
return &purchaseData, nil
}