-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathreceipts.go
151 lines (143 loc) · 4.82 KB
/
receipts.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
// Code generated by gen.go. DO NOT EDIT.
package applereceipt
import (
"encoding/asn1"
"time"
)
var (
_ asn1.RawValue
_ time.Time
)
type InAppPurchaseReceipt struct {
// The number of items purchased.
Quantity int
// The product identifier of the item that was purchased.
ProductIdentifier string
// The transaction identifier of the item that was purchased.
TransactionIdentifier string
// For a transaction that restores a previous transaction, the transaction identifier of the original transaction. Otherwise, identical to the transaction identifier.
OriginalTransactionIdentifier string
// The date and time that the item was purchased.
PurchaseDate time.Time
// For a transaction that restores a previous transaction, the date of the original transaction.
OriginalPurchaseDate time.Time
// The expiration date for the subscription, expressed as the number of milliseconds since January 1, 1970, 00:00:00 GMT.
SubscriptionExpirationDate time.Time
// For an auto-renewable subscription, whether or not it is in the introductory price period.
SubscriptionIntroductoryPricePeriod int
// For a transaction that was canceled by Apple customer support, the time and date of the cancellation. For an auto-renewable subscription plan that was upgraded, the time and date of the upgrade transaction.
CancellationDate time.Time
// The primary key for identifying subscription purchases.
WebOrderLineItemID int
// Undocumented attributes
Remaining []ReceiptAttribute
}
func newInAppPurchaseReceipt(attrs []ReceiptAttribute) (InAppPurchaseReceipt, error) {
var r InAppPurchaseReceipt
for _, attr := range attrs {
var err error
switch attr.Type {
case 1701:
_, err = asn1.Unmarshal(attr.Value, &r.Quantity)
case 1702:
_, err = asn1.UnmarshalWithParams(attr.Value, &r.ProductIdentifier, "utf8")
case 1703:
_, err = asn1.UnmarshalWithParams(attr.Value, &r.TransactionIdentifier, "utf8")
case 1705:
_, err = asn1.UnmarshalWithParams(attr.Value, &r.OriginalTransactionIdentifier, "utf8")
case 1704:
var s string
if _, err = asn1.Unmarshal(attr.Value, &s); err == nil && s != "" {
r.PurchaseDate, err = time.Parse(time.RFC3339, s)
}
case 1706:
var s string
if _, err = asn1.Unmarshal(attr.Value, &s); err == nil && s != "" {
r.OriginalPurchaseDate, err = time.Parse(time.RFC3339, s)
}
case 1708:
var s string
if _, err = asn1.Unmarshal(attr.Value, &s); err == nil && s != "" {
r.SubscriptionExpirationDate, err = time.Parse(time.RFC3339, s)
}
case 1719:
_, err = asn1.Unmarshal(attr.Value, &r.SubscriptionIntroductoryPricePeriod)
case 1712:
var s string
if _, err = asn1.Unmarshal(attr.Value, &s); err == nil && s != "" {
r.CancellationDate, err = time.Parse(time.RFC3339, s)
}
case 1711:
_, err = asn1.Unmarshal(attr.Value, &r.WebOrderLineItemID)
default:
r.Remaining = append(r.Remaining, attr)
}
if err != nil {
return r, err
}
}
return r, nil
}
type AppReceipt struct {
// The app’s bundle identifier.
BundleIdentifier string
// The app’s version number.
AppVersion string
// An opaque value used, with other data, to compute the SHA-1 hash during validation.
OpaqueValue []byte
// A SHA-1 hash, used to validate the receipt.
SHA1Hash []byte
// The receipt for an in-app purchase.
InAppPurchaseReceipts []InAppPurchaseReceipt
// The version of the app that was originally purchased.
OriginalApplicationVersion string
// The date when the app receipt was created.
ReceiptCreationDate time.Time
// The date that the app receipt expires.
ReceiptExpirationDate time.Time
// Undocumented attributes
Remaining []ReceiptAttribute
}
func newAppReceipt(attrs []ReceiptAttribute) (AppReceipt, error) {
var r AppReceipt
for _, attr := range attrs {
var err error
switch attr.Type {
case 2:
_, err = asn1.UnmarshalWithParams(attr.Value, &r.BundleIdentifier, "utf8")
case 3:
_, err = asn1.UnmarshalWithParams(attr.Value, &r.AppVersion, "utf8")
case 4:
r.OpaqueValue = attr.Value
case 5:
r.SHA1Hash = attr.Value
case 17:
var attrs []ReceiptAttribute
if _, err = asn1.UnmarshalWithParams(attr.Value, &attrs, "set"); err == nil {
var iap InAppPurchaseReceipt
iap, err = newInAppPurchaseReceipt(attrs)
if err == nil {
r.InAppPurchaseReceipts = append(r.InAppPurchaseReceipts, iap)
}
}
case 19:
_, err = asn1.UnmarshalWithParams(attr.Value, &r.OriginalApplicationVersion, "utf8")
case 12:
var s string
if _, err = asn1.Unmarshal(attr.Value, &s); err == nil && s != "" {
r.ReceiptCreationDate, err = time.Parse(time.RFC3339, s)
}
case 21:
var s string
if _, err = asn1.Unmarshal(attr.Value, &s); err == nil && s != "" {
r.ReceiptExpirationDate, err = time.Parse(time.RFC3339, s)
}
default:
r.Remaining = append(r.Remaining, attr)
}
if err != nil {
return r, err
}
}
return r, nil
}