Skip to content

Commit 186ba2b

Browse files
committed
fix(appstore): fix import cycle
1 parent 5fa8b94 commit 186ba2b

File tree

2 files changed

+32
-27
lines changed

2 files changed

+32
-27
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

-27
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
"net/http"
1313
"time"
1414

15-
"github.com/awa/go-iap/appstore/api"
1615
"github.com/golang-jwt/jwt/v4"
1716
)
1817

@@ -215,29 +214,3 @@ func (c *Client) ParseNotificationV2WithClaim(tokenStr string, result jwt.Claims
215214
})
216215
return err
217216
}
218-
219-
// IAPAPIClient is an interface to call validation API in App Store Server API
220-
type IAPAPIClient interface {
221-
Verify(ctx context.Context, transactionId string) (interface{}, error)
222-
}
223-
224-
type APIClient struct {
225-
productionCli *api.StoreClient
226-
sandboxCli *api.StoreClient
227-
}
228-
229-
func NewAPIClient(config api.StoreConfig) *APIClient {
230-
prodConf := config
231-
prodConf.Sandbox = false
232-
sandboxConf := config
233-
sandboxConf.Sandbox = true
234-
return &APIClient{productionCli: api.NewStoreClient(&prodConf), sandboxCli: api.NewStoreClient(&sandboxConf)}
235-
}
236-
237-
func (c *APIClient) Verify(ctx context.Context, transactionId string) (interface{}, error) {
238-
result, err := c.productionCli.GetTransactionInfo(ctx, transactionId)
239-
if err != nil && errors.Is(err, api.TransactionIdNotFoundError) {
240-
result, err = c.sandboxCli.GetTransactionInfo(ctx, transactionId)
241-
}
242-
return result, err
243-
}

0 commit comments

Comments
 (0)