Skip to content

Commit 0f61393

Browse files
authored
Merge pull request #303 from richzw/master
feat(appstore): add verify function to appstore server api
2 parents 1c60340 + 186ba2b commit 0f61393

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

appstore/api/validator.go

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package api
2+
3+
import (
4+
"context"
5+
"errors"
6+
)
7+
8+
// IAPAPIClient is an interface to call validation API in App Store Server API
9+
type IAPAPIClient interface {
10+
Verify(ctx context.Context, transactionId string) (interface{}, error)
11+
}
12+
13+
type APIClient struct {
14+
productionCli *StoreClient
15+
sandboxCli *StoreClient
16+
}
17+
18+
func NewAPIClient(config StoreConfig) *APIClient {
19+
prodConf := config
20+
prodConf.Sandbox = false
21+
sandboxConf := config
22+
sandboxConf.Sandbox = true
23+
return &APIClient{productionCli: NewStoreClient(&prodConf), sandboxCli: NewStoreClient(&sandboxConf)}
24+
}
25+
26+
func (c *APIClient) Verify(ctx context.Context, transactionId string) (interface{}, error) {
27+
result, err := c.productionCli.GetTransactionInfo(ctx, transactionId)
28+
if err != nil && errors.Is(err, TransactionIdNotFoundError) {
29+
result, err = c.sandboxCli.GetTransactionInfo(ctx, transactionId)
30+
}
31+
return result, err
32+
}

appstore/validator.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ type Client struct {
3939
httpCli *http.Client
4040
}
4141

42-
// list of errore
42+
// list of errors
4343
var (
4444
ErrAppStoreServer = errors.New("AppStore server error")
4545

0 commit comments

Comments
 (0)