1. Go to this page and download the library: Download romansh/laravel-creem 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 Romansh\LaravelCreem\Facades\Creem;
// Find customer by ID
$customer = Creem::customers()->find('cust_123');
// Find customer by email
$customer = Creem::customers()->findByEmail('[email protected]');
// List customers (paginated)
$customers = Creem::customers()->list($page = 1, $pageSize = 20);
// Convenience total alias derived from pagination.total_records
$totalCustomers = $customers['total'];
// Generate customer portal link
$portalLink = Creem::customers()->createPortalLink('cust_123');
return redirect($portalLink);
use Romansh\LaravelCreem\Facades\Creem;
// Find a subscription
$subscription = Creem::subscriptions()->find('sub_123');
// List subscriptions
$subscriptions = Creem::subscriptions()->list($page = 1, $limit = 20);
// List subscriptions with filters
$subscriptions = Creem::subscriptions()->list($page = 1, $limit = 20, [
'status' => 'active',
'customer_id' => 'cust_123',
]);
// Cancel a subscription
$subscription = Creem::subscriptions()->cancel('sub_123');
// Pause a subscription
$subscription = Creem::subscriptions()->pause('sub_123');
// Resume a paused subscription
$subscription = Creem::subscriptions()->resume('sub_123');
// Upgrade/change subscription to a different product
$subscription = Creem::subscriptions()->upgrade(
subscriptionId: 'sub_123',
productId: 'prod_456',
updateBehavior: 'proration-charge-immediately'
);
// Update subscription data
$subscription = Creem::subscriptions()->update('sub_123', [
'metadata' => ['updated' => true],
]);
use Romansh\LaravelCreem\Facades\Creem;
// Find a transaction by ID
$transaction = Creem::transactions()->find('txn_123');
// List all transactions (paginated)
$transactions = Creem::transactions()->list([], $page = 1, $pageSize = 20);
// List transactions with filters
$transactions = Creem::transactions()->list([
'customer_id' => 'cust_123',
'product_id' => 'prod_456',
'order_id' => 'ord_789',
], $page = 1, $pageSize = 20);
// Convenience total alias derived from pagination.total_records
$totalTransactions = $transactions['total'];
// Get transactions for a specific customer
$transactions = Creem::transactions()->byCustomer('cust_123');
// Get transactions for a specific order
$transactions = Creem::transactions()->byOrder('ord_456');
// Get transactions for a specific product
$transactions = Creem::transactions()->byProduct('prod_789');
use Romansh\LaravelCreem\Facades\Creem;
// Validate a license key
$license = Creem::licenses()->validate(
key: 'ABC123-XYZ456-XYZ456-XYZ456',
instanceId: 'inst_123'
);
if ($license['status'] === 'active') {
// Grant access to premium features
}
// Activate a license on a new device
$license = Creem::licenses()->activate(
key: 'ABC123-XYZ456-XYZ456-XYZ456',
instanceName: 'johns-macbook-pro'
);
$instanceId = $license['instance']['id'];
// Deactivate a license instance
$license = Creem::licenses()->deactivate(
key: 'ABC123-XYZ456-XYZ456-XYZ456',
instanceId: 'inst_123'
);
namespace App\Listeners;
use Romansh\LaravelCreem\Events\GrantAccess;
class ProvisionUserAccess
{
public function handle(GrantAccess $event)
{
$customer = $event->customer;
$metadata = $event->metadata;
// Use metadata (e.g. referenceId) to find internal user and provision access
// $userId = $metadata['referenceId'] ?? null;
}
}
namespace App\Http\Controllers;
use Romansh\LaravelCreem\Http\Middleware\VerifyCreemWebhook;
use Illuminate\Http\Request;
class CustomWebhookController extends Controller
{
public function __construct()
{
$this->middleware(VerifyCreemWebhook::class);
}
public function handle(Request $request)
{
$event = $request->input('event');
$data = $request->input('data');
// Handle webhook...
return response()->json(['message' => 'Processed']);
}
}
use Romansh\LaravelCreem\Exceptions\ApiException;
use Romansh\LaravelCreem\Exceptions\ConfigurationException;
try {
$checkout = Creem::checkouts()->create([...]);
} catch (ApiException $e) {
// API error (400, 403, 404, etc.)
$statusCode = $e->getStatusCode();
$messages = $e->getMessages();
$traceId = $e->getTraceId(); // Include in support requests
return back()->withErrors($messages);
} catch (ConfigurationException $e) {
// Configuration error (missing profile, invalid API key, etc.)
logger()->error($e->getMessage());
}