# InterFAX notification channel for Laravel 9.x, 10.x

Latest Version on Packagist (opens new window) Software License (opens new window) Build Status (opens new window) Total Downloads (opens new window)

This package makes it easy to send notifications using InterFAX (opens new window) with Laravel 9.x and 10.x.

# Contents

# Installation

You can install this package via composer:

composer require laravel-notification-channels/interfax

The service provider gets loaded automatically.

# Setting up the InterFAX service

This channel will use your InterFAX username and password. To use the channel, add this to your config/services.php file:

...
'interfax' => [
    'username' => env('INTERFAX_USERNAME'),
    'password' => env('INTERFAX_PASSWORD'),
    'pci'      => env('INTERFAX_PCI', false),
    'interval' => 15,
    'chunk_size' => null,
],
...

This will load your InterFAX credentials from the .env file. If your requests must be PCI-DSS-compliant, set INTERFAX_PCI=true in your .env file.

The services.interfax.interval configuration setting is the polling interval, in seconds, for a fax if it is set to check the status until it is complete. This is optional and will default to 15 if left empty. The interval has a minimum of 10 seconds, as the outbound service in the API has a maximum freqncy of 6 requests per minute and can return errors if polled more frequently.

Faxes can sometimes take more than 10 minutes to send, so it is recommended to configure a long-running queue and to push your fax notifications to that queue. More information on configuring long-running queues can be found here (opens new window).

The services.interfax.chunk_size configuration setting is the maximum file size before the InterFAX core SDK starts chunking files. The default chunk size is 1048576. When chunking, an \Interfax\Document object is created, but the /outbound/documents endpoint does not exist for the PCI-DSS-compliant API. If services.interfax.pci is set to true, it is recommended to increase the chunk size to avoid 404 errors.

# Usage

To use this package, you can create a notification class, like DocumentWasSent from the example below, in your Laravel application. Make sure to check out Laravel's documentation (opens new window) for this process.

# Send PDF via fax

<?php
use NotificationChannels\Interfax\InterfaxChannel;
use NotificationChannels\Interfax\InterfaxMessage;
use NotificationChannels\Interfax\Contracts\InterfaxNotificationContract;

class DocumentWasSent extends Notification implements InterfaxNotificationContract
{

    protected $files;

    public function __construct(array $files)
    {
        $this->files = $files;
    }

    /**
     * Get the notification's delivery channels.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function via($notifiable)
    {
        return [InterfaxChannel::class];
    }

    public function toInterfax($notifiable): InterfaxMessage
    {
        return (new InterfaxMessage)
              ->files($this->files);
    }
}

The Notifiable model will need to return a destination fax number.

public function routeNotificationForInterfax($notification)
{
    if($this->fax)
        return preg_replace('/[^\d]/', '', $this->fax);

    return null;
}

# Available Message methods

file(string $file) : Accepts the full path to a single file (full list of supported file types found here (opens new window)).
files(array $array) : Accepts an array of file paths. If overriding the default chunk_size in the config and using an \Interfax\File object in the array, use \NotificationChannels\Interfax\InterfaxFile instead to automatically set the file's chunk size on initialization.
stream(Filestream $stream, string $name) : Accepts a file stream.
addMetadata(array $data): Add metadata for logging purposes in case of an error.

# Changelog

Please see CHANGELOG (opens new window) for more information what has changed recently.

# Testing

$ composer test

# Security

If you discover any security related issues, please email craig.spivack@ivinteractive.com instead of using the issue tracker.

# Contributing

Please see CONTRIBUTING (opens new window) for details.

# Credits

# License

The MIT License (MIT). Please see License File (opens new window) for more information.