iap

package
v1.0.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	AppleUrlSandbox    = "https://sandbox.itunes.apple.com/verifyReceipt"
	AppleUrlProduction = "https://buy.itunes.apple.com/verifyReceipt"
)
View Source
const (
	AppleReceiptIsValid   = 0
	AppleReceiptIsSandbox = 21007
)
View Source
const (
	AppleSandboxEnv    = "Sandbox"
	AppleProductionEnv = "Production"
)
View Source
const (
	APPLE  string = "0"
	GOOGLE string = "1"
)

Variables

View Source
var (
	ErrPurchasesListInvalidCursor = errors.New("purchases list cursor invalid")
	ErrUnavailableTryAgain        = errors.New("apple IAP verification is currently unavailable")
	ErrFailedPrecondition         = errors.New("invalid Receipt")
	ErrPurchaseReceiptAlreadySeen = errors.New("Purchase Receipt Already Seen")
)
View Source
var (
	ErrNon200Apple = errors.New("non 200 response from apple")
)
View Source
var (
	ErrNon200ServiceGoogle = errors.New("non 200 response from Google service")
)

Functions

func ValidateReceiptGoogle

func ValidateReceiptGoogle(ctx context.Context, httpc *http.Client, clientEmail string, privateKey string, receipt string) (*ReceiptGoogleResponse, *ReceiptGoogle, []byte, error)

ValidateReceiptGoogle validate an IAP receipt with the Android Publisher API and the Google credentials.

func ValidateSubscriptionReceiptGoogle

func ValidateSubscriptionReceiptGoogle(ctx context.Context, httpc *http.Client, clientEmail string, privateKey string, receipt string) (*ReceiptSubscriptionGoogleResponse, *ReceiptGoogle, []byte, error)

ValidateSubscriptionReceiptGoogle validate an IAP receipt with subscription type

Types

type Environment

type Environment int32

Environment where the purchase took place

const (
	// Unknown environment.
	UNKNOWN Environment = 0
	// Sandbox /test environment.
	SANDBOX Environment = 1
	// Production environment.
	PRODUCTION Environment = 2
)

type IAPAppleConfig

type IAPAppleConfig struct {
	PrivateKey string `json:"private_key" usage:"Apple App Specific Shared Secret"`
}

type IAPGoogleConfig

type IAPGoogleConfig struct {
	ClientEmail string `json:"client_email" usage:"Google Service Account client email."`
	PrivateKey  string `json:"private_key" usage:"Google Service Account private key."`
}

type InApp

type InApp struct {
	OriginalTransactionID string               `json:"original_transaction_id"`
	TransactionId         string               `json:"transaction_id"` // Different than OriginalTransactionId if the user Auto-renews subscription or restores a purchase.
	ProductID             string               `json:"product_id"`
	ExpiresDateMs         string               `json:"expires_date_ms"` // Only returned for Subscription expiration or renewal date.
	PurchaseDateMs        string               `json:"purchase_date_ms"`
	CancellationDateMs    string               `json:"cancellation_date_ms"` // canceled a transaction This field is only present for refunded transactions
	CancellationReason    string               `json:"cancellation_reason"`  // reason for a refunded transaction Possible values: 1, 0
	PendingRenewalInfo    []PendingRenewalInfo `json:"pending_renewal_info"` // Only returned for app receipts that contain auto-renewable subscriptions.
}

type PendingRenewalInfo

type PendingRenewalInfo struct {
	AutoRenewStatus string `json:"auto_renew_status"` // Possible values: 1, 0
}

type Purchase

type Purchase struct {
	// contains filtered or unexported fields
}

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

type ReceiptGoogleResponse

type ReceiptGoogleResponse struct {
	AcknowledgementState int    `json:"acknowledgementState"`
	ConsumptionState     int    `json:"consumptionState"`
	DeveloperPayload     string `json:"developerPayload"`
	Kind                 string `json:"kind"`
	OrderId              string `json:"orderId"`
	PurchaseState        int    `json:"purchaseState"`
	PurchaseTimeMillis   string `json:"purchaseTimeMillis"`
	PurchaseType         int    `json:"purchaseType"`
	RegionCode           string `json:"regionCode"`
}

type ReceiptSubscriptionGoogleResponse

type ReceiptSubscriptionGoogleResponse struct {
	AcknowledgementState int    `json:"acknowledgementState"`
	DeveloperPayload     string `json:"developerPayload"`
	Kind                 string `json:"kind"`
	OrderId              string `json:"orderId"`
	PurchaseType         int    `json:"purchaseType"`
	// This field is only set if this purchase was not made using the standard in-app billing flow.
	// Possible values are: 0. Test (i.e. purchased from a license testing account) 1. Promo (i.e. purchased using a promo code)
	AutoRenewing                 bool   `json:"autoRenewing"`
	StartSubscriptionTimeMillis  int64  `json:"startTimeMillis,string,omitempty"`
	ExpirySubscriptionTimeMillis int64  `json:"expiryTimeMillis,string,omitempty"`
	LinkedPurchaseToken          string `json:"linkedPurchaseToken"`
	CancelReason                 int    `json:"cancelReason"`
	//0 User canceled the subscription
	//1 Subscription was canceled by the system, for example because of a billing problem
	//2 Subscription was replaced with a new subscription
	//3 Subscription was canceled by the developer
	UserCancellationTimeMillis string `json:"userCancellationTimeMillis"`
	// Only present if cancelReason is 0.
	PaymentState int `json:"paymentState"`
}

type ResponseReceipt

type ResponseReceipt struct {
	OriginalPurchaseDateMs string   `json:"original_purchase_date_ms"`
	InApp                  []*InApp `json:"in_app"`
}

type Store

type Store int32

Validation Provider

const (
	// Apple App Store
	APPLE_APP_STORE Store = 0
	// Google Play Store
	GOOGLE_PLAY_STORE Store = 1
)

type SubscriptionPurchase

type SubscriptionPurchase struct {
	Purchase
	AutoRenew   bool
	ExpiresTime time.Time
}

func PurchaseSubscriptionGoogle

func PurchaseSubscriptionGoogle(ctx context.Context, config IAPGoogleConfig, receipt string) (*SubscriptionPurchase, error)

func PurchasesSubscriptionApple

func PurchasesSubscriptionApple(ctx context.Context, config IAPAppleConfig, receipt string) (*SubscriptionPurchase, error)

type ValidateReceiptAppleResponse

type ValidateReceiptAppleResponse struct {
	IsRetryable bool             `json:"is-retryable"` // If true, must be retried later.
	Status      int              `json:"status"`
	Receipt     *ResponseReceipt `json:"receipt"`
	Environment string           `json:"environment"` // possible values: 'Sandbox', 'Production'.
}

func ValidateReceiptApple

func ValidateReceiptApple(ctx context.Context, httpc *http.Client, receipt, password string) (*ValidateReceiptAppleResponse, []byte, error)

ValidateReceiptApple this function will check against both the production and sandbox Apple URLs follow by Apple suggestion. return response struct and raw data. Do what ever you want.

func ValidateSubscriptionReceiptApple

func ValidateSubscriptionReceiptApple(ctx context.Context, httpc *http.Client, receipt, password string) (*ValidateReceiptAppleResponse, []byte, error)

ValidateSubscriptionReceiptApple this function for purchase subscription will check against both the production and sandbox Apple URLs follow by Apple suggestion. required password return response struct and raw data. Do what ever you want.

Jump to

Keyboard shortcuts

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