PHP code example of boldlinestudios / laravel-revenuecat-api

1. Go to this page and download the library: Download boldlinestudios/laravel-revenuecat-api 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/ */

    

boldlinestudios / laravel-revenuecat-api example snippets


use BoldLineStudios\RevenueCatApi\Facades\RevenueCat;

$subscription = RevenueCat::getSubscription('sub1ab2c3d4e5');

echo $subscription->getCustomerId();    // "19b8de26-77c1-49f1-aa18-019a391603e2"
echo $subscription->getProductId();     // "prod_1ab2c3d4e5"
echo $subscription->givesAccess();      // true

use BoldLineStudios\RevenueCatApi\Facades\RevenueCat;

$customer = RevenueCat::customers()->get('customer_id'); // CustomerData
$customers = RevenueCat::customers()->all(25); // ListPage<CustomerData>

foreach ($customers->items() as $c) { /* $c is CustomerData */ }

use BoldLineStudios\RevenueCatApi\Facades\RevenueCat;

$entitlement = RevenueCat::getEntitlement('entitlement_id'); // EntitlementData
$entitlements = RevenueCat::listEntitlements(10); // ListPage<EntitlementData>
$newEntitlement = RevenueCat::createEntitlement('premium', 'Premium access to all features'); // EntitlementData

$product = RevenueCat::getProduct('prod_123');

echo $product->getId();
echo $product->getType();

return $product->toArray();

// Paginate through all customers
$allCustomers = [];
$cursor = null;
$pageNumber = 1;

do {
    // Get current page (20 customers per page)
    $page = RevenueCat::listCustomers(20, $cursor);

    echo "Page {$pageNumber}: " . count($page->items()) . " customers\n";

    // Process customers on this page
    foreach ($page->items() as $customer) {
        echo $customer->getId();
        echo $customer->getLastSeenPlatform();
        $allCustomers[] = $customer;  // Collect all customers
    }

    // See [CustomerData](DATA.md#customerdata) for all available methods

    // Get cursor for next page
    $cursor = $page->nextCursor();
    $pageNumber++;

} while ($cursor); // Continue until no more pages

echo "Total customers found: " . count($allCustomers);



// Custom page size and starting point
$page = RevenueCat::listCustomers(100, 'cursor_123');


bash
php artisan vendor:publish --tag=revenuecat-api-config