devmohy / creem-laravel
Official Laravel package for CREEM
Installs: 0
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/devmohy/creem-laravel
Requires
- php: ^8.1
- guzzlehttp/guzzle: ^7.8
- illuminate/http: ^10.0|^11.0|^12.0
- illuminate/support: ^10.0|^11.0|^12.0
Requires (Dev)
- laravel/pint: ^1.13
- orchestra/testbench: ^8.0|^9.0|^10.0
- phpunit/phpunit: ^10.0
README
Official Laravel package for CREEM, providing a clean, Laravel-native way to integrate payments, subscriptions, and webhooks.
Features
- Facade Support: Simple API calls via
Creem::createCheckout()and more. - Webhook Integration: Middleware-protected webhook routing with automatic event dispatching.
- Artisan Commands: Easily manage your CREEM configuration and sync products.
- SaaS Ready: Designed for subscriptions and one-time payments.
- CI/CD Ready: Pre-configured GitHub Actions for automated testing.
- Code Quality: Built-in support for Laravel Pint to maintain clean code.
Installation
You can install the package via composer:
composer require devmohy/creem-laravel
You should publish the config file with:
php artisan vendor:publish --tag="creem-config"
This is the contents of the published config file:
return [ 'api_key' => env('CREEM_API_KEY'), 'webhook_secret' => env('CREEM_WEBHOOK_SECRET'), 'api_base_url' => env('CREEM_API_BASE_URL', 'https://api.creem.io/v1'), ];
Usage
Create a Checkout Session
use Creem\CreemLaravel\Facades\Creem; $response = Creem::createCheckout([ 'product_id' => 'prod_12345', 'success_url' => route('checkout.success'), 'cancel_url' => route('checkout.cancel'), 'customer' => [ 'email' => 'user@example.com', ], ]); if ($response->successful()) { $checkoutUrl = $response->json('checkout_url'); return redirect($checkoutUrl); }
Get Product Details
$product = Creem::getProduct('prod_12345'); $allProducts = Creem::getProducts();
Subscription Management
// Cancel a subscription Creem::cancelSubscription('sub_123'); // Update a subscription (e.g., change plan) Creem::updateSubscription('sub_123', [ 'plan_id' => 'plan_premium', ]);
Customer Portal
Generate a secure link for users to manage their billing:
$response = Creem::createPortalLink([ 'customer_id' => 'cus_123', 'return_url' => route('dashboard'), ]); return redirect($response->json('portal_url'));
Coupons
$coupon = Creem::getCoupon('SAVE10');
Webhooks
To handle webhooks, you can use the built-in controller or define your own route using the provided middleware.
Built-in Route (Optional)
Add this to your routes/api.php:
Route::post('/creem/webhook', \Creem\CreemLaravel\Http\Controllers\WebhookController::class) ->middleware(\Creem\CreemLaravel\Http\Middleware\VerifyWebhookSignature::class);
Events
The package dispatches events when a webhook is received:
Creem\CreemLaravel\Events\WebhookReceivedCreem\CreemLaravel\Events\CheckoutSucceededCreem\CreemLaravel\Events\SubscriptionUpdated
You can listen to these events in your EventServiceProvider:
protected $listen = [ \Creem\CreemLaravel\Events\CheckoutSucceeded::class => [ \App\Listeners\HandleSuccessfulPayment::class, ], ];
Commands
Set Webhook Secret
Generates or sets the CREEM_WEBHOOK_SECRET in your .env file.
php artisan creem:webhook-secret
Sync/List Products
Fetches and displays all products from your CREEM dashboard.
php artisan creem:sync-products
Demo Application
A full-featured demo application is included in the demo directory. It showcases:
- Pricing Plans: Beautiful UI for plan selection.
- Checkout Flow: Native integration with the CREEM checkout.
- Customer Portal: One-click billing management.
- Webhook Handling: Real-time event listening and logging.
To run the demo:
cd democomposer installcp .env.example .env(Add yourCREEM_API_KEY)php artisan serve
Testing
composer test
Security
If you discover any security related issues, please email devmohy@gmail.com instead of using the issue tracker.
Credits
Contributing
Please see CONTRIBUTING for details.
Community
License
The MIT License (MIT). Please see License File for more information.