PHP code example of xultech / devpayr-php-sdk

1. Go to this page and download the library: Download xultech/devpayr-php-sdk 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/ */

    

xultech / devpayr-php-sdk example snippets




evPayr\DevPayr;
use DevPayr\Exceptions\DevPayrException;

try {
    DevPayr::bootstrap([
        'license'        => 'YOUR-LICENSE-KEY',
        'injectables'    => true,
        'invalidBehavior'=> 'modal', // Options: modal, redirect, silent, log
    ]);
    
    // Your protected logic continues here...
    echo "License valid. Project is paid.";
} catch (DevPayrException $e) {
    // Handle critical exceptions
    echo " DevPayr error: " . $e->getMessage();
}

use DevPayr\DevPayr;

DevPayr::bootstrap([
    'license' => $_ENV['LICENSE_KEY'],
    'secret' => $_ENV['LICENSE_KEY'],
    'injectablesPath' => __DIR__ . '/injectables',
    'handleInjectables' => true,
    'invalidBehavior' => 'modal', // or 'redirect', 'log', 'silent'
    'customInvalidMessage' => 'Your license is invalid or has expired.',
]);

class MyCustomProcessor {
    public static function handle(array $injectable, string $secret, string $basePath, bool $verify = true): string
    {
        // Decrypt and save however you want
        $decrypted = CryptoHelper::decrypt($injectable['encrypted_content'], $secret);
        // Example: save to cache or custom location
        return '/custom/storage/path/' . $injectable['slug'];
    }
}

DevPayr::bootstrap([
    'secret' => $key,
    'injectablesProcessor' => MyCustomProcessor::class,
    'handleInjectables' => true
]);

'invalidBehavior' => 'modal' // or: 'redirect', 'log', 'silent'

DevPayr::bootstrap([
    'secret' => $secret,
    'license' => $license,
    'invalidBehavior' => 'redirect',
    'redirectUrl' => 'https://yourdomain.com/license-invalid',
]);

DevPayr::bootstrap([
    'secret' => $secret,
    'license' => $license,
    'onReady' => function ($response) {
        // License valid — proceed with boot logic
        echo "✅ Welcome, licensed user!";
    },
]);

use DevPayr\DevPayr;

DevPayr::bootstrap([
    'license' => 'your-license-key',
    'secret' => 'your-decryption-secret',
]);

$projects = DevPayr::projects();
$licenses = DevPayr::licenses();
$domains = DevPayr::domains();
$injectables = DevPayr::injectables();
$payments = DevPayr::payments();

use DevPayr\Services\LicenseService;
use DevPayr\Config\Config;

$config = new Config([...]);
$licenseService = new LicenseService($config);

$projectService = DevPayr::projects($config[
    'per_page' =>50
]);

// List all projects
$projects = $projectService->list();

// Create a new project
$created = $projectService->create([
    'name' => 'My Awesome App',
]);

// Update a project
$projectService->update($projectId, [
    'name' => 'Updated Name',
]);

// Get a project
$projectService->get($projectId);

// Delete a project
$projectService->delete($projectId);

$licenseService = DevPayr::licenses($config);

// Issue a new license
$newLicense = $licenseService->create([
    'project_id' => $projectId,
    'expires_at' => '2025-12-31',
]);

// Delete an existing license
$licenseService->delete($projectId, $licenseId);

// Revoke a license
$licenseService->revoke($projectId, $licenseId);

// Reactivate a license
$licenseService->reactivate($projectId, $licenseId);

// Get a license
$licenseService->show($projectId, $licenseId);

// List all project's license
$licenseService->list($projectId);

$domainService = DevPayr::domains();

// List allowed domains for a project
$domains = $domainService->list($projectId);

// Get an allowed domain for a project
$domains = $domainService->show($projectId, $domainId);

// Add a domain
$domainService->create($projectId, [
    'domain' => 'example.com',
]);

// Update a domain
$domainService->create($projectId, $domainId, [
    'domain' => 'example.com',
]);

// Delete a domain
$domainService->delete($domainId);

$injectableService = DevPayr::injectables();

// List injectables for a project
$injectables = $injectableService->list($projectId);

// Get an injectables for a project
$injectables = $injectableService->list($projectId, $injectableId);

// Create a new injectable
$injectableService->create($projectId, [
    'slug' => 'header-snippet',
    'content' => '<?= "Hello World"; 

$paymentService = DevPayr::payments($config);

// Check if a license has been paid for
$paid = $paymentService->checkWithLicenseKey([
    'license' => 'YOUR-LICENSE-KEY',
]);

// Check if a license has been paid for
$paid = $paymentService->checkWithApiKey($projectId);

if (!$paid) {
    echo "⚠️ Payment 

namespace DevPayr\Contracts;

/**
 * Interface InjectableProcessorInterface
 *
 * Allows for custom processing of SDK injectables (e.g. decrypt, verify, and save elsewhere).
 */
interface InjectableProcessorInterface
{
    /**
     * Handle a single injectable payload.
     *
     * @param array $injectable Raw injectable data from API
     * @param string $secret Shared secret (typically the license key)
     * @param string $basePath Base path for writing (if file-based)
     * @param bool $verifySignature Whether to verify HMAC signature
     *
     * @return string Path or identifier of the saved injectable
     */
    public static function handle(array $injectable, string $secret, string $basePath, bool $verifySignature = true): string;
}

namespace App\Licensing;

use DevPayr\Contracts\InjectableProcessorInterface;
use DevPayr\Exceptions\DevPayrException;
use DevPayr\Support\CryptoHelper;

class CustomInjectableHandler implements InjectableProcessorInterface
{
    public static function handle(array $injectable, string $secret, string $basePath, bool $verifySignature = true): string
    {
        $slug = $injectable['slug'];
        $encrypted = $injectable['encrypted_content'] ?? $injectable['content'];
        $decrypted = CryptoHelper::decrypt($encrypted, $secret);

        // ✅ Save to a database, Redis, S3, or custom location
        // Example: Save to temporary file
        $path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . "{$slug}.tmp";

        if (file_put_contents($path, $decrypted) === false) {
            throw new DevPayrException("Failed to store injectable: {$slug}");
        }

        return $path;
    }
}

DevPayr::bootstrap([
    'secret' => $secret,
    'license' => $license,
    'handleInjectables' => true,
    'injectablesProcessor' => \App\Licensing\CustomInjectableHandler::class,
]);

use DevPayr\DevPayr;
use DevPayr\Exceptions\DevPayrException;
use DevPayr\Exceptions\ApiResponseException;

try {
    DevPayr::bootstrap([
        'license' => 'my-license-key',
        'secret' => 'my-secret-key',
    ]);
} catch (ApiResponseException $e) {
    // API responded with an error (e.g. invalid license, quota exceeded)
    echo "API Error: " . $e->getMessage();
} catch (DevPayrException $e) {
    // SDK misconfigured or failed to decrypt/process injectables
    echo "SDK Error: " . $e->getMessage();
}

DevPayr::bootstrap([
    'license'  => 'YOUR-LICENSE-KEY',
    'secret'   => 'YOUR-SECRET',
    'recheck'  => true, // ← Set false to use cache only
]);

DevPayr::bootstrap([
    'secret'           => $secret,
    'license'          => $license,
    'injectablesPath'  => __DIR__ . '/config/devpayr/',
]);

DevPayr::bootstrap([
    'secret'              => $secret,
    'license'             => $license,
    'handleInjectables'   => true,
    'injectablesProcessor'=> \App\Licensing\CustomHandler::class,
]);

DevPayr::bootstrap([
    'secret'   => $secret,
    'license'  => $license,
    'onReady'  => function ($response) {
        // Your app boot logic
    },
]);
bash
composer 
bash
   git clone https://github.com/your-username/devpayr-php-sdk.git
   cd devpayr-php-sdk