MCPcopy Index your code
hub / github.com/rilldata/rill / getSubscriptionAndUpdateOrg

Method getSubscriptionAndUpdateOrg

admin/server/billing.go:1249–1296  ·  view source on GitHub ↗
(ctx context.Context, org *database.Organization)

Source from the content-addressed store, hash-verified

1247}
1248
1249func (s *Server) getSubscriptionAndUpdateOrg(ctx context.Context, org *database.Organization) (*billing.Subscription, *database.Organization, error) {
1250 sub, err := s.admin.Biller.GetActiveSubscription(ctx, org.BillingCustomerID)
1251 if err != nil && !errors.Is(err, billing.ErrNotFound) {
1252 return nil, nil, err
1253 }
1254
1255 var planDisplayName string
1256 var planName string
1257 if sub == nil {
1258 planDisplayName = ""
1259 planName = ""
1260 } else {
1261 planDisplayName = sub.Plan.DisplayName
1262 planName = sub.Plan.Name
1263 }
1264
1265 // update the cached plan
1266 if org.BillingPlanName == nil || *org.BillingPlanName != planName {
1267 org, err = s.admin.DB.UpdateOrganization(ctx, org.ID, &database.UpdateOrganizationOptions{
1268 Name: org.Name,
1269 DisplayName: org.DisplayName,
1270 Description: org.Description,
1271 LogoAssetID: org.LogoAssetID,
1272 LogoDarkAssetID: org.LogoDarkAssetID,
1273 FaviconAssetID: org.FaviconAssetID,
1274 ThumbnailAssetID: org.ThumbnailAssetID,
1275 CustomDomain: org.CustomDomain,
1276 DefaultProjectRoleID: org.DefaultProjectRoleID,
1277 QuotaProjects: org.QuotaProjects,
1278 QuotaDeployments: org.QuotaDeployments,
1279 QuotaSlotsTotal: org.QuotaSlotsTotal,
1280 QuotaSlotsPerDeployment: org.QuotaSlotsPerDeployment,
1281 QuotaOutstandingInvites: org.QuotaOutstandingInvites,
1282 QuotaStorageLimitBytesPerDeployment: org.QuotaStorageLimitBytesPerDeployment,
1283 BillingCustomerID: org.BillingCustomerID,
1284 PaymentCustomerID: org.PaymentCustomerID,
1285 BillingEmail: org.BillingEmail,
1286 BillingPlanName: &planName,
1287 BillingPlanDisplayName: &planDisplayName,
1288 CreatedByUserID: org.CreatedByUserID,
1289 })
1290 if err != nil {
1291 return nil, nil, err
1292 }
1293 }
1294
1295 return sub, org, nil
1296}
1297
1298func subscriptionToDTO(sub *billing.Subscription) *adminv1.Subscription {
1299 return &adminv1.Subscription{

Callers 2

GetOrganizationMethod · 0.95

Calls 2

GetActiveSubscriptionMethod · 0.65
UpdateOrganizationMethod · 0.65

Tested by

no test coverage detected