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 59d299f commit cdcd309
Showing 1 changed file with 4 additions and 21 deletions.
25 changes: 4 additions & 21 deletions lib/revenuecat/revenuecat.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ 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 @@ -72,10 +71,10 @@ const (
type StoreType string

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

// https://www.revenuecat.com/reference/subscribers
Expand All @@ -87,19 +86,3 @@ 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 cdcd309

Please sign in to comment.