1. Go to this page and download the library: Download creem/laravel 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/ */
use Creem\Laravel\Traits\Billable;
class User extends Authenticatable
{
use Billable;
}
// Create a checkout for this user
$checkout = $user->checkout('prod_abc123', [
'success_url' => route('checkout.success'),
]);
// Get billing portal URL
$portal = $user->billingPortalUrl();
// Get all subscriptions
$subscriptions = $user->creemSubscriptions();
// Cancel a subscription
$user->cancelSubscription('sub_xyz', 'scheduled');
// Create a product (price in cents)
Creem::createProduct([
'name' => 'Pro Plan',
'price' => 2999, // $29.99
'currency' => 'USD',
'billing_type' => 'recurring', // or 'onetime'
'billing_period' => 'every-month',
'tax_category' => 'saas',
]);
// Get a product
Creem::getProduct('prod_123');
// Search products
Creem::searchProducts(['limit' => 10]);
// Get customer by ID or email
Creem::getCustomer(['id' => 'cus_123']);
Creem::getCustomer(['email' => '[email protected]']);
// List all customers
Creem::listCustomers(['limit' => 50]);
// Generate billing portal link
Creem::customerBillingPortal('cus_123');
// Get a subscription
Creem::getSubscription('sub_123');
// Search subscriptions
Creem::searchSubscriptions(['status' => 'active']);
// Update (seats, units, add-ons)
Creem::updateSubscription('sub_123', ['units' => 5]);
// Upgrade to different product
Creem::upgradeSubscription('sub_123', 'prod_pro');
// Cancel (immediate or at period end)
Creem::cancelSubscription('sub_123', 'scheduled');
Creem::cancelSubscription('sub_123', 'immediate');
// Pause & Resume
Creem::pauseSubscription('sub_123');
Creem::resumeSubscription('sub_123');
// Activate a license on a device
$result = Creem::activateLicense('ABCD-1234-EFGH', 'MacBook Pro');
$instanceId = $result['instance_id'];
// Validate a license
Creem::validateLicense('ABCD-1234-EFGH', $instanceId);
// Deactivate
Creem::deactivateLicense('ABCD-1234-EFGH', $instanceId);
// Create a discount
Creem::createDiscount([
'name' => 'Launch Sale',
'code' => 'LAUNCH20',
'type' => 'percentage', // or 'fixed'
'percentage' => 20,
'duration' => 'forever', // 'forever', 'once', or 'repeating'
'applies_to_products' => ['prod_abc123'],
'max_redemptions' => 100,
]);
// Get a discount
Creem::getDiscount(['code' => 'LAUNCH20']);
// Delete a discount
Creem::deleteDiscount('disc_123');
use Creem\Laravel\Events\CheckoutCompleted;
use Creem\Laravel\Events\SubscriptionActive;
use Creem\Laravel\Events\SubscriptionCanceled;
class EventServiceProvider extends ServiceProvider
{
protected $listen = [
CheckoutCompleted::class => [
GrantAccessListener::class,
],
SubscriptionCanceled::class => [
RevokeAccessListener::class,
],
];
}
use Creem\Laravel\Events\CheckoutCompleted;
class GrantAccessListener
{
public function handle(CheckoutCompleted $event): void
{
$data = $event->payload;
// Grant access based on checkout data
// $data contains customer, product, and transaction info
}
}
use Creem\Laravel\Events\AccessGranted;
use Creem\Laravel\Events\AccessRevoked;
// AccessGranted fires on: checkout.completed, subscription.active, subscription.paid
// AccessRevoked fires on: subscription.canceled, subscription.expired
class ManageUserAccess
{
public function handleGrant(AccessGranted $event): void
{
// $event->reason — the original event type (e.g., 'checkout.completed')
// $event->payload — the webhook object data
}
public function handleRevoke(AccessRevoked $event): void
{
// Revoke the user's access
}
}
use Creem\Laravel\Events\CreemWebhookReceived;
class LogAllWebhooks
{
public function handle(CreemWebhookReceived $event): void
{
logger()->info("CREEM webhook: {$event->eventType}", $event->payload);
}
}
use Creem\Laravel\Exceptions\CreemApiException;
use Creem\Laravel\Exceptions\CreemAuthenticationException;
use Creem\Laravel\Exceptions\CreemRateLimitException;
try {
$product = Creem::getProduct('prod_123');
} catch (CreemAuthenticationException $e) {
// Missing or invalid API key (401/403)
} catch (CreemRateLimitException $e) {
// Rate limited (429) - check $e->getRetryAfter() for seconds to wait
} catch (CreemApiException $e) {
// Other API errors (400, 404, 500, etc.)
$traceId = $e->getTraceId(); // For CREEM support debugging
}