PHP code example of elqora / dgp-sdk

1. Go to this page and download the library: Download elqora/dgp-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/ */

    

elqora / dgp-sdk example snippets


use Elqora\ConfigKit\Schema\ConfigField;
use Elqora\ConfigKit\Schema\ConfigSchema;
use Elqora\ConfigKit\Support\ConfigBag;
use Elqora\ConfigKit\Support\ConfigValidationResult;

public function configSchema(): ?ConfigSchema
{
    return new ConfigSchema([
        new ConfigField(name: 'base_url', label: 'Base URL', ationResult(false);
        $result->addError('base_url', 'Base URL and API key are 

use Elqora\Dgp\Snapshots\OrderSnapshot;

$snapshot = OrderSnapshot::fromArray([
    'version' => '1',
    'mode' => 'prod',
    'built_at' => '2026-07-07T10:30:00.000Z',
    'product_id' => 'instagram-likes',
    'definition_schema_version' => '1',
    'selection' => ['filter_id' => 'instagram', 'trigger_ids' => [], 'fields' => []],
    'inputs' => ['form' => ['quantity' => 1000], 'selections' => []],
    'quantity' => 1000,
    'quantity_source' => [
        'kind' => 'host_default',
        'node_id' => null,
        'rule' => null,
        'defaulted_from_host' => true,
    ],
    'min' => 100,
    'max' => 10000,
    'service_ids' => [101, 103],
    'service_ids_by_node' => ['option:quality-ultra' => [103]],
    'fallbacks' => null,
    'utilities' => [],
    'meta' => [],
]);

$quantity = $snapshot->quantity();
$services = $snapshot->servicesForNode('option:quality-ultra');

use Elqora\Dgp\Runtime\InitializeRequest;
use Elqora\Dgp\Runtime\RuntimeContext;
use Elqora\Dgp\Runtime\PlanStatus;

$initialize = new InitializeRequest(
    orderId: 12345,
    snapshot: $snapshot,
    runtimeContext: new RuntimeContext(
        context: ['requestedBy' => 'customer_admin'],
        meta: ['traceId' => 'tr-9988'],
    ),
);

$plan = $handler->initialize($initialize)->value();
echo $plan->status->value; // 'active'

use Elqora\Dgp\Runtime\PrepareRequest;
use Elqora\Dgp\Runtime\PreparationStatus;

$persistedPlan = $runtimeStore->savePlan($plan);

$prepare = new PrepareRequest(
    orderId: $persistedPlan->orderId,
    plan: $persistedPlan,
    context: new RuntimeContext(context: ['ip' => '127.0.0.1']),
);

$preparation = $handler->prepare($prepare)->value();
echo $preparation->status->value; // 'running'

use Elqora\Dgp\Runtime\References\PlanReference;
use Elqora\Dgp\Runtime\RuntimeContext;
use Elqora\Dgp\Runtime\StartRequest;
use Elqora\Dgp\Runtime\StartResultStatus;

$start = new StartRequest(
    orderId: 12345,
    plan: new PlanReference(id: $persistedPlan->id),
    context: new RuntimeContext(context: ['ip' => '127.0.0.1']),
);

$startResult = $handler->start($start)->value();
echo $startResult->status->value; // 'running'

use Elqora\Dgp\Configuration\Dgp;
use Elqora\Dgp\Runtime\References\HandlerReference;
use Elqora\Dgp\Runtime\References\PlanReference;
use Elqora\Dgp\Runtime\PlanStatus;

Dgp::registerRuntimeRepository($runtimeRepository);

$runtime = Dgp::runtimeRepository(HandlerReference::fromKey('smm-test'));
$plan = $runtime->findPlan(12345, new PlanReference(key: 'plan-payment'))->value();
$view = $runtime->runtime(12345)->value();

// Update status directly via the repository
$runtime->updatePlanStatus($plan->id, PlanStatus::CANCELLED);

use Elqora\Dgp\Configuration\Dgp;
use Elqora\Dgp\Endpoints\HostEndpointType;

Dgp::endpointPrefix('/dgp');

$deliveryAction = Dgp::endpoint('smm-test', HostEndpointType::DELIVERY_ACTION);
$genericAction = Dgp::endpoint('smm-test', HostEndpointType::GENERIC_ACTION);
$chargePayment = Dgp::endpoint('smm-test', HostEndpointType::CHARGE_PAYMENT);
$privateAsset = Dgp::endpoint('smm-test', HostEndpointType::PRIVATE_ASSET, 'invoice.pdf');

echo $deliveryAction->path; // /dgp/smm-test/delivery/action
echo $genericAction->path;  // /dgp/smm-test/generic/action
echo $chargePayment->path;  // /dgp/smm-test/charge/payment
echo $privateAsset->path;   // /dgp/smm-test/assets/invoice.pdf

$custom = Dgp::path('smm-test', 'custom/action');

use Elqora\Dgp\Actions\ActionButton;
use Elqora\Dgp\Runtime\Plan;
use Elqora\Interactions\Interactions\Redirect;

$plan = new Plan(
    id: null,
    key: 'plan-payment',
    state: ['pending_payment' => true],
    buttons: [
        new ActionButton(
            value: 'approve',
            label: 'Approve',
        ),
        new ActionButton(
            value: 'action',
            label: 'Complete Invoice Payment',
            nextAction: new Redirect(
                url: 'https://gateway.example/pay/invoice-88',
                metadata: ['label' => 'Complete Invoice Payment'],
            ),
        ),
    ],
    nextAction: new Redirect(
        url: 'https://gateway.example/pay/invoice-88',
        metadata: ['label' => 'Complete Invoice Payment'],
    ),
);

use Elqora\Dgp\Actions\ActionButton;
use Elqora\Dgp\Actions\ActionButtonKind;
use Elqora\Dgp\Actions\ActionButtonStyle;

$buttons = [
    new ActionButton(
        value: 'cancel',
        label: 'Cancel',
        style: ActionButtonStyle::DANGER,
    ),
    new ActionButton(
        value: 'refresh',
        kind: ActionButtonKind::ICON,
        icon: 'refresh-cw',
        tooltip: 'Refresh',
    ),
];

use Elqora\Dgp\Actions\ActionButton;
use Elqora\Interactions\Interactions\Redirect;

$button = new ActionButton(
    value: 'action',
    label: 'Open payment',
    nextAction: new Redirect(
        url: 'https://gateway.example/pay/invoice-88',
    ),
);

use Elqora\Interactions\DTOs\Execution\HandlerExecution;
use Elqora\Interactions\DTOs\ScriptDefinition;
use Elqora\Interactions\Enums\Presentation;
use Elqora\Interactions\Interactions\Script;

$inline = new Script(
    scripts: [new ScriptDefinition(src: 'https://cdn.example.test/checkout.js', key: 'checkout')],
    execute: new HandlerExecution('checkout-widget', 'mount'),
    presentation: Presentation::Inline,
);

use Elqora\Dgp\Runtime\StartResult;

$start = new StartResult(
    id: null,
    key: 'start-payment',
    state: [],
    buttons: [
        new ActionButton(
            value: 'retry',
            label: 'Retry',
        ),
    ],
);

use Elqora\Dgp\Actions\ActionTarget;
use Elqora\Dgp\Actions\ActionTargetType;
use Elqora\Dgp\Actions\GenericActionRequest;

$generic = new GenericActionRequest(
    handlerKey: 'smm-test',
    actionValue: 'retry_selected',
    targets: [
        new ActionTarget(ActionTargetType::ORDER, 12345),
        new ActionTarget(ActionTargetType::CHARGE, 789, key: 'deposit'),
        new ActionTarget('provider.custom_target', 'target-1'),
    ],
);

$handler->handleGenericAction($generic);

use Elqora\Dgp\Actions\ActionTarget;
use Elqora\Dgp\Actions\ActionTargetType;
use Elqora\Dgp\Bulk\CancelBulkRequest;
use Elqora\Dgp\Bulk\RefreshBulkRequest;
use Elqora\Dgp\Bulk\RetryBulkRequest;
use Elqora\Dgp\Bulk\StartBulkRequest;

$targets = [
    new ActionTarget(ActionTargetType::ORDER, 12345),
    new ActionTarget(ActionTargetType::PLAN, 456),
];

$handler->startBulk(new StartBulkRequest('smm-test', $targets));
$handler->cancelBulk(new CancelBulkRequest('smm-test', $targets));
$handler->retryBulk(new RetryBulkRequest('smm-test', $targets));
$handler->refreshBulk(new RefreshBulkRequest('smm-test', $targets));

use Elqora\Dgp\Deliveries\DeliveryProgress;
use Elqora\Dgp\Deliveries\DeliveryProgressSegment;
use Elqora\Dgp\Deliveries\DeliveryStatus;
use Elqora\Dgp\Deliveries\InitializationDelivery;
use Elqora\Dgp\Actions\ActionButton;
use Elqora\Dgp\Actions\ActionButtonStyle;

$delivery = new InitializationDelivery(
    id: null,
    key: 'admin-review',
    status: DeliveryStatus::PROCESSING,
    label: 'Review',
    progress: new DeliveryProgress(current: 25, target: 100, percent: 25, unit: 'items'),
    kind: 'admin_review',
    name: 'Admin Review',
    isPublic: false,
    note: 'Internal preparation',
);

$progress = new DeliveryProgress(
    current: 50,
    target: 100,
    percent: 50,
    unit: 'items',
    segments: [
        new DeliveryProgressSegment(
            key: 'provider-import',
            progress: new DeliveryProgress(current: 20, target: 40, percent: 50, unit: 'items'),
            label: 'Provider import',
            status: 'processing',
            sequence: 1,
            buttons: [
                new ActionButton(
                    value: 'stop_segment',
                    label: 'Stop',
                    style: ActionButtonStyle::DANGER,
                    meta: ['segment_key' => 'provider-import'],
                ),
            ],
        ),
    ],
);

use Elqora\Dgp\Actions\ActionTarget;
use Elqora\Dgp\Actions\ActionTargetType;
use Elqora\Dgp\Actions\GenericActionRequest;

$request = new GenericActionRequest(
    handlerKey: 'smm-test',
    actionValue: 'stop_segment',
    targets: [
        new ActionTarget(ActionTargetType::FULFILLMENT_DELIVERY, $deliveryId, key: $deliveryKey),
        new ActionTarget(ActionTargetType::SEGMENT, 'provider-import', key: 'provider-import'),
    ],
);

use Elqora\Dgp\Configuration\Dgp;
use Elqora\Dgp\Deliveries\DeliveryProgress;
use Elqora\Dgp\Deliveries\DeliveryStage;
use Elqora\Dgp\Progress\DeliveryProgressRecord;
use Elqora\Dgp\Progress\ProgressSource;
use Elqora\Dgp\Runtime\References\DeliveryReference;
use Elqora\Dgp\Runtime\References\HandlerReference;

Dgp::registerDeliveryProgressRepository($progressRepository);

$progress = Dgp::deliveryProgressRepository(HandlerReference::fromKey('smm-test'));
$progress->record(new DeliveryProgressRecord(
    id: null,
    orderId: 12345,
    delivery: new DeliveryReference(key: 'admin-review'),
    stage: DeliveryStage::INITIALIZATION,
    progress: new DeliveryProgress(current: 50, target: 100, percent: 50, unit: 'items'),
    recordedAt: '2026-07-10T10:15:00Z',
    source: ProgressSource::SYNCHRONIZATION,
));

use Elqora\Dgp\Audits\AuditLevel;
use Elqora\Dgp\Audits\AuditRecord;
use Elqora\Dgp\Configuration\Dgp;
use Elqora\Dgp\Runtime\References\DeliveryReference;
use Elqora\Dgp\Runtime\References\HandlerReference;

Dgp::registerAuditRepository($auditRepository);

$audits = Dgp::auditRepository(HandlerReference::fromKey('smm-test'));
$audits->record(new AuditRecord(
    id: null,
    key: 'provider.submission_failed',
    level: AuditLevel::ERROR,
    message: 'Provider rejected the submitted order.',
    occurredAt: '2026-07-15T08:30:00Z',
    orderId: 12345,
    delivery: new DeliveryReference(key: 'fulfillment'),
    category: 'provider',
    code: 'provider_rejected',
    context: ['provider_status' => 'rejected'],
));

use Elqora\Dgp\Events\DgpEvent;
use Elqora\Dgp\Events\EventType;

$event = new DgpEvent(
    id: 'event-1',
    type: EventType::INITIALIZED,
    handlerKey: 'smm-test',
    orderId: 12345,
);

$custom = new DgpEvent(
    id: 'event-2',
    type: 'provider.custom_event',
    handlerKey: 'smm-test',
    orderId: 12345,
);

use Elqora\Dgp\Charges\Charge;
use Elqora\Dgp\Charges\ChargePaymentNotification;
use Elqora\Dgp\Charges\ChargePayment;
use Elqora\Dgp\Charges\ChargePaymentStatus;
use Elqora\Dgp\Charges\ChargeStatus;
use Elqora\Dgp\Charges\ChargeTarget;
use Elqora\Dgp\Charges\ChargeTargetType;
use Elqora\Dgp\Money\Amount;
use Elqora\Dgp\Money\Currency;
use Elqora\Dgp\Money\Money;

$payment = new ChargePayment(
    key: 'payment-1',
    amount: new Money(new Amount('25.00'), new Currency('USD')),
    status: ChargePaymentStatus::PAID,
    paidAt: '2026-07-09T10:00:00Z',
    method: 'wallet',
    reference: 'txn-123',
);

$charge = new Charge(
    id: null,
    key: 'deposit',
    target: new ChargeTarget(ChargeTargetType::PLAN, key: 'plan-payment'),
    label: 'Deposit',
    amount: new Money(new Amount('100.00'), new Currency('USD')),
    status: ChargeStatus::PARTIALLY_PAID,
    paidAmount: new Money(new Amount('25.00'), new Currency('USD')),
    balanceDue: new Money(new Amount('75.00'), new Currency('USD')),
    payments: [$payment],
);

$planCharge = new Charge(
    id: null,
    key: 'setup-fee',
    target: new ChargeTarget(ChargeTargetType::PLAN, key: 'plan-payment'),
    label: 'Setup Fee',
    amount: new Money(new Amount('100.00'), new Currency('USD')),
    status: ChargeStatus::PENDING,
);

$segmentCharge = new Charge(
    id: null,
    key: 'approval-fee',
    target: new ChargeTarget(
        type: ChargeTargetType::SEGMENT,
        key: 'approval',
        parent: new ChargeTarget(ChargeTargetType::DELIVERY, key: 'fulfillment'),
    ),
    label: 'Approval Fee',
    amount: new Money(new Amount('25.00'), new Currency('USD')),
    status: ChargeStatus::PENDING,
);

$futureCharge = new Charge(
    id: null,
    key: 'checkpoint-fee',
    target: new ChargeTarget('workflow.custom_checkpoint', key: 'checkpoint-1'),
    label: 'Checkpoint Fee',
    amount: new Money(new Amount('15.00'), new Currency('USD')),
    status: ChargeStatus::PENDING,
);

$notification = new ChargePaymentNotification(
    orderId: 12345,
    chargeKey: 'deposit',
    paymentKey: 'payment-1',
    amount: new Money(new Amount('25.00'), new Currency('USD')),
    status: ChargePaymentStatus::PAID,
    occurredAt: '2026-07-09T10:00:01Z',
    paidAt: '2026-07-09T10:00:00Z',
    resultingChargeStatus: ChargeStatus::PARTIALLY_PAID,
    chargeTarget: new ChargeTarget(ChargeTargetType::PLAN, key: 'plan-payment'),
    meta: ['gateway' => 'internal'],
);

use Elqora\Dgp\Catalog\Schemas\Contracts\ProductDefinitionCatalogContract;
use Elqora\Dgp\Catalog\Schemas\ProductDefinition;
use Elqora\Dgp\Catalog\Schemas\ProductDefinitionQuery;
use Elqora\Dgp\Errors\Result;

final class ProductCatalog implements ProductDefinitionCatalogContract
{
    public function definitions(ProductDefinitionQuery $query): Result
    {
        return Result::success([
            new ProductDefinition(
                id: 'manual-task-1',
                name: 'Manual Custom Task',
                filters: [['id' => 'tag:manual', 'label' => 'Manual Task']],
                fields: [['id' => 'field:desc', 'type' => 'text', 'label' => 'Instructions']],
                schemaVersion: '1',
            ),
        ]);
    }
}

use Elqora\Chart\Charts\Charts;
use Elqora\Chart\Enums\ValueType;
use Elqora\Chart\Series\Series;
use Elqora\Dgp\Insights\Analysis;

$chart = Charts::line(
    key: 'delivery.throughput',
    title: 'Delivery throughput',
    category: 'time',
    rows: [
        ['time' => '10:00', 'delivered' => 10],
        ['time' => '10:30', 'delivered' => 25],
    ],
    series: [
        new Series('delivered', 'Delivered', 'delivered', ValueType::INTEGER),
    ],
);

$analysis = new Analysis('delivery.throughput', $chart);

use Elqora\Dgp\Charges\Contracts\ChargeUpdateHookContract;
use Elqora\Dgp\Charges\ChargeUpdateRequest;
use Elqora\Dgp\Errors\Result;

class MyChargeUpdateHook implements ChargeUpdateHookContract
{
    public function update(ChargeUpdateRequest $request): Result
    {
        // Host-side charge persistence and presentation logic...
        return Result::success(null);
    }
}

use Elqora\Dgp\Charges\Contracts\ChargePaymentNotificationContract;
use Elqora\Dgp\Charges\ChargePaymentNotification;
use Elqora\Dgp\Errors\Result;

class MyHandlerPaymentNotifications implements ChargePaymentNotificationContract
{
    public function notifyPayment(ChargePaymentNotification $notification): Result
    {
        // Handler-side workflow progression after host-recorded payment...
        return Result::success(null);
    }
}

use Elqora\Dgp\Charges\Contracts\ChargeStateResolverContract;
use Elqora\Dgp\Charges\ChargeStateRequest;
use Elqora\Dgp\Errors\Result;

class MyChargeStateResolver implements ChargeStateResolverContract
{
    public function resolve(ChargeStateRequest $request): Result
    {
        // Resolve current charge and payment state for recovery...
        return Result::success(null);
    }
}

use Elqora\Dgp\Events\Contracts\EventHookContract;
use Elqora\Dgp\Events\DgpEvent;

class MyEventHook implements EventHookContract
{
    public function dispatch(DgpEvent $event): void
    {
        // Emit or log the event...
    }
}

use Elqora\Dgp\Events\Contracts\WebhookContract;
use Elqora\Dgp\Events\WebhookRequest;
use Elqora\Dgp\Errors\Result;

class MyWebhookHandler implements WebhookContract
{
    public function handleWebhook(WebhookRequest $request): Result
    {
        // 1. Verify signatures in $request->headers
        // 2. Decode $request->body
        // 3. Return normalized DgpEvent payload
        return Result::success($normalizedEvent);
    }
}
bash
vendor/bin/phpunit tests/Compliance/RepositoryComplianceTest.php