-
Notifications
You must be signed in to change notification settings - Fork 245
/
model.go
191 lines (166 loc) · 8.12 KB
/
model.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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
package appstore
import "encoding/json"
type numericString string
func (n *numericString) UnmarshalJSON(b []byte) error {
var number json.Number
if err := json.Unmarshal(b, &number); err != nil {
return err
}
*n = numericString(number.String())
return nil
}
type Environment string
const (
Sandbox Environment = "Sandbox"
Production Environment = "Production"
)
type (
// https://developer.apple.com/library/content/releasenotes/General/ValidateAppStoreReceipt/Chapters/ValidateRemotely.html
// The IAPRequest type has the request parameter
IAPRequest struct {
ReceiptData string `json:"receipt-data"`
// Only used for receipts that contain auto-renewable subscriptions.
Password string `json:"password,omitempty"`
// Only used for iOS7 style app receipts that contain auto-renewable or non-renewing subscriptions.
// If value is true, response includes only the latest renewal transaction for any subscriptions.
ExcludeOldTransactions bool `json:"exclude-old-transactions"`
}
// The ReceiptCreationDate type indicates the date when the app receipt was created.
ReceiptCreationDate struct {
CreationDate string `json:"receipt_creation_date"`
CreationDateMS string `json:"receipt_creation_date_ms"`
CreationDatePST string `json:"receipt_creation_date_pst"`
}
// The RequestDate type indicates the date and time that the request was sent
RequestDate struct {
RequestDate string `json:"request_date"`
RequestDateMS string `json:"request_date_ms"`
RequestDatePST string `json:"request_date_pst"`
}
// The PurchaseDate type indicates the date and time that the item was purchased
PurchaseDate struct {
PurchaseDate string `json:"purchase_date"`
PurchaseDateMS string `json:"purchase_date_ms"`
PurchaseDatePST string `json:"purchase_date_pst"`
}
// The OriginalPurchaseDate type indicates the beginning of the subscription period
OriginalPurchaseDate struct {
OriginalPurchaseDate string `json:"original_purchase_date"`
OriginalPurchaseDateMS string `json:"original_purchase_date_ms"`
OriginalPurchaseDatePST string `json:"original_purchase_date_pst"`
}
// The ExpiresDate type indicates the expiration date for the subscription
ExpiresDate struct {
ExpiresDate string `json:"expires_date,omitempty"`
ExpiresDateMS string `json:"expires_date_ms,omitempty"`
ExpiresDatePST string `json:"expires_date_pst,omitempty"`
ExpiresDateFormatted string `json:"expires_date_formatted,omitempty"`
ExpiresDateFormattedPST string `json:"expires_date_formatted_pst,omitempty"`
}
// The CancellationDate type indicates the time and date of the cancellation by Apple customer support
CancellationDate struct {
CancellationDate string `json:"cancellation_date,omitempty"`
CancellationDateMS string `json:"cancellation_date_ms,omitempty"`
CancellationDatePST string `json:"cancellation_date_pst,omitempty"`
}
// The GracePeriodDate type indicates the grace period date for the subscription
GracePeriodDate struct {
GracePeriodDate string `json:"grace_period_expires_date,omitempty"`
GracePeriodDateMS string `json:"grace_period_expires_date_ms,omitempty"`
GracePeriodDatePST string `json:"grace_period_expires_date_pst,omitempty"`
}
// The InApp type has the receipt attributes
InApp struct {
Quantity string `json:"quantity"`
ProductID string `json:"product_id"`
TransactionID string `json:"transaction_id"`
OriginalTransactionID string `json:"original_transaction_id"`
WebOrderLineItemID string `json:"web_order_line_item_id,omitempty"`
PromotionalOfferID string `json:"promotional_offer_id"`
SubscriptionGroupIdentifier string `json:"subscription_group_identifier"`
IsTrialPeriod string `json:"is_trial_period"`
IsInIntroOfferPeriod string `json:"is_in_intro_offer_period,omitempty"`
IsUpgraded string `json:"is_upgraded,omitempty"`
ExpiresDate
PurchaseDate
OriginalPurchaseDate
CancellationDate
CancellationReason string `json:"cancellation_reason,omitempty"`
}
// The Receipt type has whole data of receipt
Receipt struct {
ReceiptType string `json:"receipt_type"`
AdamID int64 `json:"adam_id"`
AppItemID numericString `json:"app_item_id"`
BundleID string `json:"bundle_id"`
ApplicationVersion string `json:"application_version"`
DownloadID int64 `json:"download_id"`
VersionExternalIdentifier numericString `json:"version_external_identifier"`
OriginalApplicationVersion string `json:"original_application_version"`
InApp []InApp `json:"in_app"`
ReceiptCreationDate
RequestDate
OriginalPurchaseDate
}
// A pending renewal may refer to a renewal that is scheduled in the future or a renewal that failed in the past for some reason.
PendingRenewalInfo struct {
SubscriptionExpirationIntent string `json:"expiration_intent"`
SubscriptionAutoRenewProductID string `json:"auto_renew_product_id"`
SubscriptionRetryFlag string `json:"is_in_billing_retry_period"`
SubscriptionAutoRenewStatus string `json:"auto_renew_status"`
SubscriptionPriceConsentStatus string `json:"price_consent_status"`
ProductID string `json:"product_id"`
OriginalTransactionID string `json:"original_transaction_id"`
GracePeriodDate
}
// The IAPResponse type has the response properties
// We defined each field by the current IAP response, but some fields are not mentioned
// in the following Apple's document;
// https://developer.apple.com/library/ios/releasenotes/General/ValidateAppStoreReceipt/Chapters/ReceiptFields.html
// If you get other types or fields from the IAP response, you should use the struct you defined.
IAPResponse struct {
Status int `json:"status"`
Environment Environment `json:"environment"`
Receipt Receipt `json:"receipt"`
LatestReceiptInfo []InApp `json:"latest_receipt_info,omitempty"`
LatestReceipt string `json:"latest_receipt,omitempty"`
PendingRenewalInfo []PendingRenewalInfo `json:"pending_renewal_info,omitempty"`
IsRetryable bool `json:"is-retryable,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
StatusResponse struct {
Status int `json:"status"`
}
// IAPResponseForIOS6 is iOS 6 style receipt schema.
IAPResponseForIOS6 struct {
AutoRenewProductID string `json:"auto_renew_product_id"`
AutoRenewStatus int `json:"auto_renew_status"`
CancellationReason string `json:"cancellation_reason,omitempty"`
ExpirationIntent string `json:"expiration_intent,omitempty"`
IsInBillingRetryPeriod string `json:"is_in_billing_retry_period,omitempty"`
LatestReceiptInfo ReceiptForIOS6 `json:"latest_expired_receipt_info"`
Receipt ReceiptForIOS6 `json:"receipt"`
Status int `json:"status"`
}
ReceiptForIOS6 struct {
AppItemID numericString `json:"app_item_id"`
BID string `json:"bid"`
BVRS string `json:"bvrs"`
CancellationDate
ExpiresDate
IsTrialPeriod string `json:"is_trial_period"`
IsInIntroOfferPeriod string `json:"is_in_intro_offer_period"`
ItemID string `json:"item_id"`
ProductID string `json:"product_id"`
PurchaseDate
OriginalTransactionID string `json:"original_transaction_id"`
OriginalPurchaseDate
Quantity string `json:"quantity"`
TransactionID string `json:"transaction_id"`
UniqueIdentifier string `json:"unique_identifier"`
UniqueVendorIdentifier string `json:"unique_vendor_identifier"`
VersionExternalIdentifier numericString `json:"version_external_identifier,omitempty"`
WebOrderLineItemID string `json:"web_order_line_item_id"`
}
)