Skip to content

Commit

Permalink
Merge pull request #303 from richzw/master
Browse files Browse the repository at this point in the history
feat(appstore): add verify function to appstore server api
  • Loading branch information
takecy authored Nov 14, 2024
2 parents 1c60340 + 186ba2b commit 0f61393
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
32 changes: 32 additions & 0 deletions appstore/api/validator.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package api

import (
"context"
"errors"
)

// IAPAPIClient is an interface to call validation API in App Store Server API
type IAPAPIClient interface {
Verify(ctx context.Context, transactionId string) (interface{}, error)
}

type APIClient struct {
productionCli *StoreClient
sandboxCli *StoreClient
}

func NewAPIClient(config StoreConfig) *APIClient {
prodConf := config
prodConf.Sandbox = false
sandboxConf := config
sandboxConf.Sandbox = true
return &APIClient{productionCli: NewStoreClient(&prodConf), sandboxCli: NewStoreClient(&sandboxConf)}
}

func (c *APIClient) Verify(ctx context.Context, transactionId string) (interface{}, error) {
result, err := c.productionCli.GetTransactionInfo(ctx, transactionId)
if err != nil && errors.Is(err, TransactionIdNotFoundError) {
result, err = c.sandboxCli.GetTransactionInfo(ctx, transactionId)
}
return result, err
}
2 changes: 1 addition & 1 deletion appstore/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type Client struct {
httpCli *http.Client
}

// list of errore
// list of errors
var (
ErrAppStoreServer = errors.New("AppStore server error")

Expand Down

0 comments on commit 0f61393

Please sign in to comment.