From 209eb6a98066518a54294b3ac2e91cc3ca1466e7 Mon Sep 17 00:00:00 2001 From: "suzuki.junsuke" Date: Fri, 16 Jan 2015 19:01:18 +0900 Subject: [PATCH] Add Validator for Purchase Product token (GooglePlay) --- README.md | 2 +- playstore/validator.go | 17 +++++++++++++++++ playstore/validator_test.go | 21 +++++++++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5c17407..e838807 100644 --- a/README.md +++ b/README.md @@ -62,7 +62,7 @@ func main() { # ToDo - [x] Validator for In App Purchase Receipt (AppStore) - [x] Validator for Subscription token (GooglePlay) -- [ ] Validator for Purchase Product token (GooglePlay) +- [x] Validator for Purchase Product token (GooglePlay) - [ ] More Tests diff --git a/playstore/validator.go b/playstore/validator.go index 97164ea..f90b64a 100644 --- a/playstore/validator.go +++ b/playstore/validator.go @@ -122,6 +122,23 @@ func (c *Client) VerifySubscription( return result, err } +// VerifyProduct Verifies product status +func (c *Client) VerifyProduct( + packageName string, + productID string, + token string, +) (*androidpublisher.ProductPurchase, error) { + service, err := androidpublisher.New(c.httpClient) + if err != nil { + return nil, err + } + + ps := androidpublisher.NewPurchasesProductsService(service) + result, err := ps.Get(packageName, productID, token).Do() + + return result, err +} + func dialTimeout(network, addr string) (net.Conn, error) { return net.DialTimeout(network, addr, defaultTimeout) } diff --git a/playstore/validator_test.go b/playstore/validator_test.go index 343d356..ce2525e 100644 --- a/playstore/validator_test.go +++ b/playstore/validator_test.go @@ -105,3 +105,24 @@ func TestVerifySubscription(t *testing.T) { // TODO Nomal scenario } + +func TestVerifyProduct(t *testing.T) { + Init() + + // Exception scenario + token := &oauth.Token{ + AccessToken: "accessToken", + RefreshToken: "refreshToken", + Expiry: time.Unix(1234567890, 0).UTC(), + } + + client := New(token) + expected := "Get https://www.googleapis.com/androidpublisher/v2/applications/package/purchases/products/productID/tokens/purchaseToken?alt=json: OAuthError: updateToken: Unexpected HTTP status 400 Bad Request" + _, err := client.VerifyProduct("package", "productID", "purchaseToken") + + if err.Error() != expected { + t.Errorf("got %v", err) + } + + // TODO Nomal scenario +}