add field for customer whether they are pro or not
This commit is contained in:
@@ -34,6 +34,18 @@ type MetricResponse struct {
|
|||||||
} `json:"metrics"`
|
} `json:"metrics"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type SubscriptionResponse struct {
|
||||||
|
Items []struct {
|
||||||
|
Status string `json:"status"`
|
||||||
|
GivesAccess bool `json:"gives_access"`
|
||||||
|
Entitlements struct {
|
||||||
|
Items []struct {
|
||||||
|
LookupKey string `json:"lookup_key"`
|
||||||
|
} `json:"items"`
|
||||||
|
} `json:"entitlements"`
|
||||||
|
} `json:"items"`
|
||||||
|
}
|
||||||
|
|
||||||
func getRevenue() string {
|
func getRevenue() string {
|
||||||
client := &http.Client{}
|
client := &http.Client{}
|
||||||
|
|
||||||
@@ -120,6 +132,58 @@ func getRevenue() string {
|
|||||||
// return result.String()
|
// return result.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func hasProSubscription(customerEmail string) bool {
|
||||||
|
client := &http.Client{}
|
||||||
|
|
||||||
|
url := fmt.Sprintf("https://api.revenuecat.com/v2/projects/proj5b2f7356/customers/%s/subscriptions", customerEmail)
|
||||||
|
req, err := http.NewRequest("GET", url, nil)
|
||||||
|
if err != nil {
|
||||||
|
logrus.Errorf("Error creating subscription request for %s: %v", customerEmail, err)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add authorization header
|
||||||
|
req.Header.Add("Authorization", "Bearer sk_wxmjNCLtnDSUPmSXlbEWyuqkpTVTi")
|
||||||
|
|
||||||
|
response, err := client.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
logrus.Errorf("Error fetching subscriptions for %s: %v", customerEmail, err)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
defer response.Body.Close()
|
||||||
|
|
||||||
|
// If customer not found or no subscriptions, return false
|
||||||
|
if response.StatusCode != 200 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
body, err := io.ReadAll(response.Body)
|
||||||
|
if err != nil {
|
||||||
|
logrus.Errorf("Error reading subscription response for %s: %v", customerEmail, err)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
var subResp SubscriptionResponse
|
||||||
|
err = json.Unmarshal(body, &subResp)
|
||||||
|
if err != nil {
|
||||||
|
logrus.Errorf("Error parsing subscription JSON for %s: %v", customerEmail, err)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if any subscription is active and has Pro entitlement
|
||||||
|
for _, sub := range subResp.Items {
|
||||||
|
if sub.Status == "active" && sub.GivesAccess {
|
||||||
|
for _, ent := range sub.Entitlements.Items {
|
||||||
|
if ent.LookupKey == "Pro" {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
titleStyle = lipgloss.NewStyle().
|
titleStyle = lipgloss.NewStyle().
|
||||||
Bold(true).
|
Bold(true).
|
||||||
@@ -193,6 +257,7 @@ type HumanData struct {
|
|||||||
DisplayName string
|
DisplayName string
|
||||||
JoinedAt time.Time
|
JoinedAt time.Time
|
||||||
KeypadConfiguration string
|
KeypadConfiguration string
|
||||||
|
HasProSubscription bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type model struct {
|
type model struct {
|
||||||
@@ -358,6 +423,17 @@ func (m model) renderDetails() string {
|
|||||||
joinedFormatted := human.JoinedAt.Format("Jan 2, 2006 at 3:04 PM")
|
joinedFormatted := human.JoinedAt.Format("Jan 2, 2006 at 3:04 PM")
|
||||||
b.WriteString(detailValueStyle.Render(fmt.Sprintf("%s (%s)", joinedFormatted, timeAgo)) + "\n\n")
|
b.WriteString(detailValueStyle.Render(fmt.Sprintf("%s (%s)", joinedFormatted, timeAgo)) + "\n\n")
|
||||||
|
|
||||||
|
// Pro Subscription Status
|
||||||
|
b.WriteString(detailLabelStyle.Render("Pro Subscription: "))
|
||||||
|
if human.HasProSubscription {
|
||||||
|
proStyle := lipgloss.NewStyle().
|
||||||
|
Foreground(lipgloss.Color("#00FF00")).
|
||||||
|
Bold(true)
|
||||||
|
b.WriteString(proStyle.Render("✓ Active") + "\n\n")
|
||||||
|
} else {
|
||||||
|
b.WriteString(dimItemStyle.Render("✗ None") + "\n\n")
|
||||||
|
}
|
||||||
|
|
||||||
// Keypad Configuration
|
// Keypad Configuration
|
||||||
if human.KeypadConfiguration != "" {
|
if human.KeypadConfiguration != "" {
|
||||||
b.WriteString(detailLabelStyle.Render("Keypad Configuration:") + "\n")
|
b.WriteString(detailLabelStyle.Render("Keypad Configuration:") + "\n")
|
||||||
@@ -456,11 +532,16 @@ func getHumansData() []*HumanData {
|
|||||||
keypadConfiguration = keypad.GetYamlConfig()
|
keypadConfiguration = keypad.GetYamlConfig()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if customer has pro subscription
|
||||||
|
hasPro := hasProSubscription(human.GetEmail())
|
||||||
|
|
||||||
humansData = append(humansData, &HumanData{
|
humansData = append(humansData, &HumanData{
|
||||||
Email: human.GetEmail(),
|
Email: human.GetEmail(),
|
||||||
DisplayName: human.GetDisplayName(),
|
DisplayName: human.GetDisplayName(),
|
||||||
JoinedAt: human.GetJoinedAt().AsTime(),
|
JoinedAt: human.GetJoinedAt().AsTime(),
|
||||||
KeypadConfiguration: keypadConfiguration,
|
KeypadConfiguration: keypadConfiguration,
|
||||||
|
HasProSubscription: hasPro,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user