Documentation ¶
Index ¶
- Constants
- Variables
- func ShouldRetryDefault(status int, err error) bool
- type Backoff
- type Cert
- type ConsumptionRequestBody
- type DoFunc
- func AddHeader(client HTTPClient, key string, value ...string) DoFunc
- func RateLimit(c HTTPClient, reqPerMin int) DoFunc
- func RequireResponseBody(c HTTPClient) DoFunc
- func RequireResponseStatus(c HTTPClient, status ...int) DoFunc
- func SetHeader(c HTTPClient, key string, value ...string) DoFunc
- func SetInitializer(c HTTPClient, init Initializer) DoFunc
- func SetRequest(ctx context.Context, c HTTPClient, method string, url string) DoFunc
- func SetRequestBody(c HTTPClient, m Marshaller, v any) DoFunc
- func SetRequestBodyJSON(c HTTPClient, v any) DoFunc
- func SetResponseBodyHandler(c HTTPClient, u Unmarshaller, ptr any) DoFunc
- func SetRetry(c HTTPClient, bo Backoff, shouldRetry func(int, error) bool) DoFunc
- type ExtendReasonCode
- type ExtendRenewalDateRequest
- type FirstSendAttemptResult
- type HTTPClient
- type HistoryResponse
- type Initializer
- type JWSDecodedHeader
- type JWSRenewalInfoDecodedPayload
- type JWSTransaction
- type JitterBackoff
- type LastTransactionsItem
- type Marshaller
- type NotificationData
- type NotificationHistoryRequest
- type NotificationHistoryResponseItem
- type NotificationHistoryResponses
- type NotificationPayload
- type NotificationTypeV2
- type OneSecondBackoff
- type OrderLookupResponse
- type RefundLookupResponse
- type RenewalInfo
- type SendTestNotificationResponse
- type StatusResponse
- type StoreClient
- func (c *StoreClient) Do(ctx context.Context, method string, url string, body io.Reader) (int, []byte, error)
- func (c *StoreClient) ExtendSubscriptionRenewalDate(ctx context.Context, originalTransactionId string, ...) (statusCode int, err error)
- func (c *StoreClient) GetALLSubscriptionStatuses(ctx context.Context, originalTransactionId string) (*StatusResponse, error)
- func (c *StoreClient) GetNotificationHistory(ctx context.Context, body NotificationHistoryRequest) (responses []NotificationHistoryResponseItem, err error)
- func (c *StoreClient) GetRefundHistory(ctx context.Context, originalTransactionId string) (responses []*RefundLookupResponse, err error)
- func (c *StoreClient) GetTestNotificationStatus(ctx context.Context, testNotificationToken string) (int, []byte, error)
- func (c *StoreClient) GetTransactionHistory(ctx context.Context, originalTransactionId string, query *url.Values) (responses []*HistoryResponse, err error)
- func (c *StoreClient) LookupOrderID(ctx context.Context, orderId string) (*OrderLookupResponse, error)
- func (c *StoreClient) ParseNotificationV2(tokenStr string) (*jwt.Token, error)
- func (c *StoreClient) ParseSignedTransactions(transactions []string) ([]*JWSTransaction, error)
- func (c *StoreClient) SendConsumptionInfo(ctx context.Context, originalTransactionId string, body ConsumptionRequestBody) (statusCode int, err error)
- func (c *StoreClient) SendRequestTestNotification(ctx context.Context) (int, []byte, error)
- type StoreConfig
- type SubscriptionGroupIdentifierItem
- type SubtypeV2
- type Token
- type TransactionInfo
- type Unmarshaller
Constants ¶
const ( UndeclaredExtendReasonCode = iota CustomerSatisfaction OtherReasons ServiceIssueOrOutage )
const ( HostSandBox = "https://api.storekit-sandbox.itunes.apple.com" HostProduction = "https://api.storekit.itunes.apple.com" PathLookUp = "/inApps/v1/lookup/{orderId}" PathTransactionHistory = "/inApps/v1/history/{originalTransactionId}" PathRefundHistory = "/inApps/v2/refund/lookup/{originalTransactionId}" PathGetALLSubscriptionStatus = "/inApps/v1/subscriptions/{originalTransactionId}" PathConsumptionInfo = "/inApps/v1/transactions/consumption/{originalTransactionId}" PathExtendSubscriptionRenewalDate = "/inApps/v1/subscriptions/extend/{originalTransactionId}" PathGetNotificationHistory = "/inApps/v1/notifications/history" PathRequestTestNotification = "/inApps/v1/notifications/test" PathGetTestNotificationStatus = "/inApps/v1/notifications/test/{testNotificationToken}" )
Variables ¶
var ( ErrAuthKeyInvalidPem = errors.New("token: AuthKey must be a valid .p8 PEM file") ErrAuthKeyInvalidType = errors.New("token: AuthKey must be of type ecdsa.PrivateKey") )
Authorize Tokens For App Store Server API Request Doc: https://developer.apple.com/documentation/appstoreserverapi/generating_tokens_for_api_requests
Functions ¶
func ShouldRetryDefault ¶ added in v1.9.0
Types ¶
type ConsumptionRequestBody ¶
type ConsumptionRequestBody struct { AccountTenure int `json:"accountTenure"` AppAccountToken string `json:"appAccountToken"` ConsumptionStatus int `json:"consumptionStatus"` CustomerConsented bool `json:"customerConsented"` DeliveryStatus int `json:"deliveryStatus"` LifetimeDollarsPurchased int `json:"lifetimeDollarsPurchased"` LifetimeDollarsRefunded int `json:"lifetimeDollarsRefunded"` Platform int `json:"platform"` PlayTime int `json:"playTime"` SampleContentProvided bool `json:"sampleContentProvided"` UserStatus int `json:"userStatus"` }
ConsumptionRequestBody https://developer.apple.com/documentation/appstoreserverapi/consumptionrequest
type DoFunc ¶
func RateLimit ¶ added in v1.6.0
func RateLimit(c HTTPClient, reqPerMin int) DoFunc
func RequireResponseBody ¶
func RequireResponseBody(c HTTPClient) DoFunc
func RequireResponseStatus ¶
func RequireResponseStatus(c HTTPClient, status ...int) DoFunc
func SetInitializer ¶ added in v1.6.0
func SetInitializer(c HTTPClient, init Initializer) DoFunc
func SetRequest ¶ added in v1.6.0
func SetRequestBody ¶ added in v1.6.0
func SetRequestBody(c HTTPClient, m Marshaller, v any) DoFunc
func SetRequestBodyJSON ¶ added in v1.6.0
func SetRequestBodyJSON(c HTTPClient, v any) DoFunc
func SetResponseBodyHandler ¶ added in v1.6.0
func SetResponseBodyHandler(c HTTPClient, u Unmarshaller, ptr any) DoFunc
type ExtendReasonCode ¶
type ExtendReasonCode int
https://developer.apple.com/documentation/appstoreserverapi/extendreasoncode
type ExtendRenewalDateRequest ¶
type ExtendRenewalDateRequest struct { ExtendByDays int `json:"extendByDays"` ExtendReasonCode ExtendReasonCode `json:"extendReasonCode"` RequestIdentifier string `json:"requestIdentifier"` }
ExtendRenewalDateRequest https://developer.apple.com/documentation/appstoreserverapi/extendrenewaldaterequest
type FirstSendAttemptResult ¶
type FirstSendAttemptResult string
https://developer.apple.com/documentation/appstoreserverapi/firstsendattemptresult
const ( FirstSendAttemptResultSuccess FirstSendAttemptResult = "SUCCESS" FirstSendAttemptResultCircularRedirect FirstSendAttemptResult = "CIRCULAR_REDIRECT" FirstSendAttemptResultInvalidResponse FirstSendAttemptResult = "INVALID_RESPONSE" FirstSendAttemptResultNoResponse FirstSendAttemptResult = "NO_RESPONSE" FirstSendAttemptResultOther FirstSendAttemptResult = "OTHER" FirstSendAttemptResultPrematureClose FirstSendAttemptResult = "PREMATURE_CLOSE" FirstSendAttemptResultSocketIssue FirstSendAttemptResult = "SOCKET_ISSUE" FirstSendAttemptResultTimedOut FirstSendAttemptResult = "TIMED_OUT" FirstSendAttemptResultTlsIssue FirstSendAttemptResult = "TLS_ISSUE" FirstSendAttemptResultUnsupportedCharset FirstSendAttemptResult = "UNSUPPORTED_CHARSET" )
type HistoryResponse ¶
type HistoryResponse struct { AppAppleId int `json:"appAppleId"` BundleId string `json:"bundleId"` Environment string `json:"environment"` HasMore bool `json:"hasMore"` Revision string `json:"revision"` SignedTransactions []string `json:"signedTransactions"` }
HistoryResponse https://developer.apple.com/documentation/appstoreserverapi/historyresponse
type Initializer ¶ added in v1.6.0
type Initializer func(HTTPClient) (DoFunc, error)
type JWSDecodedHeader ¶
type JWSDecodedHeader struct { Alg string `json:"alg,omitempty"` Kid string `json:"kid,omitempty"` X5C []string `json:"x5c,omitempty"` }
JWSDecodedHeader https://developer.apple.com/documentation/appstoreserverapi/jwsdecodedheader
type JWSRenewalInfoDecodedPayload ¶
type JWSRenewalInfoDecodedPayload struct { }
type JWSTransaction ¶
type JWSTransaction struct { TransactionID string `json:"transactionId,omitempty"` OriginalTransactionId string `json:"originalTransactionId,omitempty"` WebOrderLineItemId string `json:"webOrderLineItemId,omitempty"` BundleID string `json:"bundleId,omitempty"` ProductID string `json:"productId,omitempty"` SubscriptionGroupIdentifier string `json:"subscriptionGroupIdentifier,omitempty"` PurchaseDate int64 `json:"purchaseDate,omitempty"` OriginalPurchaseDate int64 `json:"originalPurchaseDate,omitempty"` ExpiresDate int64 `json:"expiresDate,omitempty"` Quantity int64 `json:"quantity,omitempty"` Type string `json:"type,omitempty"` AppAccountToken string `json:"appAccountToken,omitempty"` InAppOwnershipType string `json:"inAppOwnershipType,omitempty"` SignedDate int64 `json:"signedDate,omitempty"` OfferType int64 `json:"offerType,omitempty"` OfferIdentifier string `json:"offerIdentifier,omitempty"` RevocationDate int64 `json:"revocationDate,omitempty"` RevocationReason int `json:"revocationReason,omitempty"` IsUpgraded bool `json:"isUpgraded,omitempty"` }
JWSTransaction https://developer.apple.com/documentation/appstoreserverapi/jwstransaction
func (JWSTransaction) Valid ¶
func (J JWSTransaction) Valid() error
type JitterBackoff ¶ added in v1.9.0
type JitterBackoff struct { Initial time.Duration Max time.Duration Multiplier float64 // contains filtered or unexported fields }
func (*JitterBackoff) Pause ¶ added in v1.9.0
func (bo *JitterBackoff) Pause() time.Duration
type LastTransactionsItem ¶
type Marshaller ¶ added in v1.6.0
type NotificationData ¶ added in v1.10.0
type NotificationData struct { jwt.RegisteredClaims AppAppleID int `json:"appAppleId"` BundleID string `json:"bundleId"` BundleVersion string `json:"bundleVersion"` Environment string `json:"environment"` SignedRenewalInfo string `json:"signedRenewalInfo"` SignedTransactionInfo string `json:"signedTransactionInfo"` }
Notification Data
type NotificationHistoryRequest ¶
type NotificationHistoryRequest struct { StartDate int64 `json:"startDate"` EndDate int64 `json:"endDate"` OriginalTransactionId string `json:"originalTransactionId,omitempty"` NotificationType NotificationTypeV2 `json:"notificationType,omitempty"` NotificationSubtype SubtypeV2 `json:"notificationSubtype,omitempty"` }
NotificationHistoryRequest https://developer.apple.com/documentation/appstoreserverapi/notificationhistoryrequest
type NotificationHistoryResponseItem ¶
type NotificationHistoryResponseItem struct { SignedPayload string `json:"signedPayload"` FirstSendAttemptResult FirstSendAttemptResult `json:"firstSendAttemptResult"` }
NotificationHistoryResponseItem https://developer.apple.com/documentation/appstoreserverapi/notificationhistoryresponseitem
type NotificationHistoryResponses ¶
type NotificationHistoryResponses struct { HasMore bool `json:"hasMore"` PaginationToken string `json:"paginationToken"` NotificationHistory []NotificationHistoryResponseItem `json:"notificationHistory"` }
NotificationHistoryResponses https://developer.apple.com/documentation/appstoreserverapi/notificationhistoryresponse
type NotificationPayload ¶ added in v1.10.0
type NotificationPayload struct { jwt.RegisteredClaims NotificationType string `json:"notificationType"` Subtype string `json:"subtype"` NotificationUUID string `json:"notificationUUID"` NotificationVersion string `json:"notificationVersion"` Data NotificationData `json:"data"` }
Notification signed payload
type NotificationTypeV2 ¶
type NotificationTypeV2 string
const ( NotificationTypeV2ConsumptionRequest NotificationTypeV2 = "CONSUMPTION_REQUEST" NotificationTypeV2DidChangeRenewalPref NotificationTypeV2 = "DID_CHANGE_RENEWAL_PREF" NotificationTypeV2DidChangeRenewalStatus NotificationTypeV2 = "DID_CHANGE_RENEWAL_STATUS" NotificationTypeV2DidFailToRenew NotificationTypeV2 = "DID_FAIL_TO_RENEW" NotificationTypeV2DidRenew NotificationTypeV2 = "DID_RENEW" NotificationTypeV2Expired NotificationTypeV2 = "EXPIRED" NotificationTypeV2GracePeriodExpired NotificationTypeV2 = "GRACE_PERIOD_EXPIRED" NotificationTypeV2OfferRedeemed NotificationTypeV2 = "OFFER_REDEEMED" NotificationTypeV2PriceIncrease NotificationTypeV2 = "PRICE_INCREASE" NotificationTypeV2Refund NotificationTypeV2 = "REFUND" NotificationTypeV2RefundDeclined NotificationTypeV2 = "REFUND_DECLINED" NotificationTypeV2RenewalExtended NotificationTypeV2 = "RENEWAL_EXTENDED" NotificationTypeV2Revoke NotificationTypeV2 = "REVOKE" NotificationTypeV2Subscribed NotificationTypeV2 = "SUBSCRIBED" )
list of notificationType https://developer.apple.com/documentation/appstoreservernotifications/notificationtype
type OneSecondBackoff ¶ added in v1.9.0
type OneSecondBackoff struct{}
func (*OneSecondBackoff) Pause ¶ added in v1.9.0
func (bo *OneSecondBackoff) Pause() time.Duration
type OrderLookupResponse ¶
type OrderLookupResponse struct { Status int `json:"status"` SignedTransactions []string `json:"signedTransactions"` }
OrderLookupResponse https://developer.apple.com/documentation/appstoreserverapi/orderlookupresponse
type RefundLookupResponse ¶
type RefundLookupResponse struct { HasMore bool `json:"hasMore"` Revision string `json:"revision"` SignedTransactions []string `json:"signedTransactions"` }
RefundLookupResponse https://developer.apple.com/documentation/appstoreserverapi/refundlookupresponse
type RenewalInfo ¶ added in v1.10.0
type RenewalInfo struct { jwt.RegisteredClaims OriginalTransactionID string `json:"originalTransactionId"` ExpirationIntent int `json:"expirationIntent"` AutoRenewProductId string `json:"autoRenewProductId"` ProductID string `json:"productId"` AutoRenewStatus int `json:"autoRenewStatus"` IsInBillingRetryPeriod bool `json:"isInBillingRetryPeriod"` SignedDate int `json:"signedDate"` Environment string `json:"environment"` }
Notification Renewal Info
type SendTestNotificationResponse ¶
type SendTestNotificationResponse struct {
TestNotificationToken string `json:"testNotificationToken"`
}
SendTestNotificationResponse https://developer.apple.com/documentation/appstoreserverapi/sendtestnotificationresponse
type StatusResponse ¶
type StatusResponse struct { Environment string `json:"environment"` AppAppleId int `json:"appAppleId"` BundleId string `json:"bundleId"` Data []SubscriptionGroupIdentifierItem `json:"data"` }
StatusResponse https://developer.apple.com/documentation/appstoreserverapi/get_all_subscription_statuses
type StoreClient ¶
type StoreClient struct { Token *Token // contains filtered or unexported fields }
func NewStoreClient ¶
func NewStoreClient(config *StoreConfig) *StoreClient
NewStoreClient create a appstore server api client
func NewStoreClientWithHTTPClient ¶
func NewStoreClientWithHTTPClient(config *StoreConfig, httpClient *http.Client) *StoreClient
NewStoreClientWithHTTPClient creates a appstore server api client with a custom http client.
func (*StoreClient) Do ¶
func (c *StoreClient) Do(ctx context.Context, method string, url string, body io.Reader) (int, []byte, error)
Per doc: https://developer.apple.com/documentation/appstoreserverapi#topics
func (*StoreClient) ExtendSubscriptionRenewalDate ¶
func (c *StoreClient) ExtendSubscriptionRenewalDate(ctx context.Context, originalTransactionId string, body ExtendRenewalDateRequest) (statusCode int, err error)
ExtendSubscriptionRenewalDate https://developer.apple.com/documentation/appstoreserverapi/extend_a_subscription_renewal_date
func (*StoreClient) GetALLSubscriptionStatuses ¶
func (c *StoreClient) GetALLSubscriptionStatuses(ctx context.Context, originalTransactionId string) (*StatusResponse, error)
GetALLSubscriptionStatuses https://developer.apple.com/documentation/appstoreserverapi/get_all_subscription_statuses
func (*StoreClient) GetNotificationHistory ¶
func (c *StoreClient) GetNotificationHistory(ctx context.Context, body NotificationHistoryRequest) (responses []NotificationHistoryResponseItem, err error)
GetNotificationHistory https://developer.apple.com/documentation/appstoreserverapi/get_notification_history
func (*StoreClient) GetRefundHistory ¶
func (c *StoreClient) GetRefundHistory(ctx context.Context, originalTransactionId string) (responses []*RefundLookupResponse, err error)
GetRefundHistory https://developer.apple.com/documentation/appstoreserverapi/get_refund_history
func (*StoreClient) GetTestNotificationStatus ¶
func (c *StoreClient) GetTestNotificationStatus(ctx context.Context, testNotificationToken string) (int, []byte, error)
GetTestNotificationStatus https://developer.apple.com/documentation/appstoreserverapi/get_test_notification_status
func (*StoreClient) GetTransactionHistory ¶
func (c *StoreClient) GetTransactionHistory(ctx context.Context, originalTransactionId string, query *url.Values) (responses []*HistoryResponse, err error)
GetTransactionHistory https://developer.apple.com/documentation/appstoreserverapi/get_transaction_history
func (*StoreClient) LookupOrderID ¶
func (c *StoreClient) LookupOrderID(ctx context.Context, orderId string) (*OrderLookupResponse, error)
LookupOrderID https://developer.apple.com/documentation/appstoreserverapi/look_up_order_id
func (*StoreClient) ParseNotificationV2 ¶ added in v1.10.0
func (c *StoreClient) ParseNotificationV2(tokenStr string) (*jwt.Token, error)
func (*StoreClient) ParseSignedTransactions ¶
func (c *StoreClient) ParseSignedTransactions(transactions []string) ([]*JWSTransaction, error)
ParseSignedTransactions parse the jws singed transactions Per doc: https://datatracker.ietf.org/doc/html/rfc7515#section-4.1.6
func (*StoreClient) SendConsumptionInfo ¶
func (c *StoreClient) SendConsumptionInfo(ctx context.Context, originalTransactionId string, body ConsumptionRequestBody) (statusCode int, err error)
SendConsumptionInfo https://developer.apple.com/documentation/appstoreserverapi/send_consumption_information
func (*StoreClient) SendRequestTestNotification ¶
SendRequestTestNotification https://developer.apple.com/documentation/appstoreserverapi/request_a_test_notification
type StoreConfig ¶
type StoreConfig struct { KeyContent []byte // Loads a .p8 certificate KeyID string // Your private key ID from App Store Connect (Ex: 2X9R4HXF34) BundleID string // Your app’s bundle ID Issuer string // Your issuer ID from the Keys page in App Store Connect (Ex: "57246542-96fe-1a63-e053-0824d011072a") Sandbox bool // default is Production }
type SubscriptionGroupIdentifierItem ¶
type SubscriptionGroupIdentifierItem struct { SubscriptionGroupIdentifier string `json:"subscriptionGroupIdentifier"` LastTransactions []LastTransactionsItem `json:"lastTransactions"` }
type SubtypeV2 ¶
type SubtypeV2 string
SubtypeV2 is type
const ( SubTypeV2InitialBuy SubtypeV2 = "INITIAL_BUY" SubTypeV2Resubscribe SubtypeV2 = "RESUBSCRIBE" SubTypeV2Downgrade SubtypeV2 = "DOWNGRADE" SubTypeV2Upgrade SubtypeV2 = "UPGRADE" SubTypeV2AutoRenewEnabled SubtypeV2 = "AUTO_RENEW_ENABLED" SubTypeV2AutoRenewDisabled SubtypeV2 = "AUTO_RENEW_DISABLED" SubTypeV2Voluntary SubtypeV2 = "VOLUNTARY" SubTypeV2BillingRetry SubtypeV2 = "BILLING_RETRY" SubTypeV2PriceIncrease SubtypeV2 = "PRICE_INCREASE" SubTypeV2GracePeriod SubtypeV2 = "GRACE_PERIOD" SubTypeV2BillingRecovery SubtypeV2 = "BILLING_RECOVERY" SubTypeV2Pending SubtypeV2 = "PENDING" SubTypeV2Accepted SubtypeV2 = "ACCEPTED" )
list of subtypes https://developer.apple.com/documentation/appstoreservernotifications/subtype
type Token ¶
type Token struct { sync.Mutex KeyContent []byte // Loads a .p8 certificate KeyID string // Your private key ID from App Store Connect (Ex: 2X9R4HXF34) BundleID string // Your app’s bundle ID Issuer string // Your issuer ID from the Keys page in App Store Connect (Ex: "57246542-96fe-1a63-e053-0824d011072a") Sandbox bool // default is Production // internal variables AuthKey *ecdsa.PrivateKey // .p8 private key ExpiredAt int64 // The token’s expiration time, in UNIX time. Tokens that expire more than 60 minutes after the time in iat are not valid (Ex: 1623086400) Bearer string // Authorized bearer token }
Token represents an Apple Provider Authentication Token (JSON Web Token).
func (*Token) GenerateIfExpired ¶
GenerateIfExpired checks to see if the token is about to expire and generates a new token.
func (*Token) WithConfig ¶
func (t *Token) WithConfig(c *StoreConfig)
type TransactionInfo ¶ added in v1.10.0
type TransactionInfo struct { jwt.RegisteredClaims TransactionId string `json:"transactionId"` OriginalTransactionID string `json:"originalTransactionId"` WebOrderLineItemID string `json:"webOrderLineItemId"` BundleID string `json:"bundleId"` ProductID string `json:"productId"` SubscriptionGroupIdentifier string `json:"subscriptionGroupIdentifier"` PurchaseDate int `json:"purchaseDate"` OriginalPurchaseDate int `json:"originalPurchaseDate"` ExpiresDate int `json:"expiresDate"` Type string `json:"type"` InAppOwnershipType string `json:"inAppOwnershipType"` SignedDate int `json:"signedDate"` Environment string `json:"environment"` }
Notification Transaction Info