boldlinestudios/laravel-revenuecat-api
最新稳定版本:v0.1.2
Composer 安装命令:
composer require boldlinestudios/laravel-revenuecat-api
包简介
A package for Laravel backends to integrate with RevenueCat API v2 via typed methods and structured data objects.
README 文档
README
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:
- Apps
- Customers
- Entitlements
- Invoices
- Offerings
- Packages
- Paywalls
- Products
- Projects
- Purchases
- Subscriptions
Response and Data Handling
- Most methods return data objects (
AppData,CustomerData, etc.). - List endpoints return a
ListPage<T>(ListPage<T>) wrapper for pagination.
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.
统计信息
- 总下载量: 36
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-09-11