boldlinestudios/laravel-revenuecat-api

A package for Laravel backends to integrate with RevenueCat API v2 via typed methods and structured data objects.

Installs: 36

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/boldlinestudios/laravel-revenuecat-api

v0.1.2 2025-12-12 17:38 UTC

This package is not auto-updated.

Last update: 2026-01-09 18:07:33 UTC


README

License Latest Version on Packagist

Laravel RevenueCat API

A Laravel package for the RevenueCat API v2, providing typed methods and structured data objects.

Note: This is not an official package of RevenueCat or Laravel.

Quick Example

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

For the full catalog of examples with code, see ENDPOINTS.md. For a complete reference of all API response data structures, see DATA.md.

Installation

You can install the package via composer:

composer require boldlinestudios/laravel-revenuecat-api

Requirements

  • PHP 8.2+
  • Laravel 11+

Configuration

Publish the configuration file:

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

Add the following environment variables to your .env file:

REVENUECAT_API_KEY=your_api_key_here
REVENUECAT_PROJECT_ID=your_project_id
REVENUECAT_BASE_URL=https://api.revenuecat.com/v2
REVENUECAT_TIMEOUT=30

Usage

You can call methods in two ways. Both return the same results, so use whichever feels clearer.

1) Endpoint-style

Organized by resource, similar to the REST API.

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 */ }

2) Convenience-style

Direct shortcut methods for common operations.

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

Endpoints

Available endpoints with full documentation and examples:

Response and Data Handling

See the full data object catalog DATA.md.

Data Objects

Data objects expose typed getters and a toArray() method:

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

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

return $product->toArray();

See ProductData for all available methods.

ListPage & Pagination

See ListPage<T> documentation in DATA.md.

List methods return a ListPage<T> that handles pagination automatically:

// 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);

Advanced Pagination

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

Error Handling

Non-2xx responses throw typed exceptions matching RevenueCat’s error model:

  • BadRequestException (400)
  • AuthenticationException (401)
  • AuthorizationException (403)
  • NotFoundException (404)
  • ConflictException (409)
  • ValidationException (422)
  • RateLimitException (429)
  • ServerErrorException (5xx)
  • ApiResponseException (fallback for other errors)

Testing

composer test

Linting

composer lint

Static Analysis

composer stan

Contributing

Please see CONTRIBUTING.md for details.

License

Released under the MIT license.