Have app store hit prod and then sandbox if 21007

According to https://developer.apple.com/library/content/technotes/tn2413/_index.html#//apple_ref/doc/uid/DTS40016228-CH1-RECEIPTURL

Always verify your receipt first with the production URL; proceed to verify with the sandbox URL if you receive a 21007 status code. Following this approach ensures that you do not have to switch between URLs while your application is being tested or reviewed in the sandbox or is live in the App Store.
This commit is contained in:
Timothy Lock
2017-12-11 17:05:53 -05:00
parent 8266e878ac
commit 60800c1f90
2 changed files with 194 additions and 9 deletions

View File

@@ -31,6 +31,7 @@ type IAPClient interface {
type Client struct {
URL string
TimeOut time.Duration
SandboxURL string
}
// HandleError returns error message by status code
@@ -81,6 +82,7 @@ func New() Client {
client := Client{
URL: SandboxURL,
TimeOut: time.Second * 5,
SandboxURL: SandboxURL,
}
if os.Getenv("IAP_ENVIRONMENT") == "production" {
client.URL = ProductionURL
@@ -121,6 +123,26 @@ func (c *Client) Verify(req IAPRequest, result interface{}) error {
defer resp.Body.Close()
err = json.NewDecoder(resp.Body).Decode(result)
if err != nil {
return err
}
return err
// Always verify your receipt first with the production URL; proceed to verify with the sandbox URL if you receive
// a 21007 status code
//
// https://developer.apple.com/library/content/technotes/tn2413/_index.html#//apple_ref/doc/uid/DTS40016228-CH1-RECEIPTURL
r, ok := result.(*IAPResponse)
if ok && r.Status == 21007 {
b = new(bytes.Buffer)
json.NewEncoder(b).Encode(req)
resp, err := client.Post(c.SandboxURL, "application/json; charset=utf-8", b)
if err != nil {
return err
}
defer resp.Body.Close()
return json.NewDecoder(resp.Body).Decode(result)
}
return nil
}