MCPcopy Create free account
hub / github.com/bytebase/bytebase / updateLicense

Method updateLicense

backend/api/stripe/webhook.go:352–378  ·  view source on GitHub ↗

updateLicense generates a license JWT from the subscription payload and stores it. For non-ACTIVE subscriptions, stores an empty license (reverts to FREE plan).

(ctx context.Context, workspace string, payload *storepb.SubscriptionPayload)

Source from the content-addressed store, hash-verified

350// updateLicense generates a license JWT from the subscription payload and stores it.
351// For non-ACTIVE subscriptions, stores an empty license (reverts to FREE plan).
352func (h *WebhookHandler) updateLicense(ctx context.Context, workspace string, payload *storepb.SubscriptionPayload) error {
353 var license string
354
355 if payload.Status == storepb.SubscriptionPayload_ACTIVE {
356 var expiresAt time.Time
357 if payload.ExpiresAt != nil {
358 // Add 24h grace period to the license to avoid service disruption
359 // from billing cycle delays. The subscription stores the real Stripe
360 // expiry; only the license JWT gets the extended time.
361 expiresAt = payload.ExpiresAt.AsTime().Add(24 * time.Hour)
362 }
363
364 var err error
365 license, err = h.licenseService.CreateLicense(&enterprise.LicenseParams{
366 Plan: payload.Plan.String(),
367 Seats: int(payload.Seat),
368 Instances: int(payload.InstanceCount),
369 WorkspaceID: workspace,
370 ExpiresAt: expiresAt,
371 })
372 if err != nil {
373 return errors.Wrap(err, "failed to create license JWT")
374 }
375 }
376
377 return h.licenseService.StoreLicense(ctx, workspace, license)
378}
379
380// buildPayloadFromMetadata constructs a SubscriptionPayload from Stripe metadata.
381// Returns error if any required field is missing or invalid.

Callers 2

handleInvoicePaidMethod · 0.95

Calls 3

CreateLicenseMethod · 0.80
StoreLicenseMethod · 0.80
StringMethod · 0.65

Tested by

no test coverage detected