-
Notifications
You must be signed in to change notification settings - Fork 703
/
transaction_model.go
80 lines (72 loc) · 3.05 KB
/
transaction_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
package apple
import (
"fmt"
"github.com/go-pay/gopay/pkg/jwt"
)
type SignedTransaction string
// Doc: HistoryResponse https://developer.apple.com/documentation/appstoreserverapi/historyresponse
type TransactionHistoryRsp struct {
StatusCodeErr
AppAppleId int `json:"appAppleId"`
BundleId string `json:"bundleId"`
Environment string `json:"environment"`
HasMore bool `json:"hasMore"`
Revision string `json:"revision"`
SignedTransactions []SignedTransaction `json:"signedTransactions"`
}
// TransactionsItem
// Doc: https://developer.apple.com/documentation/appstoreserverapi/jwstransactiondecodedpayload
type TransactionsItem struct {
jwt.StandardClaims
AppAccountToken string `json:"appAccountToken"`
BundleId string `json:"bundleId"`
Currency string `json:"currency"`
Environment string `json:"environment"`
ExpiresDate int64 `json:"expiresDate"`
InAppOwnershipType string `json:"inAppOwnershipType"`
IsUpgraded bool `json:"isUpgraded"`
OfferDiscountType string `json:"offerDiscountType"`
OfferIdentifier string `json:"offerIdentifier"`
OfferType int `json:"offerType"`
OriginalPurchaseDate int64 `json:"originalPurchaseDate"`
OriginalTransactionId string `json:"originalTransactionId"`
Price int64 `json:"price"`
ProductId string `json:"productId"`
PurchaseDate int64 `json:"purchaseDate"`
Quantity int `json:"quantity"`
RevocationDate int64 `json:"revocationDate"`
RevocationReason int `json:"revocationReason"`
SignedDate int64 `json:"signedDate"`
Storefront string `json:"storefront"`
StorefrontId string `json:"storefrontId"`
SubscriptionGroupIdentifier string `json:"subscriptionGroupIdentifier"`
TransactionId string `json:"transactionId"`
TransactionReason string `json:"transactionReason"`
Type string `json:"type"`
WebOrderLineItemId string `json:"webOrderLineItemId"`
}
func (s *SignedTransaction) DecodeSignedTransaction() (ti *TransactionsItem, err error) {
if *s == "" {
return nil, fmt.Errorf("signedTransactions is empty")
}
ti = &TransactionsItem{}
if err = ExtractClaims(string(*s), ti); err != nil {
return nil, err
}
return ti, nil
}
// Doc: https://developer.apple.com/documentation/appstoreserverapi/transactioninforesponse
type TransactionInfoRsp struct {
StatusCodeErr
SignedTransactionInfo string `json:"signedTransactionInfo"`
}
func (t *TransactionInfoRsp) DecodeSignedTransaction() (ti *TransactionsItem, err error) {
if t.SignedTransactionInfo == "" {
return nil, fmt.Errorf("signedTransactionInfo is empty")
}
ti = &TransactionsItem{}
if err = ExtractClaims(t.SignedTransactionInfo, ti); err != nil {
return nil, err
}
return ti, nil
}