Documentation
¶
Overview ¶
Package iap provides store receipt verification helpers (Apple, Google, Huawei). Patterns follow the reference engine's iap package.
Index ¶
- Constants
- Variables
- func IsJWS(receipt string) bool
- func ParseMsTimestamp(ms string) time.Time
- func ValidateAppleJWSSignature(receipt string) error
- func ValidateReceiptHuawei(ctx context.Context, httpc *http.Client, ...) (*ValidateReceiptHuaweiResponse, *InAppPurchaseDataHuawei, []byte, error)
- func VerifySignatureHuawei(base64EncodedPublicKey, data, signature string) error
- type AppleJWSTransaction
- type InAppPurchaseDataHuawei
- type ReceiptGoogle
- type SubscriptionV2GoogleResponse
- type ValidateReceiptAppleResponse
- type ValidateReceiptGoogleResponse
- type ValidateReceiptHuaweiResponse
- type ValidationError
Constants ¶
const ( AppleReceiptValidationURLProduction = "https://buy.itunes.apple.com/verifyReceipt" AppleReceiptValidationURLSandbox = "https://sandbox.itunes.apple.com/verifyReceipt" AppleReceiptIsFromTestSandbox = 21007 )
const ( AppleSandboxEnvironment = "Sandbox" AppleProductionEnvironment = "Production" )
const AppleRootPEM = `` /* 848-byte string literal not displayed */
Variables ¶
var ( ErrNon200ServiceApple = errors.New("non-200 response from Apple service") ErrNon200ServiceGoogle = errors.New("non-200 response from Google service") ErrNon200ServiceHuawei = errors.New("non-200 response from Huawei service") ErrInvalidSignatureHuawei = errors.New("inAppPurchaseData invalid signature") )
var HTTPClient = &http.Client{Timeout: 20 * time.Second}
Shared HTTP client for provider calls.
Functions ¶
func ParseMsTimestamp ¶
ParseMsTimestamp converts Apple millisecond string to time.
func ValidateAppleJWSSignature ¶
ValidateAppleJWSSignature verifies the Apple StoreKit 2 JWS signature chain.
func ValidateReceiptHuawei ¶
func ValidateReceiptHuawei(ctx context.Context, httpc *http.Client, pubKey, clientID, clientSecret, purchaseData, signature string) (*ValidateReceiptHuaweiResponse, *InAppPurchaseDataHuawei, []byte, error)
ValidateReceiptHuawei verifies RSA signature and calls Huawei purchase token verify API.
func VerifySignatureHuawei ¶
VerifySignatureHuawei validates the InAppPurchaseData RSA signature.
Types ¶
type AppleJWSTransaction ¶
type AppleJWSTransaction struct {
ProductID string `json:"productId"`
TransactionID string `json:"transactionId"`
OriginalTransactionID string `json:"originalTransactionId"`
PurchaseDate int64 `json:"purchaseDate"`
ExpiresDate int64 `json:"expiresDate"`
RevocationDate int64 `json:"revocationDate"`
Environment string `json:"environment"`
}
AppleJWSTransaction is the decoded StoreKit 2 JWS payload.
func ParseAppleJWSTransaction ¶
func ParseAppleJWSTransaction(receipt string) (*AppleJWSTransaction, error)
ParseAppleJWSTransaction validates signature and returns the transaction payload.
type InAppPurchaseDataHuawei ¶
type InAppPurchaseDataHuawei struct {
ApplicationID string `json:"applicationId"`
AutoRenewing bool `json:"autoRenewing"`
OrderID string `json:"orderId"`
Kind int `json:"kind"`
PackageName string `json:"packageName"`
ProductID string `json:"productId"`
PurchaseTime int64 `json:"purchaseTime"`
PurchaseToken string `json:"purchaseToken"`
AccountFlag int `json:"accountFlag"`
PurchaseType int `json:"purchaseType"`
}
InAppPurchaseDataHuawei is the Huawei InAppPurchaseData JSON.
type ReceiptGoogle ¶
type ReceiptGoogle struct {
OrderID string `json:"orderId"`
PackageName string `json:"packageName"`
ProductID string `json:"productId"`
PurchaseState int `json:"purchaseState"`
PurchaseTime int64 `json:"purchaseTime"`
PurchaseToken string `json:"purchaseToken"`
}
ReceiptGoogle is the client purchase JSON used to call the Publisher API.
func DecodeReceiptGoogle ¶
func DecodeReceiptGoogle(receipt string) (*ReceiptGoogle, error)
DecodeReceiptGoogle unwraps client receipt JSON (optionally wrapped in {"json":"..."}).
type SubscriptionV2GoogleResponse ¶
type SubscriptionV2GoogleResponse struct {
LineItems []struct {
ProductID string `json:"productId"`
ExpiryTime time.Time `json:"expiryTime"`
} `json:"lineItems"`
StartTime time.Time `json:"startTime"`
}
SubscriptionV2GoogleResponse is a minimal subscriptions.v2 response.
func ValidateSubscriptionGoogle ¶
func ValidateSubscriptionGoogle(ctx context.Context, httpc *http.Client, clientEmail, privateKey, packageName, purchaseToken string) (*SubscriptionV2GoogleResponse, []byte, error)
ValidateSubscriptionGoogle calls Android Publisher purchases.subscriptionsv2.get.
type ValidateReceiptAppleResponse ¶
type ValidateReceiptAppleResponse struct {
Environment string `json:"environment"`
Status int `json:"status"`
LatestReceiptInfo []struct {
ProductID string `json:"product_id"`
TransactionID string `json:"transaction_id"`
OriginalTransactionID string `json:"original_transaction_id"`
PurchaseDateMs string `json:"purchase_date_ms"`
ExpiresDateMs string `json:"expires_date_ms"`
CancellationDateMs string `json:"cancellation_date_ms"`
} `json:"latest_receipt_info"`
Receipt *struct {
InApp []struct {
ProductID string `json:"product_id"`
TransactionID string `json:"transaction_id"`
OriginalTransactionID string `json:"original_transaction_id"`
PurchaseDateMs string `json:"purchase_date_ms"`
ExpiresDateMs string `json:"expires_date_ms"`
CancellationDateMs string `json:"cancellation_date_ms"`
} `json:"in_app"`
} `json:"receipt"`
}
ValidateReceiptAppleResponse is the legacy verifyReceipt response.
func ValidateLegacyReceiptApple ¶
func ValidateLegacyReceiptApple(ctx context.Context, httpc *http.Client, password, receipt string) (*ValidateReceiptAppleResponse, []byte, error)
ValidateLegacyReceiptApple calls Apple verifyReceipt (production then sandbox on 21007).
type ValidateReceiptGoogleResponse ¶
type ValidateReceiptGoogleResponse struct {
AcknowledgementState int `json:"acknowledgementState"`
ConsumptionState int `json:"consumptionState"`
Kind string `json:"kind"`
OrderID string `json:"orderId"`
PurchaseState int `json:"purchaseState"`
PurchaseTimeMillis string `json:"purchaseTimeMillis"`
PurchaseType int `json:"purchaseType"`
RegionCode string `json:"regionCode"`
}
ValidateReceiptGoogleResponse is the Android Publisher product purchase response.
func ValidateProductGoogle ¶
func ValidateProductGoogle(ctx context.Context, httpc *http.Client, clientEmail, privateKey, packageName, productID, purchaseToken string) (*ValidateReceiptGoogleResponse, []byte, error)
ValidateProductGoogle calls Android Publisher purchases.products.get.
type ValidateReceiptHuaweiResponse ¶
type ValidateReceiptHuaweiResponse struct {
ResponseCode string `json:"responseCode"`
ResponseMessage string `json:"responseMessage"`
PurchaseTokenData InAppPurchaseDataHuawei `json:"purchaseTokenData"`
DataSignature string `json:"dataSignature"`
}
ValidateReceiptHuaweiResponse is the Huawei verify response.
type ValidationError ¶
ValidationError wraps a non-success provider HTTP response.
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string
func (*ValidationError) Unwrap ¶
func (e *ValidationError) Unwrap() error