PHP code example of outboundiq / laravel-outboundiq

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

    

outboundiq / laravel-outboundiq example snippets


use Illuminate\Support\Facades\Http;

$response = Http::post('https://api.example.com/checkout', [
    'order_id' => 123,
]);

use OutboundIQ\Laravel\Facades\OutboundIQ;

$decision = OutboundIQ::recommend('Payment Processing');

if (!$decision) {
    // OutboundIQ unavailable → use your default logic
    return $this->chargeWith('stripe', $order);
}

$action   = $decision['decision']['action'] ?? 'unavailable';
$provider = $decision['decision']['use'] ?? 'stripe';

return match ($action) {
    'proceed' => $this->chargeWith($provider, $order),
    'caution' => $this->chargeWithRetry($provider, $order, attempts: 3),
    'avoid'   => $this->chargeWith($decision['alternatives'][0]['provider']['slug'] ?? 'stripe', $order),
    default   => $this->chargeWith('stripe', $order),
};

use OutboundIQ\Laravel\Facades\OutboundIQ;

$status = OutboundIQ::providerStatus('twilio');

if (!$status) {
    return $this->sendViaTwilio($phone, $message); // default behavior
}

if (($status['decision']['action'] ?? null) === 'avoid') {
    return $this->sendViaBackupProvider($phone, $message);
}

// proceed | caution → your policy (retry, reduced timeouts, etc.)
return $this->sendViaTwilio($phone, $message);

use OutboundIQ\Laravel\Facades\OutboundIQ;
use Illuminate\Support\Facades\Http;

$status = OutboundIQ::endpointStatus('stripe-post-v1-charges');

$timeout = 5;
if ($status && ($status['metrics']['avg_latency_ms'] ?? 0) > 0) {
    // Simple heuristic: 2× avg latency, converted to seconds (min 1)
    $timeout = max(1, (int) ceil(($status['metrics']['avg_latency_ms'] * 2) / 1000));
}

return Http::timeout($timeout)->post('https://api.stripe.com/v1/charges', $data);

use OutboundIQ\Laravel\Http\OutboundIQGuzzleClient;

$guzzle = app(OutboundIQGuzzleClient::class);

$response = $guzzle->get('https://api.example.com/data');
$response = $guzzle->post('https://api.example.com/send', [
    'json' => ['message' => 'Hello!'],
]);

use OutboundIQ\Laravel\Facades\OutboundIQ;

OutboundIQ::trackApiCall(
    url: 'https://api.example.com/endpoint',
    method: 'POST',
    duration: 150.5,
    statusCode: 200,
    requestHeaders: ['Content-Type' => 'application/json'],
    requestBody: '{"key":"value"}',
    responseHeaders: ['Content-Type' => 'application/json'],
    responseBody: '{"status":"success"}'
);
bash
php artisan vendor:publish --tag="outboundiq-config"
# or
php artisan vendor:publish --provider="OutboundIQ\Laravel\Providers\OutboundIQServiceProvider" --tag="config"
bash
php artisan outboundiq:test
bash
php artisan outboundiq:test