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)
| 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). |
| 352 | func (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. |
no test coverage detected