doc.gno

2.19 Kb ยท 66 lines
 1// Package subscription provides a flexible system for managing both recurring and
 2// lifetime subscriptions in Gno applications. It enables developers to handle
 3// payment-based access control for services or products. The library supports
 4// both subscriptions requiring periodic payments (recurring) and one-time payments
 5// (lifetime). Subscriptions are tracked using an AVL tree for efficient management
 6// of subscription statuses.
 7//
 8// Usage:
 9//
10// Import the required sub-packages (`recurring` and/or `lifetime`) to manage specific
11// subscription types. The methods provided allow users to subscribe, check subscription
12// status, and manage payments.
13//
14// Recurring Subscription:
15//
16// Recurring subscriptions require periodic payments to maintain access.
17// Users pay to extend their access for a specific duration.
18//
19// Example:
20//
21//	// Create a recurring subscription requiring 100 ugnot every 30 days
22//	recSub := recurring.NewRecurringSubscription(time.Hour * 24 * 30, 100)
23//
24//	// Process payment for the recurring subscription
25//	recSub.Subscribe()
26//
27//	// Gift a recurring subscription to another user
28//	recSub.GiftSubscription(recipientAddress)
29//
30//	// Check if a user has a valid subscription
31//	recSub.HasValidSubscription(addr)
32//
33//	// Get the expiration date of the subscription
34//	recSub.GetExpiration(caller)
35//
36//	// Update the subscription amount to 200 ugnot
37//	recSub.UpdateAmount(200)
38//
39//	// Get the current subscription amount
40//	recSub.GetAmount()
41//
42// Lifetime Subscription:
43//
44// Lifetime subscriptions require a one-time payment for permanent access.
45// Once paid, users have indefinite access without further payments.
46//
47// Example:
48//
49//	// Create a lifetime subscription costing 500 ugnot
50//	lifeSub := lifetime.NewLifetimeSubscription(500)
51//
52//	// Process payment for lifetime access
53//	lifeSub.Subscribe()
54//
55//	// Gift a lifetime subscription to another user
56//	lifeSub.GiftSubscription(recipientAddress)
57//
58//	// Check if a user has a valid subscription
59//	lifeSub.HasValidSubscription(addr)
60//
61//	// Update the lifetime subscription amount to 1000 ugnot
62//	lifeSub.UpdateAmount(1000)
63//
64//	// Get the current lifetime subscription amount
65//	lifeSub.GetAmount()
66package subscription