// 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"), }, ),})
customer が持つ features の set を構築するには、配信済みの feature flag grants を一覧表示します。endpoint はすべての entitlements にまたがる grant ごとに 1 行を返し、integration_type と status で filter できます。これらの examples では、Create via 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")