// client is a *dodopayments.Client, for example from// dodopayments.NewClient(option.WithEnvironmentTestMode()); ctx is a context.Context.client.Entitlements.New(ctx, dodopayments.EntitlementNewParams{ Name: dodopayments.F("Advanced Reports"), IntegrationType: dodopayments.F(dodopayments.EntitlementIntegrationTypeFeatureFlag), IntegrationConfig: dodopayments.F[dodopayments.IntegrationConfigUnionParam]( dodopayments.IntegrationConfigFeatureFlagConfigParam{ FeatureType: dodopayments.F(dodopayments.FeatureTypeBoolean), FeatureID: dodopayments.F("advanced_reports"), }, ),})
要构建客户拥有的功能集合,请列出其已交付的 feature flag grants。该 endpoint 会返回所有 entitlements 中每个 grant 对应的一行数据,您可以按 integration_type 和 status 进行筛选。这些示例使用通过 API 创建中的 client。
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",)# Iterating the page fetches every page of results.features = { grant.feature.feature_id: grant.metadata for grant in page if grant.feature}if "advanced_reports" in features: limit = features["advanced_reports"].get("monthly_report_limit")