PHP code example of impruthvi / cashier-entitlements
1. Go to this page and download the library: Download impruthvi/cashier-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/ */
impruthvi / cashier-entitlements example snippets
use Illuminate\Database\Eloquent\Relations\Relation;
use Impruthvi\CashierEntitlements\Billing\{PriceCatalog, PriceMapping};
use Laravel\Cashier\Cashier;
// boot(): merge with your application's existing morph map.
Cashier::useCustomerModel(Organization::class);
Relation::morphMap(['organization' => Organization::class]);
// register(): must match the configured Stripe account and mode.
$this->app->singleton(PriceCatalog::class, fn () => new PriceCatalog(
version: 'v1',
prices: [
'price_base' => new PriceMapping('base', ['projects' => 2, 'ai' => false]),
'price_pro' => new PriceMapping('pro', ['projects' => 10, 'ai' => true]),
],
providerContext: 'platform',
liveMode: false,
));
use Impruthvi\CashierEntitlements\Reconciliation\OwnerLocator;
use Impruthvi\CashierEntitlements\Resolution\LocalResolver;
$owner = app(OwnerLocator::class)->reference($organization);
$access = app(LocalResolver::class)->for($owner);
$access->can('ai'); // bool — boolean features only
$access->limit('projects'); // int; null is unlimited, zero is none
$access->usage('projects'); // int consumed in the current period
$access->remaining('projects'); // int, or null for unlimited
$access->all(); // the whole allowance map in one query