1. Go to this page and download the library: Download ceibacore/ceiba-ase 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/ */
ceibacore / ceiba-ase example snippets
use CeibaAse\AseManager;
// Register Stripe
AseManager::registerGateway('stripe', [
'publishable_key' => 'pk_live_...', // For client-side checkout
'secret_key' => 'sk_live_...', // For server-side API
'webhook_secret' => 'whsec_...', // For webhook validation
'test_mode' => false
]);
// Register PayPal
AseManager::registerGateway('paypal', [
'client_id' => 'xxx',
'client_secret' => 'yyy',
'webhook_id' => 'zzz',
'sandbox' => false
]);
// Create plan
$plan = AseManager::createPlan('pro', 'Professional Plan', 'Full features', true);
// Add price: $99.99 per month with 7-day trial
$price = AseManager::createPlanPrice(
$plan['id'],
'recurring', // or 'one_time'
99.99,
'USD',
'month', // interval: day|month|quarter|year
1, // interval count
7 // trial days
);
// List available gateways
$gateways = AseManager::getEnabledGateways();
// Returns: [
// ['id' => 'gw1', 'provider' => 'stripe'],
// ['id' => 'gw2', 'provider' => 'paypal']
// ]
// User selects a gateway
$selectedGatewayId = $gateways[0]['id'];
// Create checkout
$checkoutUrl = AseManager::createCheckoutSession(
$clientId,
$priceId,
$selectedGatewayId,
'https://your-domain.com/success?session_id={CHECKOUT_SESSION_ID}', // {CHECKOUT_SESSION_ID} is supported by Stripe
'https://your-domain.com/cancel'
);
// Redirect user
header("Location: $checkoutUrl");
use CeibaAse\AseManager;
// Grant course access when a subscription starts or renews
AseManager::listen('subscription.created', function($subscription) {
MyLmsAccessService::grant($subscription->externalClientId());
});
// Revoke access when canceled or unpaid
AseManager::listen('subscription.canceled', function($subscription) {
MyLmsAccessService::revoke($subscription->externalClientId());
});
// Sync invoices with accounting software
AseManager::listen('invoice.paid', function($invoice) {
AccountingApi::syncInvoice($invoice);
});
// Get all ENABLED gateways (active payment methods)
$gateways = AseManager::getEnabledGateways();
// Returns: [['id' => 'uuid1', 'provider' => 'stripe'], ...]
// Get ALL gateways (including disabled)
$all = AseManager::getAllGateways();
// Returns: [['id' => 'uuid1', 'provider' => 'stripe', 'is_active' => true], ...]
// Get specific gateway by ID
$gateway = AseManager::getGatewayById($gatewayId);
// Returns: ['id' => '...', 'provider' => '...', 'is_active' => true] or null
// Get first enabled gateway of a provider type
$stripe = AseManager::getGatewayByProvider('stripe');
// Returns: ['id' => '...', 'provider' => 'stripe'] or null
// Gateway credentials stored as encrypted JSON in ase_gateways table
$credentials = [
'publishable_key' => '...', // Visible to frontend for checkout
'secret_key' => '...', // Server-only, never leaked
'webhook_secret' => '...', // Encrypted at rest
'test_mode' => false
];
// Extracted via GatewayRepository::findById()
// Never logged or exposed in error messages
// Invoice created during trial has:
$invoice = [
'amount' => 0, // No charge during trial
'status' => 'draft', // Not yet issued
'reason' => 'trial'
];
// After trial ends or first renewal:
// → amount is populated with plan price
// → status changes to 'pending' or 'paid'
// migrations/php/20260505000000_add_payment_method_column.php
use CeibaAse\Migration\AseBaseMigration;
use CeibaAse\Migration\AseSchemaBuilder;
class Migration_20260505000000_AddPaymentMethodColumn extends AseBaseMigration
{
public const VERSION = '20260505000000';
public const DESCRIPTION = 'add_payment_method_column';
public function up(): void
{
AseSchemaBuilder::alterTable('ase_subscriptions', function($table) {
$table->addColumn('payment_method', 'string', 50)->after('status');
});
}
public function down(): void
{
AseSchemaBuilder::alterTable('ase_subscriptions', function($table) {
$table->dropColumn('payment_method');
});
}
}
class PostgreSQLDialect implements AseDialectInterface
{
public function jsonType(): string { /* return 'JSONB'; */ }
public function booleanType(): string { /* return 'BOOLEAN'; */ }
public function autoIncrementPk(): string { /* return 'BIGSERIAL PRIMARY KEY'; */ }
// ... (10 more methods)
}
// In your service provider
use CeibaAse\Ase;
class AseServiceProvider extends ServiceProvider
{
public function boot()
{
// Initialize ASE with Laravel's DB connection
Ase::boot([
'db' => [
'driver' => 'mysql',
'host' => config('database.connections.mysql.host'),
'database' => config('database.connections.mysql.database'),
'username' => config('database.connections.mysql.username'),
'password' => config('database.connections.mysql.password'),
]
]);
}
}
// In your service
use CeibaAse\Ase;
class SubscriptionService
{
public function __construct(private Connection $db)
{
Ase::boot([
'db' => [
'pdo' => $this->db->getWrappedConnection()
]
]);
}
}
// In your plugin bootstrap
use CeibaAse\Ase;
add_action('plugins_loaded', function() {
global $wpdb;
Ase::boot([
'db' => [
'pdo' => $wpdb->dbh // Use WordPress DB connection
]
]);
});
// Verify gateway is registered and enabled
$gateways = AseManager::getEnabledGateways();
if (empty($gateways)) {
echo "ERROR: No enabled gateways. Register one first.";
}
// Verify webhook secret matches
// Ensure raw body (not parsed JSON) is passed to handleWebhook()
$rawBody = file_get_contents('php://input');
// NOT: $rawBody = json_encode($_POST);
// After retrieving a plan via repository
$planRepo = new CeibaPlanRepository();
$plan = $planRepo->findBySlug('enterprise');
// Get entire metadata
$meta = $plan->metadata();
// Get specific attribute with optional default
$maxUsers = $plan->getMetadata('max_users', 10); // defaults to 10 if not set
$isRecommended = $plan->getMetadata('is_recommended', false);
// Check if key exists (null values return false)
if ($plan->hasMetadata('features')) {
$features = $plan->getMetadata('features');
}
// MySQL: Get all recommended plans
$db = CeibaInstance::get();
$recommended = $db->query('ase_plans')
->where([
'is_active' => 1
])
->get();
// Filter in PHP (CeibaDB does not support JSON_EXTRACT in WHERE yet)
$recommended = array_filter($recommended, function($row) {
$metadata = json_decode($row['metadata'] ?? '{}', true);
return $metadata['is_recommended'] ?? false;
});
bash
cd ceiba-ase
php bin/ase-migrate migrate
bash
GATEWAY_ENCRYPTION_KEY= # 32-byte base64 key (generate: php -r "echo base64_encode(random_bytes(32));")
GATEWAY_CSRF_SECRET= # HMAC secret (falls back to GATEWAY_SERVICE_SECRET)
bash
# Applied automatically during schema setup
php bin/ase-migrate migrate
# You can verify it exists:
php bin/ase-migrate status
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.