Skip to content

Commit

Permalink
🔄 Sync from monorepo
Browse files Browse the repository at this point in the history
  • Loading branch information
mojo-machine[bot] committed May 7, 2024
1 parent cdcd309 commit ee45524
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions lib/revenuecat/revenuecat.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type Subscriber struct {
Entitlements map[string]Entitlement `json:"entitlements"`
Subscriptions map[string]Subscription `json:"subscriptions"`
NonSubscriptions map[string][]NonSubscription `json:"non_subscriptions"`
ManagementURL *string `json:"management_url"`
}

type Entitlement struct {
Expand Down Expand Up @@ -71,10 +72,10 @@ const (
type StoreType string

const (
StoreTypeAppStore StoreType = "app_store"
StoreTypePlay StoreType = "play_store"
StoreTypeStripe StoreType = "stripe"
StoreTypePromo StoreType = "promotional"
StoreTypeAppStore StoreType = "app_store"
StoreTypePlayStore StoreType = "play_store"
StoreTypeStripe StoreType = "stripe"
StoreTypePromotional StoreType = "promotional"
)

// https://www.revenuecat.com/reference/subscribers
Expand All @@ -86,3 +87,19 @@ func (c *Client) GetOrCreateSubscriberInfo(ctx context.Context, appUserID string
path := fmt.Sprintf("/subscribers/%s", escapedAppUserID)
return res, c.client.Do(ctx, "GET", path, nil, nil, &res)
}

func (s *Subscriber) ActiveSubscriptionCount() int {
activeNonSubCount := len(s.NonSubscriptions) // always active
activeSubCount := 0
now := time.Now()

for _, e := range s.Entitlements {
if e.ExpiresDate.Before(now) {
continue
}

activeSubCount++
}

return activeNonSubCount + activeSubCount
}

0 comments on commit ee45524

Please sign in to comment.