appstore

package
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: May 27, 2022 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SandboxURL    string = "https://sandbox.itunes.apple.com/verifyReceipt"
	ProductionURL string = "https://buy.itunes.apple.com/verifyReceipt"
)

Variables

This section is empty.

Functions

func HandleError

func HandleError(status int) error

HandleError returns error message by status code

func ToBool

func ToBool(v string) bool

func ToInt64

func ToInt64(v string) int64

func ToTime

func ToTime(msString string) time.Time

Types

type CancellationDate

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

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

type Client

type Client struct {
	URL     string
	TimeOut time.Duration
	Retry   bool
	Debug   bool
}

Client implements IAPClient

func New

func New() Client

New creates a client object

func NewWithConfig

func NewWithConfig(config Config) Client

NewWithConfig creates a client with configuration

func (*Client) Verify

func (c *Client) Verify(req IAPRequest) (*Receipt, error)

Verify sends receipts and gets validation result

type Config

type Config struct {
	IsProduction bool
	TimeOut      time.Duration
	Retry        bool
	Debug        bool
}

Config is a configuration to initialize client

type ExpiresDate

type ExpiresDate struct {
	ExpiresDate    string `json:"expires_date"`
	ExpiresDateMS  string `json:"expires_date_ms"`
	ExpiresDatePST string `json:"expires_date_pst"`
}

The ExpiresDate type indicates the expiration date for the subscription

type IAPClient

type IAPClient interface {
	Verify(IAPRequest) (*Receipt, error)
}

IAPClient is an interface to call validation API in App Store

type IAPRequest

type IAPRequest struct {
	ReceiptData string `json:"receipt-data"`
	Password    string `json:"password,omitempty"`
}

The IAPRequest type has the request parameter

type IAPResponseIOS6

type IAPResponseIOS6 struct {
	Status                   int         `json:"status"`
	Receipt                  ReceiptIOS6 `json:"receipt"`
	LatestReceiptInfo        ReceiptIOS6 `json:"latest_receipt_info"`
	LatestExpiredReceiptInfo ReceiptIOS6 `json:"latest_expired_receipt_info"`
	LatestReceipt            string      `json:"latest_receipt"`

	// pending_renewal_info in iOS 6 style receipt.
	AutoRenewStatus    int    `json:"auto_renew_status"`
	AutoRenewProductID string `json:"auto_renew_product_id"`
	ExpirationIntent   string `json:"expiration_intent"`
	RetryFlag          string `json:"is_in_billing_retry_period"`

	IsRetryable bool `json:"is_retryable"`
	// contains filtered or unexported fields
}

The IAPResponse type has the response properties

func NewIAPResponseIOS6

func NewIAPResponseIOS6(rc string) *IAPResponseIOS6

func (*IAPResponseIOS6) ToIOS7

func (r *IAPResponseIOS6) ToIOS7() *IAPResponseIOS7

type IAPResponseIOS7

type IAPResponseIOS7 struct {
	Status             int                  `json:"status"`
	Environment        string               `json:"environment"`
	Receipt            ReceiptIOS7          `json:"receipt"`
	LatestReceiptInfo  []InApp              `json:"latest_receipt_info"`
	LatestReceipt      string               `json:"latest_receipt"`
	PendingRenewalInfo []PendingRenewalInfo `json:"pending_renewal_info"`
	IsRetryable        bool                 `json:"is_retryable"`
	// contains filtered or unexported fields
}

The IAPResponse type has the response properties

func NewIAPResponseIOS7

func NewIAPResponseIOS7(rc string) *IAPResponseIOS7

func (*IAPResponseIOS7) ToReceipt

func (r *IAPResponseIOS7) ToReceipt() *Receipt

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"`
	IsTrialPeriod             string `json:"is_trial_period"`
	IsInIntroOfferPeriod      string `json:"is_in_intro_offer_period"`
	AppItemID                 string `json:"app_item_id"`
	VersionExternalIdentifier string `json:"version_external_identifier"`
	WebOrderLineItemID        string `json:"web_order_line_item_id"`
	PromotionalOfferID        string `json:"promotional_offer_id"`
	OfferCodeRefName          string `json:"offer_code_ref_name"`
	PurchaseDate
	OriginalPurchaseDate
	ExpiresDate
	CancellationDate
}

The InApp type has the receipt attributes

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 added in v0.2.2

type PendingRenewalInfo struct {
	ExpirationIntent   string `json:"expiration_intent"`
	AutoRenewProductID string `json:"auto_renew_product_id"`
	RetryFlag          string `json:"is_in_billing_retry_period"`
	AutoRenewStatus    string `json:"auto_renew_status"`
	PriceConsentStatus string `json:"price_consent_status"`
	ProductID          string `json:"product_id"`
}

PendingRenewalInfo auto-renewable subscriptions

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 {
	Status      int
	Environment string

	ReceiptType                string
	AdamID                     int64
	AppItemID                  int64
	BundleID                   string
	ApplicationVersion         string
	DownloadID                 int64
	OriginalApplicationVersion string
	RequestDate                time.Time
	OriginalPurchaseDate       time.Time
	InApps                     ReceiptInApps

	LatestReceiptInfo ReceiptInApps
	LatestReceipt     string

	PendingRenewalInfo ReceiptPendingRenewalInfos
	IsRetryable        bool
	// contains filtered or unexported fields
}

Receipt is struct for iap receipt data

func (*Receipt) GetByTransactionID

func (r *Receipt) GetByTransactionID(id int64) *ReceiptInApp

GetByTransactionID returns receipt data by `transaction_id`

func (*Receipt) GetEnvironment

func (r *Receipt) GetEnvironment() string

func (*Receipt) GetLastExpiresByProductID

func (r *Receipt) GetLastExpiresByProductID(productID string) *ReceiptInApp

GetLastExpiresByProductID returns latest expires receipt data by `product_id`

func (*Receipt) GetLastExpiresByTransactionIDs

func (r *Receipt) GetLastExpiresByTransactionIDs(ids []int64) *ReceiptInApp

GetLastExpiresByTransactionIDs returns latest expires receipt data from `transaction_id` list

func (*Receipt) GetStatus

func (r *Receipt) GetStatus() int

GetStatus returns status code of the receipt see: https://developer.apple.com/library/ios/releasenotes/General/ValidateAppStoreReceipt/Chapters/ValidateRemotely.html

func (*Receipt) GetTransactionIDs

func (r *Receipt) GetTransactionIDs() []int64

GetTransactionIDs returns all of transaction_id from `in_app`

func (*Receipt) GetTransactionIDsByProduct

func (r *Receipt) GetTransactionIDsByProduct(product string) []int64

GetTransactionIDsByProduct returns all of transaction_id from `in_app` filtered by `product_id`

func (*Receipt) GetTransactionIDsByProductWithoutExpired added in v0.2.0

func (r *Receipt) GetTransactionIDsByProductWithoutExpired(product string) []int64

GetTransactionIDsByProductWithoutExpired returns all of transaction_id filtered by `product_id` except expired

func (*Receipt) GetTransactionIDsWithoutExpired added in v0.2.0

func (r *Receipt) GetTransactionIDsWithoutExpired() []int64

GetTransactionIDsWithoutExpired returns all of transaction_id except expired

func (*Receipt) HasError

func (r *Receipt) HasError() error

func (*Receipt) HasExpired

func (r *Receipt) HasExpired() bool

HasExpired checks this receipt is expired or not (only for iOS6 style)

func (*Receipt) IsAutoRenewable

func (r *Receipt) IsAutoRenewable() bool

IsAutoRenewable checks this receipt is auto-renewable subscription or not

func (*Receipt) IsValidReceipt

func (r *Receipt) IsValidReceipt() bool

IsValidReceipt checks this receipt is valid receipt or not if this receipt is auto-renewable and iOS6 style, expired one returns false

func (*Receipt) LatestReceiptString

func (r *Receipt) LatestReceiptString() string

LatestReceiptString returns raw receipt of `latest_receipt`

func (*Receipt) ResponseVersion

func (r *Receipt) ResponseVersion() int

ResponseVersion returns receipt style; iOS6 style returns `6` iOS7 style returns `7`

func (*Receipt) ShouldSendToProductionEnvironment added in v0.2.6

func (r *Receipt) ShouldSendToProductionEnvironment() bool

ShouldSendToProductionEnvironment checks this receipt status is 21008 this receipt is from the production environment, but it was sent to the test environment for verification

func (*Receipt) ShouldSendToTestEnvironment added in v0.2.6

func (r *Receipt) ShouldSendToTestEnvironment() bool

ShouldSendToTestEnvironment checks this receipt status is 21007 this receipt is from the test environment, but it was sent to the production environment for verification

func (*Receipt) String

func (r *Receipt) String() string

type ReceiptIOS6

type ReceiptIOS6 struct {
	AppItemID                  string `json:"app_item_id"`
	BundleID                   string `json:"bid"`
	ApplicationVersion         string `json:"bvrs"`
	OriginalApplicationVersion string `json:"original_application_version"`
	OriginalTransactionID      string `json:"original_transaction_id"`
	ProductID                  string `json:"product_id"`
	Quantity                   string `json:"quantity"`
	TransactionID              string `json:"transaction_id"`
	VersionExternalIdentifier  string `json:"version_external_identifier"`
	WebOrderLineItemID         string `json:"web_order_line_item_id"`
	ExpiresDate                string `json:"expires_date_formatted"`
	ExpiresDateMS              string `json:"expires_date"`
	ExpiresDatePST             string `json:"expires_date_formatted_pst"`
	RequestDate
	PurchaseDate
	OriginalPurchaseDate
	IsTrialPeriod        string `json:"is_trial_period"`
	IsInIntroOfferPeriod string `json:"is_in_intro_offer_period"`
	PromotionalOfferID   string `json:"promotional_offer_id"`
	OfferCodeRefName     string `json:"offer_code_ref_name"`
}

The Receipt type has whole data of receipt

func (*ReceiptIOS6) ToIOS7

func (rc *ReceiptIOS6) ToIOS7() ReceiptIOS7

func (*ReceiptIOS6) ToInApp

func (rc *ReceiptIOS6) ToInApp() InApp

type ReceiptIOS7

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

The Receipt type has whole data of receipt

type ReceiptInApp

type ReceiptInApp struct {
	Quantity                  int64
	ProductID                 string
	TransactionID             int64
	OriginalTransactionID     int64
	IsTrialPeriod             bool
	IsInIntroOfferPeriod      bool
	AppItemID                 int64
	VersionExternalIdentifier int64
	WebOrderLineItemID        int64
	PurchaseDate              time.Time
	OriginalPurchaseDate      time.Time
	ExpiresDate               time.Time
	CancellationDate          time.Time
	PromotionalOfferID        string
	OfferCodeRefName          string
}

ReceiptInApp is struct for in_app field

func ToReceiptInApp

func ToReceiptInApp(ap InApp) *ReceiptInApp

type ReceiptInApps

type ReceiptInApps []*ReceiptInApp

func ToReceiptInApps

func ToReceiptInApps(aps []InApp) ReceiptInApps

func (ReceiptInApps) ByProduct

func (r ReceiptInApps) ByProduct(productID string) ReceiptInApps

func (ReceiptInApps) ByTransactionID

func (r ReceiptInApps) ByTransactionID(id int64) *ReceiptInApp

func (ReceiptInApps) IsAutoRenewable

func (r ReceiptInApps) IsAutoRenewable() bool

func (ReceiptInApps) LastExpiresByProductID

func (r ReceiptInApps) LastExpiresByProductID(productID string) *ReceiptInApp

for auto-renewable

func (ReceiptInApps) LastExpiresByProductIDForLatest

func (r ReceiptInApps) LastExpiresByProductIDForLatest(productID string) *ReceiptInApp

for LatestReceiptInfo

func (ReceiptInApps) LastExpiresByTransactionIDs

func (r ReceiptInApps) LastExpiresByTransactionIDs(ids []int64) *ReceiptInApp

func (ReceiptInApps) LastExpiresByTransactionIDsForLatest

func (r ReceiptInApps) LastExpiresByTransactionIDsForLatest(ids []int64) *ReceiptInApp

func (ReceiptInApps) TransactionIDs

func (r ReceiptInApps) TransactionIDs() []int64

func (ReceiptInApps) TransactionIDsByProduct

func (r ReceiptInApps) TransactionIDsByProduct(productID string) []int64

type ReceiptPendingRenewalInfo added in v0.2.2

type ReceiptPendingRenewalInfo struct {
	ExpirationIntent   int64  `json:"expiration_intent"`
	AutoRenewProductID string `json:"auto_renew_product_id"`
	RetryFlag          bool   `json:"is_in_billing_retry_period"`
	AutoRenewStatus    bool   `json:"auto_renew_status"`
	PriceConsentStatus bool   `json:"price_consent_status"`
	ProductID          string `json:"product_id"`
}

ReceiptPendingRenewalInfo is struct for pending_renewal_info field.

func ToReceiptPendingRenewalInfo added in v0.2.2

func ToReceiptPendingRenewalInfo(pri PendingRenewalInfo) *ReceiptPendingRenewalInfo

func (ReceiptPendingRenewalInfo) IsDifferentAutoRenewProductID added in v0.2.5

func (r ReceiptPendingRenewalInfo) IsDifferentAutoRenewProductID() bool

IsDifferentAutoRenewProductID checks that AutoRenewProductID is changed from ProductID.

type ReceiptPendingRenewalInfos added in v0.2.2

type ReceiptPendingRenewalInfos []*ReceiptPendingRenewalInfo

func ToReceiptPendingRenewalInfos added in v0.2.2

func ToReceiptPendingRenewalInfos(pris []PendingRenewalInfo) ReceiptPendingRenewalInfos

func (ReceiptPendingRenewalInfos) GetRenewalInfo added in v0.2.5

func (r ReceiptPendingRenewalInfos) GetRenewalInfo(productID string) *ReceiptPendingRenewalInfo

GetRenewalInfo returns ReceiptPendingRenewalInfo of given productID.

func (ReceiptPendingRenewalInfos) IsAutoRenewStatusOff added in v0.2.3

func (r ReceiptPendingRenewalInfos) IsAutoRenewStatusOff(productID string) bool

IsAutoRenewStatusOff confirms `auto_renew_status` is disabled for given product id.

func (ReceiptPendingRenewalInfos) IsAutoRenewStatusOn added in v0.2.3

func (r ReceiptPendingRenewalInfos) IsAutoRenewStatusOn(productID string) bool

IsAutoRenewStatusOn confirms `auto_renew_status` is enabled for given product 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

Jump to

Keyboard shortcuts

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