Download the PHP package petersowah/laravel-cashier-revenue-cat without Composer
On this page you can find all versions of the php package petersowah/laravel-cashier-revenue-cat. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download petersowah/laravel-cashier-revenue-cat
More information about petersowah/laravel-cashier-revenue-cat
Files in petersowah/laravel-cashier-revenue-cat
Package laravel-cashier-revenue-cat
Short Description RevenueCat integration for Laravel to manage iOS and Android app subscriptions
License MIT
Homepage https://github.com/petersowah/laravel-cashier-revenue-cat
Informations about the package laravel-cashier-revenue-cat
Laravel Cashier RevenueCat
A Laravel Cashier driver for RevenueCat, providing seamless integration with RevenueCat's subscription management platform for iOS and Android apps.
Features
- Easy integration with RevenueCat's API V2
- Webhook handling for subscription events
- Support for both iOS and Android subscriptions
- Secure webhook signature verification
- Event-driven architecture for subscription management
- Support for entitlements management
- Support for non-subscription purchases
- Comprehensive subscription management
- Create and manage RevenueCat customers
- Check subscription status
- Get active subscriptions
- Access subscription history
- Handle subscription events
- Entitlements management
- Get all entitlements
- Check specific entitlements
- Verify entitlement status
- Offerings and products management
- Get current offering
- List available offerings
- Access product information
- Automatic retry mechanism for failed API calls
- Caching support for API responses
- Comprehensive logging and error handling
Installation
You can install the package via composer:
Route Registration
The package automatically registers its routes when installed. However, if you're experiencing issues with routes not being registered, follow these steps:
-
Verify the service provider is registered in
config/app.php
: -
Clear your route cache:
- Verify the routes are registered:
You should see the webhook route listed with the name cashier-revenue-cat.webhook
.
Common Route Registration Issues
-
Routes Not Showing Up
- Make sure you've published the package's configuration
- Verify the service provider is registered in
config/app.php
- Check that your
.env
file has the required configuration
-
Webhook Route Not Accessible
- Verify the
REVENUECAT_WEBHOOK_ENDPOINT
is set correctly in your.env
- Check that the route group (
web
orapi
) is appropriate for your use case - Ensure your web server is configured to handle the route
- Verify the
- CSRF Token Issues
- The webhook route is automatically excluded from CSRF protection
- If you're still getting CSRF errors, verify the route is registered in the correct middleware group
Configuration
You can publish the config file with:
This will create a config/cashier-revenue-cat.php
file in your config folder.
Environment Variables
Add these variables to your .env
file:
Available Configuration Options
The package configuration is organized into several sections:
API Configuration
Webhook Configuration
Cache Configuration
Logging Configuration
Error Handling Configuration
Other Configuration
Webhook Security
The package includes several security features for webhooks:
- Signature Verification: All webhooks are verified using the
X-RevenueCat-Signature
header - Rate Limiting: By default, webhooks are limited to 60 requests per minute per IP
- IP Whitelisting: You can restrict webhook access to specific IP addresses
- CSRF Protection: Webhook routes are automatically excluded from CSRF protection
To configure webhook security:
Custom Webhook Endpoint
To use a custom webhook endpoint, set the REVENUECAT_WEBHOOK_ENDPOINT
environment variable:
The webhook URL will be: https://your-domain.com/api/revenuecat/webhook
Route Group Configuration
By default, the webhook route is registered in the web
middleware group. You can change this by setting the REVENUECAT_ROUTE_GROUP
environment variable:
This affects which middleware group the webhook route belongs to. The default is web
.
For example, if you set REVENUECAT_ROUTE_GROUP=api
, the webhook route will be registered as:
If you set REVENUECAT_ROUTE_GROUP=web
, the webhook route will be registered as:
The route name will always be cashier-revenue-cat.webhook
regardless of the group.
Mobile App Integration
iOS Integration
-
First, set up RevenueCat in your iOS app by adding the RevenueCat SDK:
- Handle purchases in your iOS app:
Android Integration
-
Add the RevenueCat SDK to your Android app:
- Handle purchases in your Android app:
Flutter Integration
-
Add the RevenueCat Flutter SDK to your
pubspec.yaml
: - Initialize RevenueCat in your Flutter app:
Laravel Backend Usage
Managing Subscribers
Handling Webhooks
-
The package automatically registers a webhook route at
/webhook/revenuecat
. You can configure the endpoint in your.env
file: -
Set up the webhook URL in your RevenueCat dashboard:
- Log in to your RevenueCat dashboard at https://app.revenuecat.com
- Go to Project Settings (gear icon) in the left sidebar
- Click on "Webhooks" in the settings menu
- Click "Add Webhook"
- Enter your webhook URL (e.g.,
https://your-app.com/webhook/revenuecat
) - Select the events you want to receive
- RevenueCat will generate a webhook secret for you
-
Configure your webhook secret in your
.env
file: -
You have two options for handling webhooks:
a. Use the default webhook handler (no configuration needed): The package will automatically use the built-in webhook handler.
b. Create your own webhook handler:
This will:
- Publish the webhook handler to
app/Listeners/HandleRevenueCatWebhook.php
- Publish the webhook controller to
app/Http/Controllers/RevenueCat/WebhookController.php
- Update the configuration to use your published controller
- Update the route registration to use your published controller
Your custom handler should implement the following interface:
Note: The webhook handler configuration must include both the class name and the method name (e.g.,
Class@method
). The method name is required and must be specified after the@
symbol. The method should accept aRequest
object and return aResponse
.After publishing, the webhook route will use your published controller at
App\Http\Controllers\RevenueCat\WebhookController
, which will dispatch the webhook event to your configured handler. You can customize both the controller and handler to implement your specific webhook handling logic. - Publish the webhook handler to
-
The package automatically handles the following webhook events:
- INITIAL_PURCHASE
- RENEWAL
- CANCELLATION
- NON_RENEWING_PURCHASE
- SUBSCRIPTION_PAUSED
- SUBSCRIPTION_RESUMED
- PRODUCT_CHANGE
- BILLING_ISSUE
- REFUND
- SUBSCRIPTION_PERIOD_CHANGED
-
Listen to webhook events in your application:
- The default webhook handler includes comprehensive event handling:
The webhook endpoint is automatically secured with signature verification using the X-RevenueCat-Signature
header. The package will verify the signature using your configured webhook secret before processing any webhook events.
Webhook Event Handling
The package dispatches a WebhookReceived
event for each webhook request. You can listen to this event in your application by:
-
Registering the event listener in your
EventServiceProvider
: -
Creating a listener to handle the event:
- Implementing the event handling logic in your listener:
The event payload contains all the information from the RevenueCat webhook, including:
- Event type
- Event ID
- Timestamp
- Subscriber information
- Product information
- Entitlements
- And more
You can access this information in your event listener to implement your business logic.
Webhook Event Types
The package handles the following webhook event types:
-
INITIAL_PURCHASE
- Triggered when a user makes their first purchase
- Contains initial subscription details and user information
-
RENEWAL
- Triggered when a subscription is renewed
- Contains updated subscription period information
-
CANCELLATION
- Triggered when a subscription is cancelled
- Contains cancellation details and effective date
-
NON_RENEWING_PURCHASE
- Triggered when a subscription is set to not renew
- Contains information about when the subscription will end
-
SUBSCRIPTION_PAUSED
- Triggered when a subscription is paused
- Contains pause duration and reason
-
SUBSCRIPTION_RESUMED
- Triggered when a paused subscription is resumed
- Contains updated subscription status
-
PRODUCT_CHANGE
- Triggered when a subscription product is changed
- Contains old and new product information
-
BILLING_ISSUE
- Triggered when there's a billing problem
- Contains error details and resolution steps
-
REFUND
- Triggered when a purchase is refunded
- Contains refund amount and reason
- SUBSCRIPTION_PERIOD_CHANGED
- Triggered when a subscription period is modified
- Contains old and new period information
Each event type provides specific data in the payload that you can use to implement your business logic. The event listener example above shows how to handle each type of event.
Database Tables
The package creates the following database tables:
customers
: Stores customer informationsubscriptions
: Stores subscription information
Models
The package provides the following models:
Customer
: Represents a customerSubscription
: Represents a subscription
Usage
To use the package, add the Billable
trait to your User model:
This will give your User model access to the following relationships:
customer()
: Get the customer associated with the usersubscriptions()
: Get the subscriptions associated with the user
Configuration
The package can be configured by publishing the configuration file:
This will create a config/cashier-revenue-cat.php
file where you can configure:
- API Key
- Project ID
- Webhook Secret
- Webhook Endpoint
- Webhook Handler
Webhooks
The package provides webhook handling for RevenueCat events. To use webhooks:
- Configure your webhook endpoint in RevenueCat to point to your application's webhook URL
- Set the webhook secret in your configuration
- The package will automatically handle incoming webhooks and dispatch events
Events
The package dispatches the following events:
WebhookReceived
: Dispatched when a webhook is received from RevenueCat
Testing
The package provides a test case that you can use in your tests:
This test case provides:
- Database configuration for testing
- RevenueCat configuration for testing
- Helper methods for creating test data
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-cashier-revenue-cat with dependencies
ext-json Version *
guzzlehttp/guzzle Version ^7.8
illuminate/contracts Version ^10.0||^11.0||^12.0
illuminate/database Version ^10.0||^11.0||^12.0
illuminate/http Version ^10.0||^11.0||^12.0
illuminate/support Version ^10.0||^11.0||^12.0
laravel/framework Version ^10.0||^11.0||^12.0
moneyphp/money Version ^4.0
nesbot/carbon Version ^2.67||^3.0
spatie/laravel-package-tools Version ^1.16
symfony/http-kernel Version ^6.2||^7.0