PHP code example of vipertecpro / mobile-entitlements
1. Go to this page and download the library: Download vipertecpro/mobile-entitlements library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
vipertecpro / mobile-entitlements example snippets
if ($request->user()->hasEntitlement('pro')) {
// ...
}
use Vipertecpro\MobileEntitlements\Concerns\HasEntitlements;
class User extends Authenticatable
{
use HasEntitlements;
}
'entitlements' => [
'pro' => ['com.example.pro.monthly', 'com.example.pro.yearly', 'pro_monthly', 'pro_yearly'],
'lifetime' => ['com.example.lifetime', 'lifetime_unlock'],
],
// Google Play does not say whether a one-time product is a consumable, so list them here.
'consumables' => ['coins_100'],
$user->hasEntitlement('pro'); // bool
$user->entitlement('pro'); // ?Entitlement, the active one with the latest expiry
$user->entitlements; // every row
$user->activeEntitlements()->get(); // rows that grant access right now
Route::middleware(['auth:sanctum', 'entitled:pro'])->group(function () {
// 402 JSON when the user lacks the entitlement
});
Route::middleware('entitled:pro,lifetime')->get(...); // any of several keys
use Vipertecpro\MobileEntitlements\Enums\Store;
use Vipertecpro\MobileEntitlements\Facades\MobileEntitlements;
MobileEntitlements::verify(Store::AppStore, $jws); // VerifiedPurchase, nothing stored
MobileEntitlements::grantFromToken($user, Store::GooglePlay, $token);
MobileEntitlements::reconcile($user);