iap

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2025 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrExists   = errors.New("iap already exists")
	ErrNotFound = errors.New("iap not found")
)

Functions

This section is empty.

Types

type Product

type Product uint8
const (
	ProductUnknown Product = iota
	ProductCreateAccount
)

type Purchase

type Purchase struct {
	ReceiptID []byte
	Platform  commonpb.Platform
	User      *commonpb.UserId
	Product   Product
	State     State
	CreatedAt time.Time
}

func (*Purchase) Clone

func (p *Purchase) Clone() *Purchase

type Server

type Server struct {
	iappb.UnimplementedIapServer
	// contains filtered or unexported fields
}

func NewServer

func NewServer(
	log *zap.Logger,
	authz auth.Authorizer,
	accounts account.Store,
	iaps Store,
	appleVerifier Verifier,
	googleVerifier Verifier,
) *Server

func (*Server) OnPurchaseCompleted

todo: DB transaction for all calls todo: eventually we'll need to distinguish what was purchased

type State

type State uint8
const (
	StateUnknown State = iota
	StateWaitingForPayment
	StateWaitingForFulfillment
	StateFulfilled
)

type Store

type Store interface {
	CreatePurchase(ctx context.Context, purchase *Purchase) error
	GetPurchase(ctx context.Context, receiptId []byte) (*Purchase, error)
}

type Verifier

type Verifier interface {

	// VerifyReceipt takes a IAP receipt (for iOS/Android usually a
	// base64-encoded string, for memory a signed payload) and determines if it
	// is valid and has purchased the required feature.
	VerifyReceipt(ctx context.Context, receipt string) (bool, error)

	// GetReceiptIdentifier takes a IAP receipt and returns the identifier of the
	// purchased feature. This can be used to identify the receipt in the system.
	GetReceiptIdentifier(ctx context.Context, receipt string) ([]byte, error)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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