PHP code example of quicreatdev / vatflow-php

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

    

quicreatdev / vatflow-php example snippets




use VatFlow\VatFlowClient;

// Initialize the client
$client = new VatFlowClient('YOUR_RAPIDAPI_KEY');


$vatNumber = 'FR14652014051';
$maxCacheDays = 7; // Request data no older than 7 days (default)
$autoRetry = true; // Automatically retry on 5xx network errors (default)

$response = $client->validate($vatNumber, $maxCacheDays, $autoRetry);

if ($response['success']) {
    echo "Company Name: " . $response['data']['name'] . "\n";
    echo "Address: " . $response['data']['address'] . "\n";
    echo "Is Valid: " . ($response['data']['is_valid'] ? 'Yes' : 'No') . "\n";
} else {
    echo "Error: " . $response['error'];
}


$vatNumber = 'FR14652014051';
$webhookUrl = 'https://api.yourdomain.com/webhooks/vatflow';

$response = $client->subscribeWebhook($vatNumber, $webhookUrl);

if ($response['success']) {
    echo "Subscribed! Subscription ID: " . $response['data']['subscription_id'];
}


$response = $client->listWebhooks();

if ($response['success']) {
    echo "You have " . $response['count'] . " active webhooks.\n";
    print_r($response['data']);
}


$vatNumber = 'FR14652014051';
$subscriptionId = 'a1b2c3d4-e5f6-7890-abcd-ef1234567890';

$response = $client->deleteWebhook($vatNumber, $subscriptionId);

if ($response['success']) {
    echo "Webhook successfully deleted.";
}


array(3) {
  ["success"] => bool(false)
  ["error"] => string(60) "The VAT number format is invalid for this country."
  ["status_code"] => int(400) // Provided for network or severe API errors
}

bash
composer