PHP code example of interfax / interfax

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

    

interfax / interfax example snippets




use Interfax\Client;

$interfax = new Client(['username' => 'username', 'password' => 'password']);
$fax = $interfax->deliver(['faxNumber' => '+11111111112', 'file' => 'folder/file.pdf']);

// get the latest status:
$fax->refresh()->status; // Pending if < 0. Error if > 0

// Simple polling
while ($fax->refresh()->status < 0) {
    sleep(5);
}

$client = new Interfax\Client(['username' => '...', 'password' => '...']);

// Alternative: will utilise environment variables:
// * INTERFAX_USERNAME
// * INTERFAX_PASSWORD

$client = new Interfax\Client();

$client = new Interfax\Client(['username' => '...', 'password' => '...']);
$fax = $client->deliver([
    'faxNumber' => '+442086090368',
    'file' => __DIR__ . '/../tests/Interfax/test.pdf'
]);

$stream = fopen('/tmp/fax.pdf', 'rb');
$fax = $client->deliver([
    'faxNumber' => '+442086090368',
    'file' => [$stream, ['name' => 'fax.pdf', 'mime_type' => 'application/pdf']]

echo $client->getBalance();
// (string) 9.86

$outbound = $client->outbound;

$faxes = $client->outbound->recent();
// Interfax\Outbound\Fax[]

$fax_ids = [ ... ]; // array of fax ids
$client->outbound->completed($fax_ids);
// Interfax\Outbound\Fax[]

$fax = $client->outbound->find(123456);
//Interfax\Outbound\Fax || null

$fax = $client->outbound->find(123456);
if ($fax) {
    $image = $fax->image();
    $image->save('path/to/save/file/to.tif');
}

$fax = $client->outbound->find(123456);
if ($fax) {
    $fax->cancel();
}

$faxes = $client->outbound->search(['faxNumber' => '+1230002305555']);
// Interfax\Outbound\Fax[]

$fax = $client->outbound->resend($id);
// Interfax\Outbound\Fax sent to the original number
$fax = $client->outbound->resend($id, $new_number);
// Interfax\Outbound\Fax sent to the $new_number

$inbound = $client->inbound;
//Interfax\Inbound

$faxes = $inbound->incoming();
//\Interfax\Inbound\Fax[]
$faxes = $inbound->incoming(['unreadOnly' => true ...]); // see docs for list of supported query params
//\Interfax\Inbound\Fax[]

$fax = $inbound->find(123456);
//\Interfax\Inbound\Fax || null

$fax = $client->inbound->find(123456);
if ($fax) {
    $image = $fax->image();
    $image->save('path/to/save/file/to.pdf');
}

$fax = $client->inbound->find(123456);
if ($fax) {
    $emails = $fax->emails(); // array structure of forwarding emails.
}

[
    [
       'emailAddress' => '[email protected]',
       'messageStatus' => 0,
       'completionTime' => '2012-0623T17 => 24 => 11'
    ],
    //...
];

$fax = $client->inbound->find(123456);
if ($fax) {
    $fax->markUnread(); // returns true
    $fax->markRead(); //returns true
}

$fax = $client->inbound->find(123456);
if ($fax) {
    $fax->resend(); 
}

$document = $client->documents->create('test.pdf', filesize('test.pdf'));
$stream = fopen('test.pdf', 'rb');
$current = 0;
while (!feof($stream)) {
    $chunk = fread($stream, 500);
    $end = $current + strlen($chunk);
    $doc->upload($current, $end-1, $chunk);
    $current = $end;
}
fclose($stream);

$params = [...]; // see documentation for possible params
$document = $client->documents->create($filename, filesize($filename), $params);
// Interfax\Document

$document->upload($start, $end, $data); // returns the document object.

$document->status;
$document->fileName;
$document->refresh()->attributes();

$document->location;
// or as returned by the API:
$document->uri;

// fluent methods that return the $fax instance
$fax->refresh(); // refreshes the data on the fax object
$fax->cancel(); // cancel the fax, returns true on success
$fax->hide(); // hides the faxes from the fax lists

$image = $fax->image(); // returns Interfax\Image
$new_fax = $fax->resend('+1111111'); // returns a new Interfax\Outbound\Fax
$fax->attributes(); // hash array of fax data properties - see details below

echo $fax->completionTime
echo $fax->duration
...

$fax->attributes();

// fluent methods that return the $fax instance for method chaining
$fax->refresh(); // reload properties of the inbound fax
$fax->markRead(); // mark the fax read - returns true or throws exception
$fax->markUnread(); // mark the fax unread - returns true or throws exception
$fax->resend();

$image = $fax->image(); // Returns a Interfax\Image for this fax
$email_array = $fax->emails(); // see below for details on the structure of this array
$fax->attributes(); // hash array of properties
file
file