Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(appstore): add verify function to appstore server api #303

Merged
merged 2 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading