Skip to content

Commit

Permalink
Adds stripe price tiers in the plan information
Browse files Browse the repository at this point in the history
  • Loading branch information
emmdim committed Nov 20, 2024
1 parent 7f4dffc commit b2ed73f
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 9 deletions.
22 changes: 21 additions & 1 deletion api/docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,16 @@ This request can be made only by organization admins.
"smsNotification":false
}
},
"censusSizeTiers": [
{
"flatAmount":9900,
"upTo":100
},
{
"flatAmount":79900,
"upTo":1500
}
],
...
]
}
Expand Down Expand Up @@ -882,7 +892,17 @@ This request can be made only by organization admins.
"personalization":false,
"emailReminder":true,
"smsNotification":false
}
},
"censusSizeTiers": [
{
"flatAmount":9900,
"upTo":100
},
{
"flatAmount":79900,
"upTo":1500
}
],
}
```

Expand Down
22 changes: 14 additions & 8 deletions db/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,20 @@ type Features struct {
}

type Plan struct {
ID uint64 `json:"id" bson:"_id"`
Name string `json:"name" bson:"name"`
StripeID string `json:"stripeID" bson:"stripeID"`
StartingPrice int64 `json:"startingPrice" bson:"startingPrice"`
Default bool `json:"default" bson:"default"`
Organization PlanLimits `json:"organization" bson:"organization"`
VotingTypes VotingTypes `json:"votingTypes" bson:"votingTypes"`
Features Features `json:"features" bson:"features"`
ID uint64 `json:"id" bson:"_id"`
Name string `json:"name" bson:"name"`
StripeID string `json:"stripeID" bson:"stripeID"`
StartingPrice int64 `json:"startingPrice" bson:"startingPrice"`
Default bool `json:"default" bson:"default"`
Organization PlanLimits `json:"organization" bson:"organization"`
VotingTypes VotingTypes `json:"votingTypes" bson:"votingTypes"`
Features Features `json:"features" bson:"features"`
CensusSizeTiers []PlanTier `json:"censusSizeTiers" bson:"censusSizeTiers"`
}

type PlanTier struct {
Amount int64 `json:"Amount" bson:"Amount"`
UpTo int64 `json:"upTo" bson:"upTo"`
}

type OrganizationSubscription struct {
Expand Down
11 changes: 11 additions & 0 deletions stripe/stripe.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,16 @@ func (s *StripeClient) GetPlans() ([]*db.Plan, error) {
if len(price.Tiers) > 0 {
startingPrice = price.Tiers[0].FlatAmount
}
var tiers []db.PlanTier
for _, tier := range price.Tiers {
if tier.UpTo == 0 {
continue
}
tiers = append(tiers, db.PlanTier{
Amount: tier.FlatAmount,
UpTo: tier.UpTo,
})
}
plans = append(plans, &db.Plan{
ID: uint64(i),
Name: price.Nickname,
Expand All @@ -135,6 +145,7 @@ func (s *StripeClient) GetPlans() ([]*db.Plan, error) {
EmailReminder: featuresData["EmailReminder"],
SmsNotification: featuresData["SmsNotification"],
},
CensusSizeTiers: tiers,
})
}
}
Expand Down

0 comments on commit b2ed73f

Please sign in to comment.