Skip to content

Commit

Permalink
feat(api): add more fields per the latest document
Browse files Browse the repository at this point in the history
  • Loading branch information
richzw committed Jun 15, 2023
1 parent 5e35708 commit c1eb125
Showing 1 changed file with 118 additions and 43 deletions.
161 changes: 118 additions & 43 deletions model.go
Original file line number Diff line number Diff line change
@@ -1,29 +1,39 @@
package appstore

import "github.com/golang-jwt/jwt/v4"
import (
"github.com/golang-jwt/jwt/v4"
)

// OrderLookupResponse https://developer.apple.com/documentation/appstoreserverapi/orderlookupresponse
type OrderLookupResponse struct {
Status int `json:"status"`
SignedTransactions []string `json:"signedTransactions"`
}

// TransactionInfoResponse https://developer.apple.com/documentation/appstoreserverapi/transactioninforesponse
type TransactionInfoResponse struct {
SignedTransactionInfo string `json:"signedTransactionInfo"`
}
type Environment string

// Environment https://developer.apple.com/documentation/appstoreserverapi/environment
const (
Sandbox Environment = "Sandbox"
Production Environment = "Production"
)

// HistoryResponse https://developer.apple.com/documentation/appstoreserverapi/historyresponse
type HistoryResponse struct {
AppAppleId int `json:"appAppleId"`
BundleId string `json:"bundleId"`
Environment string `json:"environment"`
HasMore bool `json:"hasMore"`
Revision string `json:"revision"`
SignedTransactions []string `json:"signedTransactions"`
AppAppleId int64 `json:"appAppleId"`
BundleId string `json:"bundleId"`
Environment Environment `json:"environment"`
HasMore bool `json:"hasMore"`
Revision string `json:"revision"`
SignedTransactions []string `json:"signedTransactions"`
}

// TransactionInfoResponse https://developer.apple.com/documentation/appstoreserverapi/transactioninforesponse
type TransactionInfoResponse struct {
SignedTransactionInfo string `json:"signedTransactionInfo"`
}

// RefundLookupResponse https://developer.apple.com/documentation/appstoreserverapi/refundlookupresponse
// RefundLookupResponse same as the RefundHistoryResponse https://developer.apple.com/documentation/appstoreserverapi/refundhistoryresponse
type RefundLookupResponse struct {
HasMore bool `json:"hasMore"`
Revision string `json:"revision"`
Expand All @@ -32,8 +42,8 @@ type RefundLookupResponse struct {

// StatusResponse https://developer.apple.com/documentation/appstoreserverapi/get_all_subscription_statuses
type StatusResponse struct {
Environment string `json:"environment"`
AppAppleId int `json:"appAppleId"`
Environment Environment `json:"environment"`
AppAppleId int64 `json:"appAppleId"`
BundleId string `json:"bundleId"`
Data []SubscriptionGroupIdentifierItem `json:"data"`
}
Expand All @@ -45,27 +55,51 @@ type SubscriptionGroupIdentifierItem struct {

type LastTransactionsItem struct {
OriginalTransactionId string `json:"originalTransactionId"`
Status int `json:"status"`
Status int32 `json:"status"`
SignedRenewalInfo string `json:"signedRenewalInfo"`
SignedTransactionInfo string `json:"signedTransactionInfo"`
}

// MassExtendRenewalDateRequest https://developer.apple.com/documentation/appstoreserverapi/massextendrenewaldaterequest
type MassExtendRenewalDateRequest struct {
RequestIdentifier string `json:"requestIdentifier"`
ExtendByDays int32 `json:"extendByDays"`
ExtendReasonCode int32 `json:"extendReasonCode"`
ProductId string `json:"productId"`
StorefrontCountryCodes []string `json:"storefrontCountryCodes"`
}

// ConsumptionRequestBody https://developer.apple.com/documentation/appstoreserverapi/consumptionrequest
type ConsumptionRequestBody struct {
AccountTenure int `json:"accountTenure"`
AccountTenure int32 `json:"accountTenure"`
AppAccountToken string `json:"appAccountToken"`
ConsumptionStatus int `json:"consumptionStatus"`
ConsumptionStatus int32 `json:"consumptionStatus"`
CustomerConsented bool `json:"customerConsented"`
DeliveryStatus int `json:"deliveryStatus"`
LifetimeDollarsPurchased int `json:"lifetimeDollarsPurchased"`
LifetimeDollarsRefunded int `json:"lifetimeDollarsRefunded"`
Platform int `json:"platform"`
PlayTime int `json:"playTime"`
DeliveryStatus int32 `json:"deliveryStatus"`
LifetimeDollarsPurchased int32 `json:"lifetimeDollarsPurchased"`
LifetimeDollarsRefunded int32 `json:"lifetimeDollarsRefunded"`
Platform int32 `json:"platform"`
PlayTime int32 `json:"playTime"`
SampleContentProvided bool `json:"sampleContentProvided"`
UserStatus int `json:"userStatus"`
UserStatus int32 `json:"userStatus"`
}

// JWSRenewalInfoDecodedPayload https://developer.apple.com/documentation/appstoreserverapi/jwsrenewalinfodecodedpayload
type JWSRenewalInfoDecodedPayload struct {
AutoRenewProductId string `json:"autoRenewProductId"`
AutoRenewStatus int32 `json:"autoRenewStatus"`
Environment Environment `json:"environment"`
ExpirationIntent int32 `json:"expirationIntent"`
GracePeriodExpiresDate int64 `json:"gracePeriodExpiresDate"`
IsInBillingRetryPeriod bool `json:"isInBillingRetryPeriod"`
OfferIdentifier string `json:"offerIdentifier"`
OfferType string `json:"offerType"`
OriginalTransactionId string `json:"originalTransactionId"`
PriceIncreaseStatus int32 `json:"priceIncreaseStatus"`
ProductId string `json:"productId"`
RecentSubscriptionStartDate int64 `json:"recentSubscriptionStartDate"`
RenewalDate int64 `json:"renewalDate"`
SignedDate int64 `json:"signedDate"`
}

// JWSDecodedHeader https://developer.apple.com/documentation/appstoreserverapi/jwsdecodedheader
Expand All @@ -75,27 +109,50 @@ type JWSDecodedHeader struct {
X5C []string `json:"x5c,omitempty"`
}

// TransactionReason indicates the cause of a purchase transaction,
// https://developer.apple.com/documentation/appstoreservernotifications/transactionreason
type TransactionReason string

const (
TransactionReasonPurchase = "PURCHASE"
TransactionReasonRenewal = "RENEWAL"
)

// IAPType https://developer.apple.com/documentation/appstoreserverapi/type
type IAPType string

const (
AutoRenewable IAPType = "Auto-Renewable Subscription"
NonConsumable IAPType = "Non-Consumable"
Consumable IAPType = "Consumable"
NonRenewable IAPType = "Non-Renewing Subscription"
)

// JWSTransaction https://developer.apple.com/documentation/appstoreserverapi/jwstransaction
type JWSTransaction struct {
TransactionID string `json:"transactionId,omitempty"`
OriginalTransactionId string `json:"originalTransactionId,omitempty"`
WebOrderLineItemId string `json:"webOrderLineItemId,omitempty"`
BundleID string `json:"bundleId,omitempty"`
ProductID string `json:"productId,omitempty"`
SubscriptionGroupIdentifier string `json:"subscriptionGroupIdentifier,omitempty"`
PurchaseDate int64 `json:"purchaseDate,omitempty"`
OriginalPurchaseDate int64 `json:"originalPurchaseDate,omitempty"`
ExpiresDate int64 `json:"expiresDate,omitempty"`
Quantity int64 `json:"quantity,omitempty"`
Type string `json:"type,omitempty"`
AppAccountToken string `json:"appAccountToken,omitempty"`
InAppOwnershipType string `json:"inAppOwnershipType,omitempty"`
SignedDate int64 `json:"signedDate,omitempty"`
OfferType int64 `json:"offerType,omitempty"`
OfferIdentifier string `json:"offerIdentifier,omitempty"`
RevocationDate int64 `json:"revocationDate,omitempty"`
RevocationReason int `json:"revocationReason,omitempty"`
IsUpgraded bool `json:"isUpgraded,omitempty"`
TransactionID string `json:"transactionId,omitempty"`
OriginalTransactionId string `json:"originalTransactionId,omitempty"`
WebOrderLineItemId string `json:"webOrderLineItemId,omitempty"`
BundleID string `json:"bundleId,omitempty"`
ProductID string `json:"productId,omitempty"`
SubscriptionGroupIdentifier string `json:"subscriptionGroupIdentifier,omitempty"`
PurchaseDate int64 `json:"purchaseDate,omitempty"`
OriginalPurchaseDate int64 `json:"originalPurchaseDate,omitempty"`
ExpiresDate int64 `json:"expiresDate,omitempty"`
Quantity int32 `json:"quantity,omitempty"`
Type IAPType `json:"type,omitempty"`
AppAccountToken string `json:"appAccountToken,omitempty"`
InAppOwnershipType string `json:"inAppOwnershipType,omitempty"`
SignedDate int64 `json:"signedDate,omitempty"`
OfferType int32 `json:"offerType,omitempty"`
OfferIdentifier string `json:"offerIdentifier,omitempty"`
RevocationDate int64 `json:"revocationDate,omitempty"`
RevocationReason int32 `json:"revocationReason,omitempty"`
IsUpgraded bool `json:"isUpgraded,omitempty"`
Storefront string `json:"storefront,omitempty"`
StorefrontId string `json:"storefrontId,omitempty"`
TransactionReason TransactionReason `json:"transactionReason,omitempty"`
Environment Environment `json:"environment,omitempty"`
}

func (J JWSTransaction) Valid() error {
Expand All @@ -114,18 +171,29 @@ const (

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

// MassExtendRenewalDateStatusResponse https://developer.apple.com/documentation/appstoreserverapi/massextendrenewaldatestatusresponse
type MassExtendRenewalDateStatusResponse struct {
RequestIdentifier string `json:"requestIdentifier"`
Complete bool `json:"complete"`
CompleteDate int64 `json:"completeDate,omitempty"`
FailedCount int64 `json:"failedCount,omitempty"`
SucceededCount int64 `json:"succeededCount,omitempty"`
}

// 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 NotificationTypeV2 `json:"notificationType,omitempty"`
NotificationSubtype SubtypeV2 `json:"notificationSubtype,omitempty"`
OnlyFailures bool `json:"onlyFailures"`
TransactionId string `json:"transactionId"`
}

type NotificationTypeV2 string
Expand Down Expand Up @@ -181,6 +249,13 @@ type NotificationHistoryResponses struct {
type NotificationHistoryResponseItem struct {
SignedPayload string `json:"signedPayload"`
FirstSendAttemptResult FirstSendAttemptResult `json:"firstSendAttemptResult"`
SendAttempts []SendAttemptItem `json:"sendAttempts"`
}

// SendAttemptItem https://developer.apple.com/documentation/appstoreserverapi/sendattemptitem
type SendAttemptItem struct {
AttemptDate int64 `json:"attemptDate"`
SendAttemptResult FirstSendAttemptResult `json:"sendAttemptResult"`
}

// https://developer.apple.com/documentation/appstoreserverapi/firstsendattemptresult
Expand Down

0 comments on commit c1eb125

Please sign in to comment.