Documentation
¶
Overview ¶
Package purchase sells in-app products through the platform store.
purchase.OnUpdate(app, func(t purchase.Transaction) { // before Run
if t.State == purchase.Purchased || t.State == purchase.Restored {
unlock(t.ProductID)
purchase.Finish(app, t)
}
})
ps, invalid, err := purchase.Products(app, "pro", "coins100")
t, err := purchase.Buy(app, "pro")
iOS: StoreKit (SKProductsRequest and SKPaymentQueue — the Objective-C API; StoreKit 2 is Swift-only). The transaction observer is installed at launch, so transactions left over from an earlier run (an interrupted purchase, Ask to Buy approvals, renewals) arrive as updates after Started. Purchased and restored transactions stay in the queue until Finish: deliver the content first. Failed transactions are finished automatically. Products must exist in App Store Connect (or a StoreKit configuration in Xcode); otherwise they come back as invalid.
Android: Google Play Billing needs the Play Billing library, which Tango does not bundle (the host has no third-party dependencies). Every call returns ErrUnsupported; see docs/mobile.md ("应用内购买") for wiring it in.
Calls that wait for the store block; on Android call them from a goroutine (see docs/mobile.md). Desktop: ErrUnsupported.
Index ¶
Constants ¶
const ( Consumable = platform.ProductConsumable NonConsumable = platform.ProductNonConsumable Subscription = platform.ProductSubscription Purchasing = platform.TxPurchasing Purchased = platform.TxPurchased Failed = platform.TxFailed Restored = platform.TxRestored Deferred = platform.TxDeferred )
Variables ¶
var ( ErrUnsupported = platform.ErrUnsupported ErrCanceled = platform.ErrCanceled ErrNotAvailable = platform.ErrNotAvailable // payments disabled (parental controls, MDM) ErrNotFound = platform.ErrNotFound // unknown product / no receipt )
Functions ¶
func CanMakePayments ¶
CanMakePayments reports whether the user may buy (false when restricted or unsupported).
func Finish ¶
func Finish(a *tango.App, t Transaction) error
Finish tells the store the app delivered t's content. Until then the store reports t again on every launch.
func OnUpdate ¶
func OnUpdate(a *tango.App, fn func(Transaction))
OnUpdate calls fn on the main thread for every transaction update: the app's own purchases (each state), restores, and transactions the store delivers by itself. Register it before Run. Several functions may be registered; each sees every update. It does nothing where the backend has no store.
Types ¶
type ProductKind ¶
type ProductKind = platform.ProductKind
type State ¶
type State = platform.TransactionState
type Transaction ¶
type Transaction = platform.Transaction
func Buy ¶
func Buy(a *tango.App, productID string) (Transaction, error)
Buy purchases one unit of a product returned by Products and waits for the outcome: Purchased, or Deferred (awaiting approval; the final state arrives through OnUpdate). ErrCanceled when the user canceled.
func BuyQuantity ¶
BuyQuantity is Buy for n units of a consumable.