PHP code example of hyperized / wefact
1. Go to this page and download the library: Download hyperized/wefact 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/ */
hyperized / wefact example snippets
return [
'api_v2_url' => env('HOSTFACT_URL', 'https://yoursite.tld/Pro/apiv2/api.php'),
'api_v2_key' => env('HOSTFACT_KEY', 'token'),
'api_v2_timeout' => env('HOSTFACT_TIMEOUT', 20),
];
use Hyperized\Hostfact\Api\Controllers\Product;
use Hyperized\Hostfact\Api\Entity\Product as ProductEntity;
use Hyperized\Hostfact\Api\Response\ListResponse;
$response = Product::new()->list(['searchfor' => 'hosting']);
if ($response instanceof ListResponse) {
echo $response->pagination->totalResults . ' results';
foreach ($response->entities as $product) {
assert($product instanceof ProductEntity);
echo $product->ProductName;
echo $product->PriceExcl;
}
}
use Hyperized\Hostfact\Api\Controllers\Invoice;
$invoice = Invoice::fromHttpClient($httpClient);
$result = $invoice->show(['Identifier' => 'F0001']);
use Hyperized\Hostfact\Api\Controllers\Invoice;
use Hyperized\Hostfact\Api\Entity\Invoice as InvoiceEntity;
use Hyperized\Hostfact\Api\Response\ShowResponse;
$response = Invoice::new()->show(['InvoiceCode' => 'F0001']);
assert($response instanceof ShowResponse);
$invoice = $response->entity;
assert($invoice instanceof InvoiceEntity);
$invoice->Identifier; // ?int
$invoice->InvoiceCode; // ?string
$invoice->Status; // ?InvoiceStatus (enum)
$invoice->Date; // ?DateTimeImmutable
$invoice->AmountExcl; // ?string (for bcmath precision)
$invoice->Sent; // ?bool
// Nested entities
foreach ($invoice->InvoiceLines as $line) {
$line->Description; // ?string
$line->PriceExcl; // ?string
}
// Fallback to DataBag for undocumented fields
$invoice->bag->string('SomeUndocumentedField');
$response = Product::new()->list(['searchfor' => 'hosting']);
assert($response instanceof ListResponse);
foreach ($response->entities as $product) {
assert($product instanceof ProductEntity);
echo $product->ProductCode;
echo $product->ProductName;
}
$bag->string('ProductCode') // string
$bag->int('Identifier') // int
$bag->float('PriceExcl') // float
$bag->bool('AutoRenew') // bool (handles "yes"/"no", 1/0)
$bag->nullableString('Comment') // ?string
$bag->nullableInt('PackageID') // ?int
$bag->nullableBool('Sent') // ?bool
$bag->nullableDateTime('Created') // ?DateTimeImmutable
$bag->array('Groups') // array
$bag->bag('Subscription') // nested DataBag
$bag->bags('InvoiceLines') // list<DataBag>
$bag->has('SomeField') // bool
$bag['ProductCode'] // mixed (ArrayAccess)
bash
php artisan vendor:publish --provider="Hyperized\Hostfact\Providers\HostfactServiceProvider" --tag="config"
env
HOSTFACT_URL=https://yoursite.tld/Pro/apiv2/api.php
HOSTFACT_KEY=your-api-token
HOSTFACT_TIMEOUT=20