android

package
v0.170.0 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2026 License: AGPL-3.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ConfigEnvPrefix is the prefix applied to environment variables for configuring Android Billing.
	ConfigEnvPrefix = "ANDROID_"
)

Variables

View Source
var ErrClientNotStarted = errors.New("client not started")
View Source
var ErrNotFound = errors.New("not found")

Functions

func GetPriceID added in v0.168.0

func GetPriceID(frequency string) (string, error)

func HandleRTDN added in v0.166.0

func HandleRTDN(res http.ResponseWriter, req *http.Request)

HandleRTDN handles Real-Time Developer Notifications from Google Pub/Sub. Configure a Pub/Sub push subscription pointing at /billing/rtdn in Play Console.

https://developer.android.com/google/play/billing/rtdn-reference

func IsValidSKU added in v0.168.2

func IsValidSKU(sku string) bool

func StartClient added in v0.168.2

func StartClient(ctx context.Context) error

func TokenAlreadyGranted added in v0.168.2

func TokenAlreadyGranted(ctx context.Context, token string) (bool, error)

Types

type Config

type Config struct {
	// PackageName is what the app package is named in the Google Play Store.
	PackageName string            `koanf:"packagename" validate:"required"`
	PubSubEmail string            `koanf:"pubsubemail" validate:"required,email"`
	Pricing     map[string]string `koanf:"pricing"     validate:"required"`
}

Config is the configuration for Android Billing.

type Entitlement

type Entitlement struct {
	UserID        string
	SKU           string
	PurchaseToken string
	ExpiresAt     *time.Time // nil for lifetime/one-time purchases
	GrantedAt     time.Time
}

Entitlement represents a verified, active entitlement for a user.

func VerifyAndAcknowledgeSubscription

func VerifyAndAcknowledgeSubscription(
	ctx context.Context,
	user *models.User, sku, token string,
) (*Entitlement, error)

VerifyAndAcknowledgeSubscription verifies a subscription purchase.

type PurchaseState

type PurchaseState int

PurchaseState mirrors the Play API integer values.

const (
	PurchaseStatePurchased PurchaseState = 0
	PurchaseStateCancelled PurchaseState = 1
	PurchaseStatePending   PurchaseState = 2
)

type SubscriptionNotificationType added in v0.168.2

type SubscriptionNotificationType int
const (
	// SubscriptionRecovered indicates a subscription was recovered from account hold or resumed from pause.
	SubscriptionRecovered SubscriptionNotificationType = 1
	// SubscriptionRenewed indicates an active subscription was renewed.
	SubscriptionRenewed SubscriptionNotificationType = 2
	// SubscriptionCanceled indicates a subscription was either voluntarily or involuntarily cancelled. For voluntary
	// cancellation, sent when the user cancels.
	SubscriptionCanceled SubscriptionNotificationType = 3
	// SubscriptionPurchased indicates a new subscription was purchased.
	SubscriptionPurchased SubscriptionNotificationType = 4
	// SubscriptionOnHold indicates a subscription has entered account hold (if enabled).
	SubscriptionOnHold SubscriptionNotificationType = 5
	// SubscriptionInGracePeriod indicates a subscription has entered grace period (if enabled).
	SubscriptionInGracePeriod SubscriptionNotificationType = 6
	// SubscriptionRestarted indicates a user has restored their subscription from Play > Account > Subscriptions. The
	// subscription was canceled but had not expired yet when the user restores. For more information, see Restorations.
	SubscriptionRestarted SubscriptionNotificationType = 7
	// SubscriptionPaused indicates a subscription has been paused.
	SubscriptionPaused SubscriptionNotificationType = 10
	// SubscriptionRevoked indicates a subscription has been revoked from the user before the expiration time.
	SubscriptionRevoked SubscriptionNotificationType = 12
	// SubscriptionExpired indicates a subscription has expired.
	SubscriptionExpired SubscriptionNotificationType = 13
)

Jump to

Keyboard shortcuts

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