forked from Mirrors/go-iap
Fix bug involving HttpStatusResponse
the `ok` in `r, ok := result.(*HttpStatusResponse)` would always fail unless the `result` being passed in was also of type `HttpStatusResponse`
This commit is contained in:
@@ -115,7 +115,7 @@ type (
|
||||
|
||||
// The HttpStatusResponse struct contains the status code returned by the store
|
||||
// Used as a workaround to detect when to hit the production appstore or sandbox appstore regardless of receipt type
|
||||
HttpStatusResponse struct {
|
||||
StatusResponse struct {
|
||||
Status int `json:"status"`
|
||||
}
|
||||
)
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
@@ -115,14 +116,24 @@ func (c *Client) Verify(req IAPRequest, result interface{}) error {
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
err = json.NewDecoder(resp.Body).Decode(result)
|
||||
// Read the body now so that we can unmarshal it twice
|
||||
buf, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = json.Unmarshal(buf, &result)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// https://developer.apple.com/library/content/technotes/tn2413/_index.html#//apple_ref/doc/uid/DTS40016228-CH1-RECEIPTURL
|
||||
r, ok := result.(*HttpStatusResponse)
|
||||
if ok && r.Status == 21007 {
|
||||
var r StatusResponse
|
||||
err = json.Unmarshal(buf, &r)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if r.Status == 21007 {
|
||||
b = new(bytes.Buffer)
|
||||
json.NewEncoder(b).Encode(req)
|
||||
resp, err := client.Post(c.SandboxURL, "application/json; charset=utf-8", b)
|
||||
|
||||
@@ -93,9 +93,9 @@ func TestHandleError(t *testing.T) {
|
||||
|
||||
func TestNew(t *testing.T) {
|
||||
expected := Client{
|
||||
ProductionURL: SandboxURL,
|
||||
TimeOut: time.Second * 5,
|
||||
ProductionURL: ProductionURL,
|
||||
SandboxURL: SandboxURL,
|
||||
TimeOut: time.Second * 5,
|
||||
}
|
||||
|
||||
actual := New()
|
||||
@@ -127,6 +127,7 @@ func TestNewWithConfig(t *testing.T) {
|
||||
|
||||
expected := Client{
|
||||
ProductionURL: ProductionURL,
|
||||
SandboxURL: SandboxURL,
|
||||
TimeOut: time.Second * 2,
|
||||
}
|
||||
|
||||
@@ -141,6 +142,7 @@ func TestNewWithConfigTimeout(t *testing.T) {
|
||||
|
||||
expected := Client{
|
||||
ProductionURL: ProductionURL,
|
||||
SandboxURL: SandboxURL,
|
||||
TimeOut: time.Second * 5,
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user