PHP code example of hometown / estimator

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

    

hometown / estimator example snippets


use Hometown\Estimator\Hometown;

$hometown = new Hometown(getenv('HOMETOWN_API_KEY'));

$estimate = $hometown->estimates->create(['input' => ['text' => 'sandbox:priced']]);

echo $estimate['status'], "\n"; // priced
echo $estimate['price']['min_cents'], "\n"; // 103680
foreach ($estimate['steps'] ?? [] as $step) {
    echo $step['text'], "\n";
}

/** @phpstan-import-type Estimate from \Hometown\Estimator\Types */

use Hometown\Estimator\Exception\HometownException;
use Hometown\Estimator\Exception\InsufficientCreditsException;

try {
    $estimate = $hometown->estimates->create(['input' => ['text' => 'Paint a 12 by 14 ft bedroom']]);
} catch (InsufficientCreditsException) {
    // buy credits in the dashboard
} catch (HometownException $error) {
    error_log("{$error->errorCode} {$error->requestId}");
}

use Hometown\Estimator\Exception\WebhookSignatureException;
use Hometown\Estimator\Webhook;

try {
    $event = Webhook::verify(file_get_contents('php://input'), $_SERVER['HTTP_HOMETOWN_SIGNATURE'] ?? null, $secret);
} catch (WebhookSignatureException) {
    http_response_code(400);
    exit;
}