Version: v1.3.7 Latest Latest

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

Go to latest
Published: Oct 14, 2020 License: MIT Imports: 8 Imported by: 0




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


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")


func HandleError

func HandleError(status int) error

HandleError returns error message by status code


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
const (
	Sandbox    Environment = "Sandbox"
	Production Environment = "Production"

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

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"`
} 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; 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"`

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



	CancellationReason string `json:"cancellation_reason,omitempty"`

The InApp type has the receipt attributes

type NotificationEnvironment

type NotificationEnvironment string
const (
	NotificationSandbox    NotificationEnvironment = "Sandbox"
	NotificationProduction NotificationEnvironment = "PROD"

type NotificationExpiresDate

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

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"`


type NotificationType

type NotificationType string

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"

type NotificationUnifiedReceipt

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"`

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"`


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 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"`

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"`
	IsTrialPeriod        string `json:"is_trial_period"`
	IsInIntroOfferPeriod string `json:"is_in_intro_offer_period"`
	ItemID               string `json:"item_id"`
	ProductID            string `json:"product_id"`
	OriginalTransactionID string `json:"original_transaction_id"`
	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"`

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"`

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 string `json:"expiration_intent"`

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

	// 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: .
	LatestReceipt string `json:"latest_receipt"`
	// Deprecated: use UnifiedReceipt.LatestReceiptInfo instead. See details: .
	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: .
	LatestExpiredReceipt string `json:"latest_expired_receipt"`
	// Deprecated: see details: .
	LatestExpiredReceiptInfo NotificationReceipt `json:"latest_expired_receipt_info"`

	// Posted only if the notification_type is CANCEL.


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
t or T : Toggle theme light dark auto
y or Y : Canonical URL