iap

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2025 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CreateAccountProductID     = "com.flipcash.iap.createAccount"
	CreateAccountBonusGoogleID = "com.flipcash.iap.createAccountWithWelcomeBonus"
	CreateAccountBonusAppleID  = "com.flipcash.iap.createAccountBonus"
)

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
	ProductCreateAccountBonusGoogle
	ProductCreateAccountBonusApple
)

type Purchase

type Purchase struct {
	ReceiptID       []byte
	Platform        commonpb.Platform
	User            *commonpb.UserId
	Product         Product
	PaymentAmount   float64
	PaymentCurrency string
	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

type State

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

type Store

type Store interface {
	CreatePurchase(ctx context.Context, purchase *Purchase) error
	GetPurchaseByID(ctx context.Context, receiptID []byte) (*Purchase, error)
	GetPurchasesByUserAndProduct(ctx context.Context, userID *commonpb.UserId, product Product) ([]*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, product 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