PHP code example of robo-meister / accord-flow-api

1. Go to this page and download the library: Download robo-meister/accord-flow-api 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/ */

    

robo-meister / accord-flow-api example snippets




ccordFlow\AccordFlowClient;

$client = new AccordFlowClient(
    baseUrl: 'http://localhost:8080',
    bearerToken: getenv('ACCORDFLOW_TOKEN') ?: null,
    tenantId: getenv('ACCORDFLOW_TENANT') ?: null,
);

$status = $client->status();

$envelope = $client->createEnvelope([
    'name' => 'Engagement agreement',
    'organisationId' => 'org-123',
    'globalDocumentId' => 'doc-123',
    'contextType' => 'legal_matter',
    'contextId' => 'matter-123',
    'sendImmediately' => false,
    'notificationOwnership' => 'EXTERNAL',
    'rcContext' => ['correlationId' => 'signing-123'],
], 'signing-123:create');

$envelopeId = $envelope['id'];
$client->addEnvelopeDocument($envelopeId, '/path/to/approved.pdf', 'signing-123:document');

$recipientResult = $client->addEnvelopeRecipients($envelopeId, [[
    'name' => 'Client',
    'email' => '[email protected]',
    'routingOrder' => 1,
    'role' => 'SIGNER',
]], 'signing-123:recipients');
$recipientId = $recipientResult['recipients'][0]['id'];

$session = $client->createEnvelopeEmbeddedSession($envelopeId, [
    'recipientId' => $recipientId,
    'locale' => 'en-US',
], 'signing-123:session');
$signingUrl = $session['signingUrl'] ?? null;
if (!is_string($signingUrl) || filter_var($signingUrl, FILTER_VALIDATE_URL) === false) {
    throw new RuntimeException('AccordFlow did not return a signing destination.');
}

// Run only after the application's professional review and current-state checks.
$client->sendEnvelope($envelopeId, [
    'initiatedBy' => '[email protected]',
    'notificationOwnership' => 'EXTERNAL',
], 'signing-123:send');

// Communication, not AccordFlow, now delivers the approved invitation.
// $communicationReceipt comes from that subsystem's durable send result.
if (($communicationReceipt['status'] ?? null) === 'SENT') {
    $client->recordEnvelopeDeliveryProof($envelopeId, [
        'recipientId' => $recipientId,
        'channel' => 'EMAIL',
        'eventType' => 'DISPATCHED',
        'status' => 'SENT',
        'destination' => '[email protected]',
        'templateId' => 'legal.signature.invitation.v1',
        'providerEventId' => $communicationReceipt['messageId'],
        'occurredAt' => $communicationReceipt['sentAt'],
    ], 'signing-123:delivery-proof');
}

$status = $client->getEnvelopeStatus($envelopeId);
if (($status['status'] ?? $status) !== 'COMPLETED') {
    throw new RuntimeException('Envelope is not complete.');
}

$executed = $client->listEnvelopeExecutedDocuments($envelopeId);
foreach ($executed['documents'] ?? [] as $descriptor) {
    $artifact = $client->downloadEnvelopeExecutedDocument(
        $envelopeId,
        $descriptor['artifactId'],
    );

    if (hash('sha256', $artifact->body) !== $descriptor['sha256']) {
        throw new RuntimeException('Executed document hash mismatch.');
    }

    // Persist exactly $artifact->body.
}

$bundles = $client->listEnvelopeEvidenceBundles($envelopeId);

$bundle = $client->createEnvelopeEvidenceBundle(
    $envelopeId,
    payload: ['requestedBy' => 'reconciliation-service'],
    idempotencyKey: 'signature-123:evidence-bundle',
);

$existing = $bundles[0] ?? null;
if ($existing !== null) {
    $download = $client->downloadEnvelopeEvidenceBundle(
        $envelopeId,
        $existing['bundleId'],
    );
}

$response = $client->sign([
    'envelopeId' => 456,
    'data' => 'Hello world',
    'documentType' => 'txt',
    'profile' => [
        'countryCode' => 'PL',
        'type' => 'EXTERNAL',
        'mode' => 'RAW',
    ],
    'username' => 'demo',
    'consent' => [
        // This value must reflect the actual signer's explicit choice, not a default.
        'accepted' => true,
        'method' => 'CHECKBOX',
    ],
]);

$signature = $response['signature'] ?? null;
$redirectUrl = $response['redirectUrl'] ?? null;

$signed = $client->signFile('/path/to/document.pdf', 456, [
    'profileId' => 123,
]);

$verification = $client->verifyFile(
    '/path/to/document.pdf',
    $signed['signature'],
    ['profileId' => 123],
);

// The second signFile argument is the multipart envelopeId form field.

$usage = $client->get('/api/auth/usage/demo');
$createdUser = $client->post('/api/auth/signup', [
    'username' => 'demo',
    'password' => 'change-me',
]);

use AccordFlow\AccordFlowException;

try {
    $client->verify([
        'data' => 'Hello world',
        'signature' => $signature,
        'documentType' => 'txt',
        'username' => 'demo',
    ]);
} catch (AccordFlowException $error) {
    error_log('AccordFlow verification failed; HTTP ' . $error->getStatusCode());
}