Skip to content

Commit f56d121

Browse files
authored
Merge pull request #206 from kaijietti/master
feat(appstore): add get transaction info
2 parents e983905 + 95c1299 commit f56d121

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

appstore/api/model.go

+5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ type HistoryResponse struct {
1818
SignedTransactions []string `json:"signedTransactions"`
1919
}
2020

21+
// TransactionInfoResponse https://developer.apple.com/documentation/appstoreserverapi/transactioninforesponse
22+
type TransactionInfoResponse struct {
23+
SignedTransactionInfo string `json:"signedTransactionInfo"`
24+
}
25+
2126
// RefundLookupResponse https://developer.apple.com/documentation/appstoreserverapi/refundlookupresponse
2227
type RefundLookupResponse struct {
2328
HasMore bool `json:"hasMore"`

appstore/api/store.go

+28-1
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@ import (
77
"crypto/x509"
88
"encoding/json"
99
"fmt"
10-
"github.com/golang-jwt/jwt/v4"
1110
"io"
1211
"net/http"
1312
"net/url"
1413
"strings"
1514
"time"
15+
16+
"github.com/golang-jwt/jwt/v4"
1617
)
1718

1819
const (
@@ -21,6 +22,7 @@ const (
2122

2223
PathLookUp = "/inApps/v1/lookup/{orderId}"
2324
PathTransactionHistory = "/inApps/v1/history/{originalTransactionId}"
25+
PathTransactionInfo = "/inApps/v1/transactions/{transactionId}"
2426
PathRefundHistory = "/inApps/v2/refund/lookup/{originalTransactionId}"
2527
PathGetALLSubscriptionStatus = "/inApps/v1/subscriptions/{originalTransactionId}"
2628
PathConsumptionInfo = "/inApps/v1/transactions/consumption/{originalTransactionId}"
@@ -164,6 +166,31 @@ func (a *StoreClient) GetTransactionHistory(ctx context.Context, originalTransac
164166
return
165167
}
166168

169+
// GetTransactionInfo https://developer.apple.com/documentation/appstoreserverapi/get_transaction_info
170+
func (a *StoreClient) GetTransactionInfo(ctx context.Context, transactionId string) (rsp *TransactionInfoResponse, err error) {
171+
URL := HostProduction + PathTransactionInfo
172+
if a.Token.Sandbox {
173+
URL = HostSandBox + PathTransactionInfo
174+
}
175+
URL = strings.Replace(URL, "{transactionId}", transactionId, -1)
176+
177+
statusCode, body, err := a.Do(ctx, http.MethodGet, URL, nil)
178+
if err != nil {
179+
return nil, err
180+
}
181+
182+
if statusCode != http.StatusOK {
183+
return nil, fmt.Errorf("appstore api: %v return status code %v", URL, statusCode)
184+
}
185+
186+
err = json.Unmarshal(body, &rsp)
187+
if err != nil {
188+
return nil, err
189+
}
190+
191+
return
192+
}
193+
167194
// GetRefundHistory https://developer.apple.com/documentation/appstoreserverapi/get_refund_history
168195
func (a *StoreClient) GetRefundHistory(ctx context.Context, originalTransactionId string) (responses []*RefundLookupResponse, err error) {
169196
baseURL := HostProduction + PathRefundHistory

0 commit comments

Comments
 (0)