Skip to content

feat(appstore): add GetNotificationHistory and ExtendSubscriptionRenewalDate api for appstore api #173

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 23 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ go get github.com/awa/go-iap/hms

### In App Purchase (via App Store)

```
```go
import(
"github.com/awa/go-iap/appstore"
)
Expand All @@ -46,7 +46,7 @@ func main() {

### In App Billing (via GooglePlay)

```
```go
import(
"github.com/awa/go-iap/playstore"
)
Expand All @@ -67,7 +67,7 @@ func main() {

### In App Purchase (via Amazon App Store)

```
```go
import(
"github.com/awa/go-iap/amazon"
)
Expand All @@ -82,7 +82,7 @@ func main() {

### In App Purchase (via Huawei Mobile Services)

```
```go
import(
"github.com/awa/go-iap/hms"
)
Expand All @@ -101,7 +101,7 @@ func main() {

```go
import(
"github.com/awa/go-iap/appstore/api"
"github.com/awa/go-iap/appstore/api"
)

// For generate key file and download it, please refer to https://developer.apple.com/documentation/appstoreserverapi/creating_api_keys_to_use_with_the_app_store_server_api
Expand All @@ -111,23 +111,24 @@ const ACCOUNTPRIVATEKEY = `
-----END PRIVATE KEY-----
`
func main() {
c := &api.StoreConfig{
KeyContent: []byte(ACCOUNTPRIVATEKEY), // Loads a .p8 certificate
KeyID: "FAKEKEYID", // Your private key ID from App Store Connect (Ex: 2X9R4HXF34)
BundleID: "fake.bundle.id", // Your app’s bundle ID
Issuer: "xxxxx-xx-xx-xx-xxxxxxxxxx",// Your issuer ID from the Keys page in App Store Connect (Ex: "57246542-96fe-1a63-e053-0824d011072a")
Sandbox: false, // default is Production
}
originalTransactionId := "FAKETRANSACTIONID"
a := api.NewStoreClient(c)
query := &url.Values{}
query.Set("productType", "AUTO_RENEWABLE")
query.Set("productType", "NON_CONSUMABLE")
responses, err := a.GetTransactionHistory(originalTransactionId, query)

for _, response := range responses {
transantions, err := a.ParseSignedTransactions(response.SignedTransactions)
}
c := &api.StoreConfig{
KeyContent: []byte(ACCOUNTPRIVATEKEY), // Loads a .p8 certificate
KeyID: "FAKEKEYID", // Your private key ID from App Store Connect (Ex: 2X9R4HXF34)
BundleID: "fake.bundle.id", // Your app’s bundle ID
Issuer: "xxxxx-xx-xx-xx-xxxxxxxxxx",// Your issuer ID from the Keys page in App Store Connect (Ex: "57246542-96fe-1a63-e053-0824d011072a")
Sandbox: false, // default is Production
}
originalTransactionId := "FAKETRANSACTIONID"
a := api.NewStoreClient(c)
query := &url.Values{}
query.Set("productType", "AUTO_RENEWABLE")
query.Set("productType", "NON_CONSUMABLE")
ctx := context.Background()
responses, err := a.GetTransactionHistory(ctx, originalTransactionId, query)

for _, response := range responses {
transantions, err := a.ParseSignedTransactions(response.SignedTransactions)
}
}
```

Expand Down
62 changes: 62 additions & 0 deletions appstore/api/model.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package api

import "github.com/awa/go-iap/appstore"

// OrderLookupResponse https://developer.apple.com/documentation/appstoreserverapi/orderlookupresponse
type OrderLookupResponse struct {
Status int `json:"status"`
Expand Down Expand Up @@ -94,3 +96,63 @@ type JWSTransaction struct {
func (J JWSTransaction) Valid() error {
return nil
}

// https://developer.apple.com/documentation/appstoreserverapi/extendreasoncode
type ExtendReasonCode int

const (
UndeclaredExtendReasonCode = iota
CustomerSatisfaction
OtherReasons
ServiceIssueOrOutage
)

// ExtendRenewalDateRequest https://developer.apple.com/documentation/appstoreserverapi/extendrenewaldaterequest
type ExtendRenewalDateRequest struct {
ExtendByDays int `json:"extendByDays"`
ExtendReasonCode ExtendReasonCode `json:"extendReasonCode"`
RequestIdentifier string `json:"requestIdentifier"`
}

// NotificationHistoryRequest https://developer.apple.com/documentation/appstoreserverapi/notificationhistoryrequest
type NotificationHistoryRequest struct {
StartDate int64 `json:"startDate"`
EndDate int64 `json:"endDate"`
OriginalTransactionId string `json:"originalTransactionId,omitempty"`
NotificationType appstore.NotificationTypeV2 `json:"notificationType,omitempty"`
NotificationSubtype appstore.SubtypeV2 `json:"notificationSubtype,omitempty"`
}

// NotificationHistoryResponses https://developer.apple.com/documentation/appstoreserverapi/notificationhistoryresponse
type NotificationHistoryResponses struct {
HasMore bool `json:"hasMore"`
PaginationToken string `json:"paginationToken"`
NotificationHistory []NotificationHistoryResponseItem `json:"notificationHistory"`
}

// NotificationHistoryResponseItem https://developer.apple.com/documentation/appstoreserverapi/notificationhistoryresponseitem
type NotificationHistoryResponseItem struct {
SignedPayload string `json:"signedPayload"`
FirstSendAttemptResult FirstSendAttemptResult `json:"firstSendAttemptResult"`
}

// https://developer.apple.com/documentation/appstoreserverapi/firstsendattemptresult
type FirstSendAttemptResult string

const (
FirstSendAttemptResultSuccess FirstSendAttemptResult = "SUCCESS"
FirstSendAttemptResultCircularRedirect FirstSendAttemptResult = "CIRCULAR_REDIRECT"
FirstSendAttemptResultInvalidResponse FirstSendAttemptResult = "INVALID_RESPONSE"
FirstSendAttemptResultNoResponse FirstSendAttemptResult = "NO_RESPONSE"
FirstSendAttemptResultOther FirstSendAttemptResult = "OTHER"
FirstSendAttemptResultPrematureClose FirstSendAttemptResult = "PREMATURE_CLOSE"
FirstSendAttemptResultSocketIssue FirstSendAttemptResult = "SOCKET_ISSUE"
FirstSendAttemptResultTimedOut FirstSendAttemptResult = "TIMED_OUT"
FirstSendAttemptResultTlsIssue FirstSendAttemptResult = "TLS_ISSUE"
FirstSendAttemptResultUnsupportedCharset FirstSendAttemptResult = "UNSUPPORTED_CHARSET"
)

// SendTestNotificationResponse https://developer.apple.com/documentation/appstoreserverapi/sendtestnotificationresponse
type SendTestNotificationResponse struct {
TestNotificationToken string `json:"testNotificationToken"`
}
Loading