-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathentitlements_example.php
More file actions
58 lines (48 loc) · 2.11 KB
/
entitlements_example.php
File metadata and controls
58 lines (48 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
require_once __DIR__ . '/../vendor/autoload.php';
use Kinde\KindeSDK\KindeClientSDK;
// Initialize the SDK
$kinde = new KindeClientSDK(
domain: 'https://your-domain.kinde.com',
clientId: 'your_client_id',
clientSecret: 'your_client_secret',
redirectUri: 'http://localhost:8000/callback'
);
try {
// First, authenticate the user (this would typically happen through the login flow)
// For this example, we assume the user is already authenticated
// Get all entitlements for the authenticated user
echo "Getting all entitlements...\n";
$entitlements = $kinde->getAllEntitlements();
echo "Found " . count($entitlements) . " entitlements:\n";
foreach ($entitlements as $entitlement) {
echo "- " . $entitlement->getFeatureName() . " (Key: " . $entitlement->getFeatureKey() . ")\n";
echo " Max Limit: " . $entitlement->getEntitlementLimitMax() . "\n";
echo " Min Limit: " . $entitlement->getEntitlementLimitMin() . "\n";
echo " Unit Amount: " . $entitlement->getUnitAmount() . "\n";
echo " Price Name: " . $entitlement->getPriceName() . "\n\n";
}
// Check if user has a specific entitlement
$featureKey = 'premium_features';
if ($kinde->hasEntitlement($featureKey)) {
echo "User has access to: " . $featureKey . "\n";
// Get the limit for this entitlement
$limit = $kinde->getEntitlementLimit($featureKey);
if ($limit !== null) {
echo "Limit for " . $featureKey . ": " . $limit . "\n";
}
} else {
echo "User does not have access to: " . $featureKey . "\n";
}
// Get a specific entitlement
$entitlement = $kinde->getEntitlement('basic_features');
if ($entitlement) {
echo "Found entitlement: " . $entitlement->getFeatureName() . "\n";
echo "Feature Key: " . $entitlement->getFeatureKey() . "\n";
echo "Max Limit: " . $entitlement->getEntitlementLimitMax() . "\n";
} else {
echo "Entitlement 'basic_features' not found\n";
}
} catch (Exception $e) {
echo "Error: " . $e->getMessage() . "\n";
}