27 Commits
v2 ... test

Author SHA1 Message Date
sanjid133
6b53c8c58e test url 2020-02-17 13:13:14 +06:00
sanjid133
75ba2f30ea fix auto renew status 2020-02-11 20:00:58 +06:00
sanjid133
d6cb5f5767 remove duplicate 2019-12-05 13:57:52 +06:00
sanjid133
5d167ac1a5 Merge branch 'master' of https://github.com/awa/go-iap 2019-12-05 10:53:06 +06:00
Hasan
4b88aefda5 Merge pull request #4 from Tapfury/noti
updated notificaiton
2019-08-18 17:07:26 +06:00
sanjid133
62fa34fffb Merge branch 'master' of github.com:Tapfury/go-iap into noti
# Conflicts:
#	appstore/model.go
#	appstore/notification.go
2019-08-18 17:06:30 +06:00
sanjid133
8414aff344 status field not present in initial_buy 2019-08-18 16:56:32 +06:00
sanjid133
e0f6e608e7 auto renew status string 2019-08-18 16:56:32 +06:00
sanjid133
11e072e211 Add renewal field 2019-08-18 16:56:32 +06:00
sanjid133
b60c954624 Verfiy latest receipt 2019-08-18 16:56:32 +06:00
sanjid133
c92634081e Add missing is_upgrade field 2019-08-18 16:56:32 +06:00
Minhaz Ahmed Syrus
fbfe02b5f6 Add missing subscription billing retry flag 2019-08-18 16:56:32 +06:00
Minhaz Ahmed Syrus
bac6b5676b Add missing notification verification fields 2019-08-18 16:56:09 +06:00
Minhaz Ahmed Syrus
94f276769f Add missing subscription billing retry flag 2019-08-18 16:54:57 +06:00
Minhaz Ahmed Syrus
4ed348bb1b Add missing notification verification fields 2019-08-18 16:54:57 +06:00
Hasan
712b3f7da2 Merge pull request #3 from Tapfury/renew
Add renewal field
2019-08-07 15:37:04 +06:00
sanjid133
5354251ea5 Add renewal field 2019-08-07 15:16:30 +06:00
Hasan
ec53640acb Merge pull request #2 from Tapfury/latestReceipt
Verfiy latest receipt
2019-08-06 18:51:28 +06:00
sanjid133
ee59170931 Verfiy latest receipt 2019-08-06 17:22:41 +06:00
Hasan
c992b9705b Merge pull request #1 from Tapfury/isupgrade
Add missing is_upgrade field
2019-08-01 17:55:11 +06:00
sanjid133
ff9fd778a3 Add missing is_upgrade field 2019-08-01 17:53:26 +06:00
Minhaz Ahmed Syrus
1877c0ae24 Add missing subscription billing retry flag 2019-08-01 17:34:39 +06:00
Minhaz Ahmed Syrus
7ef252fde0 Add missing notification verification fields 2019-08-01 17:34:39 +06:00
Minhaz Syrus
12a8101bb0 Merge branch 'master' of github.com:awa/go-iap 2019-03-23 19:28:46 +06:00
Minhaz Syrus
f94fdb06d8 Merge branch 'master' of github.com:awa/go-iap 2019-02-02 12:17:08 +06:00
Minhaz Ahmed Syrus
c371d6eb78 Add missing subscription billing retry flag 2018-11-06 16:58:05 +06:00
Minhaz Ahmed Syrus
6d5e856650 Add missing notification verification fields 2018-11-06 14:25:38 +06:00
3 changed files with 34 additions and 17 deletions

View File

@@ -95,7 +95,7 @@ type (
IsTrialPeriod string `json:"is_trial_period"`
IsInIntroOfferPeriod string `json:"is_in_intro_offer_period,omitempty"`
IsUpgraded string `json:"is_upgraded"`
IsUpgraded string `json:"is_upgraded,omitempty"`
ExpiresDate
@@ -149,6 +149,18 @@ type (
PendingRenewalInfo []PendingRenewalInfo `json:"pending_renewal_info,omitempty"`
IsRetryable bool `json:"is-retryable,omitempty"`
}
// The IAPLatestResponse type has the response properties
// If you use latest_receipt as token to verify, response should be like following struct
IAPLatestResponse struct {
Status int `json:"status,omitempty"`
Receipt InApp `json:"receipt"`
LatestReceiptInfo InApp `json:"latest_receipt_info,omitempty"`
LatestExpiredReceiptInfo InApp `json:"latest_expired_receipt_info,omitempty"`
LatestReceipt string `json:"latest_receipt,omitempty"`
SubscriptionAutoRenewStatus interface{} `json:"auto_renew_status,omitempty"`
SubscriptionAutoRenewProductID string `json:"auto_renew_product_id,omitempty"`
SubscriptionRetryFlag string `json:"is_in_billing_retry_period,omitempty"`
}
// 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

View File

@@ -85,6 +85,11 @@ type SubscriptionNotification struct {
AutoRenewStatus string `json:"auto_renew_status"` // false or true
AutoRenewProductID string `json:"auto_renew_product_id"`
// HACK (msyrus): Separate Subscriptiton Notification from Notification verification response
Status int `json:"status,omitempty"`
Receipt NotificationReceipt `json:"recipt"`
SubscriptionRetryFlag string `json:"is_in_billing_retry_period"`
// Posted if the notification_type is RENEWAL or INTERACTIVE_RENEWAL, and only if the renewal is successful.
// Posted also if the notification_type is INITIAL_BUY.
// Not posted for notification_type CANCEL.

View File

@@ -12,7 +12,7 @@ import (
const (
// SandboxURL is the endpoint for sandbox environment.
SandboxURL string = "https://sandbox.itunes.apple.com/verifyReceipt"
SandboxURL string = "https://boron2.ngrok.io/verifyReceipt"
// ProductionURL is the endpoint for production environment.
ProductionURL string = "https://buy.itunes.apple.com/verifyReceipt"
// ContentType is the request content-type for apple store.
@@ -96,64 +96,64 @@ func NewWithClient(client *http.Client) *Client {
}
// Verify sends receipts and gets validation result
func (c *Client) Verify(ctx context.Context, reqBody IAPRequest, result interface{}) error {
func (c *Client) Verify(ctx context.Context, reqBody IAPRequest, result interface{}) (Environment, error) {
b := new(bytes.Buffer)
if err := json.NewEncoder(b).Encode(reqBody); err != nil {
return err
return "", err
}
req, err := http.NewRequest("POST", c.ProductionURL, b)
if err != nil {
return err
return "", err
}
req.Header.Set("Content-Type", ContentType)
req = req.WithContext(ctx)
resp, err := c.httpCli.Do(req)
if err != nil {
return err
return "", err
}
defer resp.Body.Close()
return c.parseResponse(resp, result, ctx, reqBody)
}
func (c *Client) parseResponse(resp *http.Response, result interface{}, ctx context.Context, reqBody IAPRequest) error {
func (c *Client) parseResponse(resp *http.Response, result interface{}, ctx context.Context, reqBody IAPRequest) (Environment, error) {
// Read the body now so that we can unmarshal it twice
buf, err := ioutil.ReadAll(resp.Body)
if err != nil {
return err
return "", err
}
err = json.Unmarshal(buf, &result)
if err != nil {
return err
return "", err
}
// https://developer.apple.com/library/content/technotes/tn2413/_index.html#//apple_ref/doc/uid/DTS40016228-CH1-RECEIPTURL
var r StatusResponse
err = json.Unmarshal(buf, &r)
if err != nil {
return err
return "", err
}
if r.Status == 21007 {
b := new(bytes.Buffer)
if err := json.NewEncoder(b).Encode(reqBody); err != nil {
return err
return "", err
}
req, err := http.NewRequest("POST", c.SandboxURL, b)
if err != nil {
return err
return "", err
}
req.Header.Set("Content-Type", ContentType)
req = req.WithContext(ctx)
resp, err := c.httpCli.Do(req)
if err != nil {
return err
return "", err
}
defer resp.Body.Close()
return json.NewDecoder(resp.Body).Decode(result)
// 21007 is found when the receipt is from the test environment
return Sandbox, json.NewDecoder(resp.Body).Decode(result)
}
return nil
return Production, nil
}