Skip to content

Commit

Permalink
feat(appstore): add get transaction info
Browse files Browse the repository at this point in the history
  • Loading branch information
kaijietti committed Jun 6, 2023
1 parent e983905 commit 95c1299
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
5 changes: 5 additions & 0 deletions appstore/api/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ type HistoryResponse struct {
SignedTransactions []string `json:"signedTransactions"`
}

// TransactionInfoResponse https://developer.apple.com/documentation/appstoreserverapi/transactioninforesponse
type TransactionInfoResponse struct {
SignedTransactionInfo string `json:"signedTransactionInfo"`
}

// RefundLookupResponse https://developer.apple.com/documentation/appstoreserverapi/refundlookupresponse
type RefundLookupResponse struct {
HasMore bool `json:"hasMore"`
Expand Down
29 changes: 28 additions & 1 deletion appstore/api/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ import (
"crypto/x509"
"encoding/json"
"fmt"
"github.com/golang-jwt/jwt/v4"
"io"
"net/http"
"net/url"
"strings"
"time"

"github.com/golang-jwt/jwt/v4"
)

const (
Expand All @@ -21,6 +22,7 @@ const (

PathLookUp = "/inApps/v1/lookup/{orderId}"
PathTransactionHistory = "/inApps/v1/history/{originalTransactionId}"
PathTransactionInfo = "/inApps/v1/transactions/{transactionId}"
PathRefundHistory = "/inApps/v2/refund/lookup/{originalTransactionId}"
PathGetALLSubscriptionStatus = "/inApps/v1/subscriptions/{originalTransactionId}"
PathConsumptionInfo = "/inApps/v1/transactions/consumption/{originalTransactionId}"
Expand Down Expand Up @@ -164,6 +166,31 @@ func (a *StoreClient) GetTransactionHistory(ctx context.Context, originalTransac
return
}

// GetTransactionInfo https://developer.apple.com/documentation/appstoreserverapi/get_transaction_info
func (a *StoreClient) GetTransactionInfo(ctx context.Context, transactionId string) (rsp *TransactionInfoResponse, err error) {
URL := HostProduction + PathTransactionInfo
if a.Token.Sandbox {
URL = HostSandBox + PathTransactionInfo
}
URL = strings.Replace(URL, "{transactionId}", transactionId, -1)

statusCode, body, err := a.Do(ctx, http.MethodGet, URL, nil)
if err != nil {
return nil, err
}

if statusCode != http.StatusOK {
return nil, fmt.Errorf("appstore api: %v return status code %v", URL, statusCode)
}

err = json.Unmarshal(body, &rsp)
if err != nil {
return nil, err
}

return
}

// GetRefundHistory https://developer.apple.com/documentation/appstoreserverapi/get_refund_history
func (a *StoreClient) GetRefundHistory(ctx context.Context, originalTransactionId string) (responses []*RefundLookupResponse, err error) {
baseURL := HostProduction + PathRefundHistory
Expand Down

0 comments on commit 95c1299

Please sign in to comment.