-
Notifications
You must be signed in to change notification settings - Fork 249
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #303 from richzw/master
feat(appstore): add verify function to appstore server api
- Loading branch information
Showing
2 changed files
with
33 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters