appstore

package
v1.3.12 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 25, 2022 License: MIT Imports: 8 Imported by: 27

Documentation

Index

Constants

View Source
const (
	SubTypeV2InitialBuy        = "INITIAL_BUY"
	SubTypeV2Resubscribe       = "RESUBSCRIBE"
	SubTypeV2Downgrade         = "DOWNGRADE"
	SubTypeV2Upgrade           = "UPGRADE"
	SubTypeV2AutoRenewEnabled  = "AUTO_RENEW_ENABLED"
	SubTypeV2AutoRenewDisabled = "AUTO_RENEW_DISABLED"
	SubTypeV2Voluntary         = "VOLUNTARY"
	SubTypeV2BillingRetry      = "BILLING_RETRY"
	SubTypeV2PriceIncrease     = "PRICE_INCREASE"
	SubTypeV2GracePeriod       = "GRACE_PERIOD"
	SubTypeV2BillingRecovery   = "BILLING_RECOVERY"
	SubTypeV2Pending           = "PENDING"
	SubTypeV2Accepted          = "ACCEPTED"
)

list of subtypes https://developer.apple.com/documentation/appstoreservernotifications/subtype

View Source
const (
	// SandboxURL is the endpoint for sandbox environment.
	SandboxURL string = "https://sandbox.itunes.apple.com/verifyReceipt"
	// ProductionURL is the endpoint for production environment.
	ProductionURL string = "https://buy.itunes.apple.com/verifyReceipt"
	// ContentType is the request content-type for apple store.
	ContentType string = "application/json; charset=utf-8"
)

Variables

View Source
var (
	ErrAppStoreServer = errors.New("AppStore server error")

	ErrInvalidJSON            = errors.New("The App Store could not read the JSON object you provided.")
	ErrInvalidReceiptData     = errors.New("The data in the receipt-data property was malformed or missing.")
	ErrReceiptUnauthenticated = errors.New("The receipt could not be authenticated.")
	ErrInvalidSharedSecret    = errors.New("The shared secret you provided does not match the shared secret on file for your account.")
	ErrServerUnavailable      = errors.New("The receipt server is not currently available.")
	ErrReceiptIsForTest       = errors.New("This receipt is from the test environment, but it was sent to the production environment for verification. Send it to the test environment instead.")
	ErrReceiptIsForProduction = errors.New("This receipt is from the production environment, but it was sent to the test environment for verification. Send it to the production environment instead.")
	ErrReceiptUnauthorized    = errors.New("This receipt could not be authorized. Treat this the same as if a purchase was never made.")

	ErrInternalDataAccessError = errors.New("Internal data access error.")
	ErrUnknown                 = errors.New("An unknown error occurred")
)

list of errore

Functions

func HandleError

func HandleError(status int) error

HandleError returns error message by status code

Types

type AutoRenewStatusChangeDate added in v1.3.9

type AutoRenewStatusChangeDate struct {
	AutoRenewStatusChangeDate    string `json:"auto_renew_status_change_date"`
	AutoRenewStatusChangeDateMS  string `json:"auto_renew_status_change_date_ms"`
	AutoRenewStatusChangeDatePST string `json:"auto_renew_status_change_date_pst"`
}

AutoRenewStatusChangeDate type indicates the auto renew status change date

type CancellationDate

type CancellationDate struct {
	CancellationDate    string `json:"cancellation_date,omitempty"`
	CancellationDateMS  string `json:"cancellation_date_ms,omitempty"`
	CancellationDatePST string `json:"cancellation_date_pst,omitempty"`
}

The CancellationDate type indicates the time and date of the cancellation by Apple customer support

type Client

type Client struct {
	ProductionURL string
	SandboxURL    string
	// contains filtered or unexported fields
}

Client implements IAPClient

func New

func New() *Client

New creates a client object

func NewWithClient

func NewWithClient(client *http.Client) *Client

NewWithClient creates a client with a custom http client.

func (*Client) Verify

func (c *Client) Verify(ctx context.Context, reqBody IAPRequest, result interface{}) error

Verify sends receipts and gets validation result

type Environment

type Environment string

Environment is alias

const (
	Sandbox    Environment = "Sandbox"
	Production Environment = "Production"
)

list of Environment

type ExpiresDate

type ExpiresDate struct {
	ExpiresDate             string `json:"expires_date,omitempty"`
	ExpiresDateMS           string `json:"expires_date_ms,omitempty"`
	ExpiresDatePST          string `json:"expires_date_pst,omitempty"`
	ExpiresDateFormatted    string `json:"expires_date_formatted,omitempty"`
	ExpiresDateFormattedPST string `json:"expires_date_formatted_pst,omitempty"`
}

The ExpiresDate type indicates the expiration date for the subscription

type GracePeriodDate added in v1.1.0

type GracePeriodDate struct {
	GracePeriodDate    string `json:"grace_period_expires_date,omitempty"`
	GracePeriodDateMS  string `json:"grace_period_expires_date_ms,omitempty"`
	GracePeriodDatePST string `json:"grace_period_expires_date_pst,omitempty"`
}

The GracePeriodDate type indicates the grace period date for the subscription

type IAPClient

type IAPClient interface {
	Verify(ctx context.Context, reqBody IAPRequest, resp interface{}) error
}

IAPClient is an interface to call validation API in App Store

type IAPRequest

type IAPRequest struct {
	ReceiptData string `json:"receipt-data"`
	// Only used for receipts that contain auto-renewable subscriptions.
	Password string `json:"password,omitempty"`
	// Only used for iOS7 style app receipts that contain auto-renewable or non-renewing subscriptions.
	// If value is true, response includes only the latest renewal transaction for any subscriptions.
	ExcludeOldTransactions bool `json:"exclude-old-transactions"`
}

IAPRequest is struct https://developer.apple.com/library/content/releasenotes/General/ValidateAppStoreReceipt/Chapters/ValidateRemotely.html The IAPRequest type has the request parameter

type IAPResponse

type IAPResponse struct {
	Status             int                  `json:"status"`
	Environment        Environment          `json:"environment"`
	Receipt            Receipt              `json:"receipt"`
	LatestReceiptInfo  []InApp              `json:"latest_receipt_info,omitempty"`
	LatestReceipt      string               `json:"latest_receipt,omitempty"`
	PendingRenewalInfo []PendingRenewalInfo `json:"pending_renewal_info,omitempty"`
	IsRetryable        bool                 `json:"is-retryable,omitempty"`
}

The IAPResponse type has the response properties We defined each field by the current IAP response, but some fields are not mentioned in the following Apple's document; https://developer.apple.com/library/ios/releasenotes/General/ValidateAppStoreReceipt/Chapters/ReceiptFields.html If you get other types or fields from the IAP response, you should use the struct you defined.

type IAPResponseForIOS6

type IAPResponseForIOS6 struct {
	AutoRenewProductID       string         `json:"auto_renew_product_id"`
	AutoRenewStatus          int            `json:"auto_renew_status"`
	CancellationReason       string         `json:"cancellation_reason,omitempty"`
	ExpirationIntent         string         `json:"expiration_intent,omitempty"`
	IsInBillingRetryPeriod   string         `json:"is_in_billing_retry_period,omitempty"`
	Receipt                  ReceiptForIOS6 `json:"receipt"`
	LatestExpiredReceiptInfo ReceiptForIOS6 `json:"latest_expired_receipt_info"`
	LatestReceipt            string         `json:"latest_receipt"`
	LatestReceiptInfo        ReceiptForIOS6 `json:"latest_receipt_info"`
	Status                   int            `json:"status"`
}

IAPResponseForIOS6 is iOS 6 style receipt schema.

type InApp

type InApp struct {
	Quantity                    string `json:"quantity"`
	ProductID                   string `json:"product_id"`
	TransactionID               string `json:"transaction_id"`
	OriginalTransactionID       string `json:"original_transaction_id"`
	WebOrderLineItemID          string `json:"web_order_line_item_id,omitempty"`
	PromotionalOfferID          string `json:"promotional_offer_id"`
	SubscriptionGroupIdentifier string `json:"subscription_group_identifier"`
	OfferCodeRefName            string `json:"offer_code_ref_name,omitempty"`

	IsTrialPeriod        string `json:"is_trial_period"`
	IsInIntroOfferPeriod string `json:"is_in_intro_offer_period,omitempty"`
	IsUpgraded           string `json:"is_upgraded,omitempty"`

	ExpiresDate

	PurchaseDate
	OriginalPurchaseDate

	CancellationDate
	CancellationReason string `json:"cancellation_reason,omitempty"`

	InAppOwnershipType string `json:"in_app_ownership_type,omitempty"`
}

The InApp type has the receipt attributes

type NotificationEnvironment

type NotificationEnvironment string

NotificationEnvironment is type

const (
	NotificationSandbox    NotificationEnvironment = "Sandbox"
	NotificationProduction NotificationEnvironment = "PROD"
)

list of NotificationEnvironment

type NotificationExpiresDate

type NotificationExpiresDate struct {
	ExpiresDateMS  string `json:"expires_date"`
	ExpiresDateUTC string `json:"expires_date_formatted"`
	ExpiresDatePST string `json:"expires_date_formatted_pst"`
}

NotificationExpiresDate is struct

type NotificationReceipt

type NotificationReceipt struct {
	UniqueIdentifier          string `json:"unique_identifier"`
	AppItemID                 string `json:"app_item_id"`
	Quantity                  string `json:"quantity"`
	VersionExternalIdentifier string `json:"version_external_identifier"`
	UniqueVendorIdentifier    string `json:"unique_vendor_identifier"`
	WebOrderLineItemID        string `json:"web_order_line_item_id"`
	ItemID                    string `json:"item_id"`
	ProductID                 string `json:"product_id"`
	BID                       string `json:"bid"`
	BVRS                      string `json:"bvrs"`
	TransactionID             string `json:"transaction_id"`
	OriginalTransactionID     string `json:"original_transaction_id"`
	IsTrialPeriod             string `json:"is_trial_period"`
	IsInIntroOfferPeriod      string `json:"is_in_intro_offer_period"`

	PurchaseDate
	OriginalPurchaseDate
	NotificationExpiresDate
	CancellationDate
}

NotificationReceipt is struct

type NotificationType

type NotificationType string

NotificationType is type https://developer.apple.com/documentation/appstoreservernotifications/notification_type https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/StoreKitGuide/Chapters/Subscriptions.html#//apple_ref/doc/uid/TP40008267-CH7-SW16

const (
	// Initial purchase of the subscription.
	NotificationTypeInitialBuy NotificationType = "INITIAL_BUY"
	// Subscription was canceled by Apple customer support.
	NotificationTypeCancel NotificationType = "CANCEL"
	// Automatic renewal was successful for an expired subscription.
	// Deprecated: DID_RECOVER should be used instead of RENEWAL
	NotificationTypeRenewal NotificationType = "RENEWAL"
	// Expired subscription recovered through a billing retry.
	NotificationTypeDidRecover NotificationType = "DID_RECOVER"
	// Customer renewed a subscription interactively after it lapsed.
	NotificationTypeInteractiveRenewal NotificationType = "INTERACTIVE_RENEWAL"
	// Customer changed the plan that takes affect at the next subscription renewal. Current active plan is not affected.
	NotificationTypeDidChangeRenewalPreference NotificationType = "DID_CHANGE_RENEWAL_PREF"
	// Customer changed the subscription renewal status. Current active plan is not affected.
	NotificationTypeDidChangeRenewalStatus NotificationType = "DID_CHANGE_RENEWAL_STATUS"
	// Subscription failed to renew due to a billing issue.
	NotificationTypeDidFailToRenew NotificationType = "DID_FAIL_TO_RENEW"
	// AppleCare successfully refunded the transaction for a consumable, non-consumable, or a non-renewing subscription.
	NotificationTypeRefund NotificationType = "REFUND"
	// App Store has started asking the customer to consent to your app’s subscription price increase.
	NotificationTypePriceIncreaseConsent NotificationType = "PRICE_INCREASE_CONSENT"
	// Customer’s subscription has successfully auto-renewed for a new transaction period.
	NotificationTypeDidRenew NotificationType = "DID_RENEW"
	// Customer's in-app purchase through Family Sharing is no longer available through sharing.
	NotificationTypeDidRevoke NotificationType = "REVOKE"
	// Indicates that the customer initiated a refund request for a consumable in-app purchase, and the App Store is requesting that you provide consumption data.
	NotificationTypeConsumptionRequest NotificationType = "CONSUMPTION_REQUEST"
)

list of NotificationType

type NotificationTypeV2 added in v1.3.12

type NotificationTypeV2 string

NotificationTypeV2 is type

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 NotificationUnifiedReceipt added in v1.2.0

type NotificationUnifiedReceipt struct {
	Status             int                  `json:"status"`
	Environment        Environment          `json:"environment"`
	LatestReceipt      string               `json:"latest_receipt"`
	LatestReceiptInfo  []InApp              `json:"latest_receipt_info"`
	PendingRenewalInfo []PendingRenewalInfo `json:"pending_renewal_info,omitempty"`
}

NotificationUnifiedReceipt is struct

type OriginalPurchaseDate

type OriginalPurchaseDate struct {
	OriginalPurchaseDate    string `json:"original_purchase_date"`
	OriginalPurchaseDateMS  string `json:"original_purchase_date_ms"`
	OriginalPurchaseDatePST string `json:"original_purchase_date_pst"`
}

The OriginalPurchaseDate type indicates the beginning of the subscription period

type PendingRenewalInfo

type PendingRenewalInfo struct {
	SubscriptionExpirationIntent   string `json:"expiration_intent"`
	SubscriptionAutoRenewProductID string `json:"auto_renew_product_id"`
	SubscriptionRetryFlag          string `json:"is_in_billing_retry_period"`
	SubscriptionAutoRenewStatus    string `json:"auto_renew_status"`
	SubscriptionPriceConsentStatus string `json:"price_consent_status"`
	ProductID                      string `json:"product_id"`
	OriginalTransactionID          string `json:"original_transaction_id"`
	OfferCodeRefName               string `json:"offer_code_ref_name,omitempty"`

	GracePeriodDate
}

PendingRenewalInfo is struct A pending renewal may refer to a renewal that is scheduled in the future or a renewal that failed in the past for some reason.

type PreorderDate added in v1.3.11

type PreorderDate struct {
	PreorderDate    string `json:"preorder_date"`
	PreorderDateMS  string `json:"preorder_date_ms"`
	PreorderDatePST string `json:"preorder_date_pst"`
}

The PreorderDate type indicates the date and time that the pre-order

type PurchaseDate

type PurchaseDate struct {
	PurchaseDate    string `json:"purchase_date"`
	PurchaseDateMS  string `json:"purchase_date_ms"`
	PurchaseDatePST string `json:"purchase_date_pst"`
}

The PurchaseDate type indicates the date and time that the item was purchased

type Receipt

type Receipt struct {
	ReceiptType                string        `json:"receipt_type"`
	AdamID                     int64         `json:"adam_id"`
	AppItemID                  numericString `json:"app_item_id"`
	BundleID                   string        `json:"bundle_id"`
	ApplicationVersion         string        `json:"application_version"`
	DownloadID                 int64         `json:"download_id"`
	VersionExternalIdentifier  numericString `json:"version_external_identifier"`
	OriginalApplicationVersion string        `json:"original_application_version"`
	InApp                      []InApp       `json:"in_app"`
	ReceiptCreationDate
	RequestDate
	OriginalPurchaseDate
	PreorderDate
}

The Receipt type has whole data of receipt

type ReceiptCreationDate

type ReceiptCreationDate struct {
	CreationDate    string `json:"receipt_creation_date"`
	CreationDateMS  string `json:"receipt_creation_date_ms"`
	CreationDatePST string `json:"receipt_creation_date_pst"`
}

The ReceiptCreationDate type indicates the date when the app receipt was created.

type ReceiptForIOS6

type ReceiptForIOS6 struct {
	AppItemID numericString `json:"app_item_id"`
	BID       string        `json:"bid"`
	BVRS      string        `json:"bvrs"`
	CancellationDate
	ExpiresDate
	IsTrialPeriod        string `json:"is_trial_period"`
	IsInIntroOfferPeriod string `json:"is_in_intro_offer_period"`
	ItemID               string `json:"item_id"`
	ProductID            string `json:"product_id"`
	PurchaseDate
	OriginalTransactionID string `json:"original_transaction_id"`
	OriginalPurchaseDate
	Quantity                  string        `json:"quantity"`
	TransactionID             string        `json:"transaction_id"`
	UniqueIdentifier          string        `json:"unique_identifier"`
	UniqueVendorIdentifier    string        `json:"unique_vendor_identifier"`
	VersionExternalIdentifier numericString `json:"version_external_identifier,omitempty"`
	WebOrderLineItemID        string        `json:"web_order_line_item_id"`
}

ReceiptForIOS6 is struct

type RequestDate

type RequestDate struct {
	RequestDate    string `json:"request_date"`
	RequestDateMS  string `json:"request_date_ms"`
	RequestDatePST string `json:"request_date_pst"`
}

The RequestDate type indicates the date and time that the request was sent

type StatusResponse

type StatusResponse struct {
	Status int `json:"status"`
}

StatusResponse is struct The HttpStatusResponse struct contains the status code returned by the store Used as a workaround to detect when to hit the production appstore or sandbox appstore regardless of receipt type

type SubscriptionNotification

type SubscriptionNotification struct {
	Environment      NotificationEnvironment `json:"environment"`
	NotificationType NotificationType        `json:"notification_type"`

	// Not show in raw notify body
	Password              string `json:"password"`
	OriginalTransactionID string `json:"original_transaction_id"`
	AutoRenewAdamID       string `json:"auto_renew_adam_id"`

	// The primary key for identifying a subscription purchase.
	// Posted only if the notification_type is CANCEL.
	WebOrderLineItemID string `json:"web_order_line_item_id"`

	// This is the same as the Subscription Expiration Intent in the receipt.
	// Posted only if notification_type is RENEWAL or INTERACTIVE_RENEWAL.
	ExpirationIntent int `json:"expiration_intent"`

	// Auto renew info
	AutoRenewStatus    string `json:"auto_renew_status"` // false or true
	AutoRenewProductID string `json:"auto_renew_product_id"`
	AutoRenewStatusChangeDate

	// Posted if the notification_type is RENEWAL or INTERACTIVE_RENEWAL, and only if the renewal is successful.
	// Posted also if the notification_type is INITIAL_BUY.
	// Not posted for notification_type CANCEL.
	// Deprecated: use UnifiedReceipt.LatestReceipt instead. See details: https://developer.apple.com/documentation/appstoreservernotifications/ .
	LatestReceipt string `json:"latest_receipt"`
	// Deprecated: use UnifiedReceipt.LatestReceiptInfo instead. See details: https://developer.apple.com/documentation/appstoreservernotifications/ .
	LatestReceiptInfo NotificationReceipt `json:"latest_receipt_info"`

	// In the new notifications above properties latest_receipt, latest_receipt_info are moved under this one
	UnifiedReceipt NotificationUnifiedReceipt `json:"unified_receipt"`

	// Posted only if the notification_type is RENEWAL or CANCEL or if renewal failed and subscription expired.
	// Deprecated: see details: https://developer.apple.com/documentation/appstoreservernotifications/ .
	LatestExpiredReceipt string `json:"latest_expired_receipt"`
	// Deprecated: see details: https://developer.apple.com/documentation/appstoreservernotifications/ .
	LatestExpiredReceiptInfo NotificationReceipt `json:"latest_expired_receipt_info"`

	// BID is the app bundle ID
	BID string `json:"bid,omitempty"`
	// BVRS is the app bundle version
	BVRS string `json:"bvrs,omitempty"`

	// Posted only if the notification_type is CANCEL.
	CancellationDate
}

SubscriptionNotification is struct for https://developer.apple.com/documentation/appstoreservernotifications/responsebodyv1

type SubscriptionNotificationV2 added in v1.3.12

type SubscriptionNotificationV2 struct {
	SignedPayload SubscriptionNotificationV2SignedPayload `json:"signedPayload"`
}

SubscriptionNotificationV2 is struct for https://developer.apple.com/documentation/appstoreservernotifications/responsebodyv2

type SubscriptionNotificationV2Data added in v1.3.12

type SubscriptionNotificationV2Data struct {
	AppAppleID            int    `json:"appAppleId"`
	BundleID              string `json:"bundleId"`
	BundleVersion         string `json:"bundleVersion"`
	Environment           string `json:"environment"`
	SignedRenewalInfo     string `json:"signedRenewalInfo"`
	SignedTransactionInfo string `json:"signedTransactionInfo"`
}

SubscriptionNotificationV2Data is struct https://developer.apple.com/documentation/appstoreservernotifications/data

type SubscriptionNotificationV2DecodedPayload added in v1.3.12

type SubscriptionNotificationV2DecodedPayload struct {
	NotificationType    NotificationTypeV2             `json:"notificationType"`
	Subtype             SubtypeV2                      `json:"subtype"`
	NotificationUUID    string                         `json:"notificationUUID"`
	NotificationVersion string                         `json:"notificationVersion"`
	Data                SubscriptionNotificationV2Data `json:"data"`
}

SubscriptionNotificationV2DecodedPayload is struct https://developer.apple.com/documentation/appstoreservernotifications/responsebodyv2decodedpayload

type SubscriptionNotificationV2JWSDecodedHeader added in v1.3.12

type SubscriptionNotificationV2JWSDecodedHeader struct {
	Alg string   `json:"alg"`
	Kid string   `json:"kid"`
	X5c []string `json:"x5c"`
}

SubscriptionNotificationV2JWSDecodedHeader is struct

type SubscriptionNotificationV2SignedPayload added in v1.3.12

type SubscriptionNotificationV2SignedPayload struct {
	SignedPayload string `json:"signedPayload"`
}

SubscriptionNotificationV2SignedPayload is struct https://developer.apple.com/documentation/appstoreservernotifications/signedpayload

type SubtypeV2 added in v1.3.12

type SubtypeV2 string

SubtypeV2 is type

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL