列出客户交付的功能标志授权,并构建已启用功能集。终端返回每个授权跨所有权限的一行,支持按 integration_type 和 status 筛选。
const features = new Map<string, Record<string, unknown>>();for await (const grant of client.customers.listEntitlementGrants('cus_abc123', { integration_type: 'feature_flag', status: 'Delivered',})) { if (grant.feature) { features.set(grant.feature.feature_id, grant.metadata ?? {}); }}if (features.has('advanced_reports')) { const limit = features.get('advanced_reports')?.monthly_report_limit; // unlock the dashboard, enforce the limit}
page = client.customers.list_entitlement_grants( customer_id="cus_abc123", integration_type="feature_flag", status="Delivered",)features = { grant.feature.feature_id: grant.metadata for grant in page.items if grant.feature}if "advanced_reports" in features: limit = features["advanced_reports"].get("monthly_report_limit")
page, _ := client.Customers.ListEntitlementGrants( ctx, "cus_abc123", dodopayments.CustomerListEntitlementGrantsParams{ IntegrationType: dodopayments.F("feature_flag"), Status: dodopayments.F("Delivered"), },)features := map[string]bool{}for _, grant := range page.Items { if grant.Feature.FeatureID != "" { features[grant.Feature.FeatureID] = true }}
feature 负载仅在 feature_flag 授权上填充;对于每种其他集成类型,它为 null。完整响应格式请参见 列出客户授权 API 参考。
在每个请求上检查 API 会增加热路径的延迟。使用短 TTL(分钟而非小时)为每个客户缓存功能集,并在授权变更状态时从您的 webhook 处理程序中使缓存无效 —— 这种结合保持检查快速,并使撤销接近于即时。