Documentation
¶
Overview ¶
Package storekit implements Apple's In-App Purchase and StoreKit server APIs: the App Store Server API and the Retention Messaging API.
StoreKit API credentials are intentionally separate from App Store Connect API credentials. The client signs a fresh JWT for every request.
Index ¶
- Constants
- Variables
- func AddDecodedJWSPayloads(raw json.RawMessage) (json.RawMessage, error)
- func CollectPages(first json.RawMessage, cursor PageCursor, ...) (json.RawMessage, error)
- func DecodeJWSPayloadUnverified(token string) (json.RawMessage, error)
- func RemoveAllCredentials() error
- func RemoveCredentials(name string) error
- func SetDefaultCredentials(name string) error
- func ShouldBypassKeychain() bool
- func StoreCredentials(name string, credentials Credentials) error
- func StoreCredentialsConfig(name string, credentials Credentials) error
- func StoreCredentialsConfigAt(name string, credentials Credentials, path string) error
- func ValidateMessage(message Message) error
- func ValidateRealtimeURL(value string) error
- type APIError
- type Client
- func (c *Client) DeleteDefault(ctx context.Context, productID, locale string) error
- func (c *Client) DeleteImage(ctx context.Context, identifier string) error
- func (c *Client) DeleteMessage(ctx context.Context, identifier string) error
- func (c *Client) DeleteRealtimeURL(ctx context.Context) error
- func (c *Client) GetAllSubscriptionStatuses(ctx context.Context, transactionID string, statuses []int) (json.RawMessage, error)
- func (c *Client) GetCustomerGroups(ctx context.Context, transactionID string) (json.RawMessage, error)
- func (c *Client) GetDefault(ctx context.Context, productID, locale string) (*DefaultMessageResponse, error)
- func (c *Client) GetGroupMembers(ctx context.Context, groupID string, limit int, paginationToken string) (json.RawMessage, error)
- func (c *Client) GetNotificationHistory(ctx context.Context, request NotificationHistoryRequest, ...) (json.RawMessage, error)
- func (c *Client) GetPerformanceTestResult(ctx context.Context, requestID string) (*PerformanceTestResult, error)
- func (c *Client) GetRealtimeURL(ctx context.Context) (*RealtimeURLResponse, error)
- func (c *Client) GetRefundHistory(ctx context.Context, transactionID, revision string) (json.RawMessage, error)
- func (c *Client) GetTestNotificationStatus(ctx context.Context, testNotificationToken string) (json.RawMessage, error)
- func (c *Client) GetTransactionHistory(ctx context.Context, transactionID string, query TransactionHistoryQuery, ...) (json.RawMessage, error)
- func (c *Client) GetTransactionInfo(ctx context.Context, transactionID string) (json.RawMessage, error)
- func (c *Client) ListImages(ctx context.Context) (*ImageListResponse, error)
- func (c *Client) ListMessages(ctx context.Context) (*MessageListResponse, error)
- func (c *Client) LookUpOrderID(ctx context.Context, orderID string) (json.RawMessage, error)
- func (c *Client) RequestTestNotification(ctx context.Context) (json.RawMessage, error)
- func (c *Client) SetDefault(ctx context.Context, productID, locale, messageIdentifier string) (*DefaultMessageResponse, error)
- func (c *Client) SetRealtimeURL(ctx context.Context, realtimeURL string) (*RealtimeURLResponse, error)
- func (c *Client) StartPerformanceTest(ctx context.Context, originalTransactionID string) (*PerformanceTestStartResponse, error)
- func (c *Client) UploadImage(ctx context.Context, identifier string, size ImageSize, data []byte) error
- func (c *Client) UploadMessage(ctx context.Context, identifier string, message Message) error
- func (c *Client) Validate() error
- type ClientOption
- type Credentials
- type DefaultMessageResponse
- type Environment
- type HeaderPosition
- type ImageIdentifier
- type ImageListResponse
- type ImageSize
- type ImageState
- type Message
- type MessageBulletPoint
- type MessageIdentifier
- type MessageImage
- type MessageListResponse
- type MutationResult
- type NotificationHistoryRequest
- type PageCursor
- type PerformanceResponseTimes
- type PerformanceTestConfig
- type PerformanceTestResult
- type PerformanceTestStartResponse
- type RealtimeURLResponse
- type StoredCredential
- type TransactionHistoryQuery
Constants ¶
const ( ProductionBaseURL = "https://api.storekit.apple.com" SandboxBaseURL = "https://api.storekit-sandbox.apple.com" )
const ( StatePending = "PENDING" StateApproved = "APPROVED" StateRejected = "REJECTED" )
Variables ¶
var ( // SignedTransactionPages covers Get Transaction History and Get Refund History. SignedTransactionPages = PageCursor{ItemsKey: "signedTransactions", TokenKey: "revision"} NotificationHistoryPages = PageCursor{ItemsKey: "notificationHistory", TokenKey: "paginationToken"} GroupMemberPages = PageCursor{ItemsKey: "members", TokenKey: "paginationToken"} )
Functions ¶
func AddDecodedJWSPayloads ¶
func AddDecodedJWSPayloads(raw json.RawMessage) (json.RawMessage, error)
AddDecodedJWSPayloads returns raw with a "<field>Decoded" sibling next to every signed* string or string-array field, holding the unverified payload. Signed fields inside decoded payloads are decoded too. Existing fields are never changed.
func CollectPages ¶
func CollectPages(first json.RawMessage, cursor PageCursor, next func(token string) (json.RawMessage, error)) (json.RawMessage, error)
CollectPages follows hasMore and the continuation token from first, and returns the final page's envelope with every page's items concatenated. The final page keeps Apple's last token, which callers can store to resume.
func DecodeJWSPayloadUnverified ¶
func DecodeJWSPayloadUnverified(token string) (json.RawMessage, error)
DecodeJWSPayloadUnverified returns the JSON payload of an Apple-signed compact JWS. It does NOT verify the signature or certificate chain, so the result must not be trusted as proof of a purchase.
func RemoveAllCredentials ¶
func RemoveAllCredentials() error
func RemoveCredentials ¶
func SetDefaultCredentials ¶
func ShouldBypassKeychain ¶
func ShouldBypassKeychain() bool
ShouldBypassKeychain reports whether StoreKit keychain access is disabled.
func StoreCredentials ¶
func StoreCredentials(name string, credentials Credentials) error
StoreCredentials stores a credential in the system keychain when available.
func StoreCredentialsConfig ¶
func StoreCredentialsConfig(name string, credentials Credentials) error
func StoreCredentialsConfigAt ¶
func StoreCredentialsConfigAt(name string, credentials Credentials, path string) error
func ValidateMessage ¶
ValidateMessage checks documented Retention Messaging limits before upload.
func ValidateRealtimeURL ¶
Types ¶
type APIError ¶
APIError describes an error returned by the Retention Messaging API.
func (*APIError) HTTPStatusCode ¶ added in v1.260713.0
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func NewClient ¶
func NewClient(credentials Credentials, environment Environment, opts ...ClientOption) (*Client, error)
func (*Client) DeleteDefault ¶
func (*Client) DeleteImage ¶
func (*Client) DeleteMessage ¶
func (*Client) GetAllSubscriptionStatuses ¶
func (c *Client) GetAllSubscriptionStatuses(ctx context.Context, transactionID string, statuses []int) (json.RawMessage, error)
GetAllSubscriptionStatuses calls Get All Subscription Statuses.
func (*Client) GetCustomerGroups ¶
func (c *Client) GetCustomerGroups(ctx context.Context, transactionID string) (json.RawMessage, error)
GetCustomerGroups calls Get Customer Groups.
func (*Client) GetDefault ¶
func (*Client) GetGroupMembers ¶
func (c *Client) GetGroupMembers(ctx context.Context, groupID string, limit int, paginationToken string) (json.RawMessage, error)
GetGroupMembers calls Get Group Members. A zero limit uses Apple's default.
func (*Client) GetNotificationHistory ¶
func (c *Client) GetNotificationHistory(ctx context.Context, request NotificationHistoryRequest, paginationToken string) (json.RawMessage, error)
GetNotificationHistory calls Get Notification History. Apple transports this read as a POST, so it is marked as a read for read-only mode.
func (*Client) GetPerformanceTestResult ¶
func (*Client) GetRealtimeURL ¶
func (c *Client) GetRealtimeURL(ctx context.Context) (*RealtimeURLResponse, error)
func (*Client) GetRefundHistory ¶
func (c *Client) GetRefundHistory(ctx context.Context, transactionID, revision string) (json.RawMessage, error)
GetRefundHistory calls Get Refund History (v2). revision is empty for the first page.
func (*Client) GetTestNotificationStatus ¶
func (c *Client) GetTestNotificationStatus(ctx context.Context, testNotificationToken string) (json.RawMessage, error)
GetTestNotificationStatus calls Get Test Notification Status.
func (*Client) GetTransactionHistory ¶
func (c *Client) GetTransactionHistory(ctx context.Context, transactionID string, query TransactionHistoryQuery, revision string) (json.RawMessage, error)
GetTransactionHistory calls Get Transaction History (v2). revision is empty for the first page.
func (*Client) GetTransactionInfo ¶
func (c *Client) GetTransactionInfo(ctx context.Context, transactionID string) (json.RawMessage, error)
GetTransactionInfo calls Get Transaction Info.
func (*Client) ListImages ¶
func (c *Client) ListImages(ctx context.Context) (*ImageListResponse, error)
func (*Client) ListMessages ¶
func (c *Client) ListMessages(ctx context.Context) (*MessageListResponse, error)
func (*Client) LookUpOrderID ¶
LookUpOrderID calls Look Up Order ID.
func (*Client) RequestTestNotification ¶
RequestTestNotification calls Request a Test Notification, which asks the App Store to send a TEST notification to the configured server URL.
func (*Client) SetDefault ¶
func (*Client) SetRealtimeURL ¶
func (*Client) StartPerformanceTest ¶
func (*Client) UploadImage ¶
func (*Client) UploadMessage ¶
type ClientOption ¶
type ClientOption func(*Client)
func WithBaseURL ¶
func WithBaseURL(baseURL string) ClientOption
WithBaseURL overrides the StoreKit server API host URL that request paths such as /inApps/v1/... are appended to. It exists for tests and Apple-compatible proxies.
func WithHTTPClient ¶
func WithHTTPClient(httpClient *http.Client) ClientOption
func WithNow ¶
func WithNow(now func() time.Time) ClientOption
type Credentials ¶
type Credentials struct {
KeyID string
IssuerID string
PrivateKeyPath string
PrivateKeyPEM string
BundleID string
Profile string
}
Credentials holds an In-App Purchase API key and its target app bundle ID.
func GetCredentialsWithSource ¶
func GetCredentialsWithSource(profile string) (Credentials, string, error)
type DefaultMessageResponse ¶
type DefaultMessageResponse struct {
MessageIdentifier string `json:"messageIdentifier"`
}
type Environment ¶
type Environment string
Environment selects the StoreKit server environment.
const ( Production Environment = "production" Sandbox Environment = "sandbox" )
func ParseEnvironment ¶
func ParseEnvironment(value string) (Environment, error)
ParseEnvironment validates a StoreKit environment.
type HeaderPosition ¶
type HeaderPosition string
HeaderPosition controls where the header appears in a retention message.
const ( HeaderAboveBody HeaderPosition = "ABOVE_BODY" HeaderAboveImage HeaderPosition = "ABOVE_IMAGE" )
type ImageIdentifier ¶
type ImageListResponse ¶
type ImageListResponse struct {
ImageIdentifiers []ImageIdentifier `json:"imageIdentifiers"`
}
type Message ¶
type Message struct {
Header string `json:"header"`
Body string `json:"body"`
Image *MessageImage `json:"image,omitempty"`
BulletPoints []MessageBulletPoint `json:"bulletPoints,omitempty"`
HeaderPosition HeaderPosition `json:"headerPosition,omitempty"`
}
type MessageBulletPoint ¶
type MessageIdentifier ¶
type MessageImage ¶
type MessageListResponse ¶
type MessageListResponse struct {
MessageIdentifiers []MessageIdentifier `json:"messageIdentifiers"`
}
type MutationResult ¶
type MutationResult struct {
Resource string `json:"resource"`
Identifier string `json:"identifier,omitempty"`
Action string `json:"action"`
Environment Environment `json:"environment"`
Success bool `json:"success"`
}
MutationResult is the stable CLI response for an empty successful mutation.
type NotificationHistoryRequest ¶
type NotificationHistoryRequest struct {
StartDate int64 `json:"startDate"`
EndDate int64 `json:"endDate"`
NotificationType string `json:"notificationType,omitempty"`
NotificationSubtype string `json:"notificationSubtype,omitempty"`
TransactionID string `json:"transactionId,omitempty"`
OnlyFailures bool `json:"onlyFailures,omitempty"`
}
NotificationHistoryRequest is Apple's NotificationHistoryRequest body. Dates are UNIX time in milliseconds.
type PageCursor ¶
PageCursor names the item array and continuation token of a paginated App Store Server API response that reports hasMore.
func (PageCursor) HasMore ¶
func (p PageCursor) HasMore(page json.RawMessage) (bool, string, error)
HasMore reports whether a page says more results exist, and its token.
type PerformanceTestConfig ¶
type PerformanceTestResult ¶
type PerformanceTestResult struct {
Config PerformanceTestConfig `json:"config"`
Failures map[string]int32 `json:"failures,omitempty"`
NumPending int `json:"numPending,omitempty"`
RequestID string `json:"requestId,omitempty"`
ResponseTimes PerformanceResponseTimes `json:"responseTimes,omitempty"`
Result string `json:"result"`
SuccessRate int32 `json:"successRate,omitempty"`
Target string `json:"target,omitempty"`
}
type PerformanceTestStartResponse ¶
type PerformanceTestStartResponse struct {
Config PerformanceTestConfig `json:"config"`
RequestID string `json:"requestId"`
}
type RealtimeURLResponse ¶
type RealtimeURLResponse struct {
RealtimeURL string `json:"realtimeURL"`
}
type StoredCredential ¶
type StoredCredential struct {
Credentials `json:"-"`
Name string `json:"name"`
IsDefault bool `json:"default"`
Source string `json:"source"`
SourcePath string `json:"source_path,omitempty"`
}
func ListCredentials ¶
func ListCredentials() ([]StoredCredential, error)