From 2ed2786f8e91ace8e366c1e14c6830fd5442c114 Mon Sep 17 00:00:00 2001 From: Bogdan Constantinescu Date: Fri, 20 Feb 2015 16:54:19 +0200 Subject: [PATCH 1/4] gorequest wasn't sending the request for validation In the gorequest Send method, there is a switch that checks the type of the parameter (https://github.com/parnurzeal/gorequest/blob/master/main.go#L341). In this particular case, the type of *IAPRequest is "ptr" which results in gorequest's switch to go the default case which is empty. The request was made with an empty body. --- appstore/validator.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/appstore/validator.go b/appstore/validator.go index dd1fb90..ca19d48 100644 --- a/appstore/validator.go +++ b/appstore/validator.go @@ -99,9 +99,15 @@ func NewWithConfig(config Config) Client { // Verify sends receipts and gets validation result func (c *Client) Verify(req *IAPRequest) (IAPResponse, error) { result := IAPResponse{} + obj, err_json := json.Marshal(req) + if err_json != nil { + return result, fmt.Errorf("%v", err_json) + } + res, body, errs := gorequest.New(). Post(c.URL). - Send(req). + Type("json"). + SendString(string(obj)). Timeout(c.TimeOut). End() From 9379daa02b7cf5ea5d32d94b9693ab9360a32551 Mon Sep 17 00:00:00 2001 From: Bogdan Constantinescu Date: Tue, 24 Feb 2015 21:52:20 +0200 Subject: [PATCH 2/4] Revert "gorequest wasn't sending the request for validation" This reverts commit 2ed2786f8e91ace8e366c1e14c6830fd5442c114. --- appstore/validator.go | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/appstore/validator.go b/appstore/validator.go index ca19d48..dd1fb90 100644 --- a/appstore/validator.go +++ b/appstore/validator.go @@ -99,15 +99,9 @@ func NewWithConfig(config Config) Client { // Verify sends receipts and gets validation result func (c *Client) Verify(req *IAPRequest) (IAPResponse, error) { result := IAPResponse{} - obj, err_json := json.Marshal(req) - if err_json != nil { - return result, fmt.Errorf("%v", err_json) - } - res, body, errs := gorequest.New(). Post(c.URL). - Type("json"). - SendString(string(obj)). + Send(req). Timeout(c.TimeOut). End() From e55df6a60c5946251c7b4cbc0bbb677d505dc68a Mon Sep 17 00:00:00 2001 From: Bogdan Constantinescu Date: Tue, 24 Feb 2015 21:53:29 +0200 Subject: [PATCH 3/4] Removed pointer to IAPRequest --- appstore/validator.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appstore/validator.go b/appstore/validator.go index dd1fb90..ba78002 100644 --- a/appstore/validator.go +++ b/appstore/validator.go @@ -97,7 +97,7 @@ func NewWithConfig(config Config) Client { } // Verify sends receipts and gets validation result -func (c *Client) Verify(req *IAPRequest) (IAPResponse, error) { +func (c *Client) Verify(req IAPRequest) (IAPResponse, error) { result := IAPResponse{} res, body, errs := gorequest.New(). Post(c.URL). From 128a24822942f903ac3aaf8782f82dac03f0bca9 Mon Sep 17 00:00:00 2001 From: Bogdan Constantinescu Date: Tue, 24 Feb 2015 22:00:47 +0200 Subject: [PATCH 4/4] Update validator test --- appstore/validator_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appstore/validator_test.go b/appstore/validator_test.go index 1af6d9a..a2e5fde 100644 --- a/appstore/validator_test.go +++ b/appstore/validator_test.go @@ -105,7 +105,7 @@ func TestVerify(t *testing.T) { req := IAPRequest{ ReceiptData: "dummy data", } - actual, _ := client.Verify(&req) + actual, _ := client.Verify(req) if !reflect.DeepEqual(actual, expected) { t.Errorf("got %v\nwant %v", actual, expected) }