-
Notifications
You must be signed in to change notification settings - Fork 6
/
apple_type.go
136 lines (116 loc) · 4.78 KB
/
apple_type.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package apple
import (
"fmt"
"github.com/golang-jwt/jwt/v5"
"github.com/smartwalle/apple/internal/storekit"
"net/url"
)
type Environment string
const (
EnvironmentSandbox Environment = "Sandbox"
EnvironmentProduction Environment = "Production"
)
type Param interface {
Values() url.Values
}
type Error struct {
Code int `json:"errorCode"`
Message string `json:"errorMessage"`
}
func (e Error) Error() string {
return fmt.Sprintf("%d - %s", e.Code, e.Message)
}
type SignedTransaction string
func (s SignedTransaction) Decode() (*Transaction, error) {
if s == "" {
return nil, nil
}
var item = &Transaction{}
if err := storekit.DecodeClaims(string(s), item); err != nil {
return nil, err
}
return item, nil
}
type InAppOwnershipType string
const (
InAppOwnershipTypeFamilyShared InAppOwnershipType = "FAMILY_SHARED"
InAppOwnershipTypePUrchased InAppOwnershipType = "PURCHASED"
)
type OfferType int
const (
OfferTypeIntroductory OfferType = 1
OfferTypePromotional OfferType = 2
OfferTypeSubscription OfferType = 3
)
type TransactionType string
const (
TransactionTypeAutoRenewable TransactionType = "Auto-Renewable Subscription"
TransactionTypeNonConsumable TransactionType = "Non-Consumable"
TransactionTypeConsumable TransactionType = "Consumable"
TransactionTypeNonRenewing TransactionType = "Non-Renewing Subscription"
)
// Transaction
// https://developer.apple.com/documentation/appstoreserverapi/jwstransactiondecodedpayload
// https://developer.apple.com/documentation/appstoreservernotifications/jwstransactiondecodedpayload
type Transaction struct {
jwt.RegisteredClaims
AppAccountToken string `json:"appAccountToken"`
TransactionId string `json:"transactionId"`
OriginalTransactionId string `json:"originalTransactionId"`
WebOrderLineItemId string `json:"webOrderLineItemId"`
BundleId string `json:"bundleId"`
ProductId string `json:"productId"`
SubscriptionGroupIdentifier string `json:"subscriptionGroupIdentifier"`
PurchaseDate int64 `json:"purchaseDate"`
OriginalPurchaseDate int64 `json:"originalPurchaseDate"`
ExpiresDate int64 `json:"expiresDate"`
Quantity int `json:"quantity"`
Type TransactionType `json:"type"`
InAppOwnershipType InAppOwnershipType `json:"inAppOwnershipType"`
SignedDate int64 `json:"signedDate"`
OfferIdentifier string `json:"offerIdentifier"`
OfferType OfferType `json:"offerType"`
Environment Environment `json:"environment"`
RevocationReason int `json:"revocationReason"`
RevocationDate int64 `json:"revocationDate"`
IsUpgraded bool `json:"isUpgraded"`
Storefront string `json:"storefront"`
StorefrontId string `json:"storefrontId"`
TransactionReason string `json:"transactionReason"`
}
type SignedRenewal string
func (s SignedRenewal) Decode() (*Renewal, error) {
if s == "" {
return nil, nil
}
var item = &Renewal{}
if err := storekit.DecodeClaims(string(s), item); err != nil {
return nil, err
}
return item, nil
}
type AutoRenewStatus int
const (
AutoRenewStatusOff AutoRenewStatus = 0
AutoRenewStatusOn AutoRenewStatus = 1
)
// Renewal
// https://developer.apple.com/documentation/appstoreserverapi/jwsrenewalinfodecodedpayload
// https://developer.apple.com/documentation/appstoreservernotifications/jwsrenewalinfodecodedpayload
type Renewal struct {
jwt.RegisteredClaims
AutoRenewProductId string `json:"autoRenewProductId"`
AutoRenewStatus AutoRenewStatus `json:"autoRenewStatus"`
Environment Environment `json:"environment"`
ExpirationIntent int `json:"expirationIntent"`
GracePeriodExpiresDate int64 `json:"gracePeriodExpiresDate"`
IsInBillingRetryPeriod bool `json:"isInBillingRetryPeriod"`
OfferIdentifier string `json:"offerIdentifier"`
OfferType OfferType `json:"offerType"`
OriginalTransactionId string `json:"originalTransactionId"`
PriceIncreaseStatus int `json:"priceIncreaseStatus"`
ProductId string `json:"productId"`
RecentSubscriptionStartDate int64 `json:"recentSubscriptionStartDate"`
RenewalDate int64 `json:"renewalDate"`
SignedDate int64 `json:"signedDate"`
}