1. Go to this page and download the library: Download avtocod/b2b-api-php-laravel 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/ */
avtocod / b2b-api-php-laravel example snippets
declare(strict_types = 1);
namespace App\Console\Commands;
use Avtocod\B2BApi\Params\UserReportMakeParams;
use Avtocod\B2BApi\Laravel\ReportTypes\RepositoryInterface;
use Avtocod\B2BApi\Laravel\Connections\ConnectionsFactoryInterface;
class SomeCommand extends \Illuminate\Console\Command
{
/**
* The console command name.
*
* @var string
*/
protected $name = 'some:command';
/**
* Execute the console command.
*
* @param RepositoryInterface $report_types
* @param ConnectionsFactoryInterface $connections
*
* @return void
*/
public function handle(RepositoryInterface $report_types, ConnectionsFactoryInterface $connections): void
{
$uid = $report_types->default()->getUid(); // Get default report type UID
// Create a parameter object for a request to make a report
$report_make_params = UserReportMakeParams($uid, 'VIN', 'Z94CB41AAGR323020')
$report_uid = $connections->default()
->userReportMake($report_make_params)
->first()
->getReportUid();
$this->comment("Report UID: {$report_uid}");
}
}
declare(strict_types = 1);
namespace App\Listeners;
use Psr\Log\LoggerInterface;
use Psr\Http\Message\ResponseInterface;
use Avtocod\B2BApi\Events\RequestFailedEvent;
class LogFailedB2bApiRequestListener
{
/**
* @var LoggerInterface
*/
protected $logger;
/**
* Create a new listener instance.
*
* @param LoggerInterface $logger
*/
public function __construct(LoggerInterface $logger)
{
$this->logger = $logger;
}
/**
* @param RequestFailedEvent $event
*
* @return void
*/
public function handle(RequestFailedEvent $event): void
{
$this->logger->warning('Request to the Avtocod B2B API Failed', [
'request_uri' => $event->getRequest()->getUri(),
'response_code' => $event->getResponse() instanceof ResponseInterface
? $event->getResponse()->getStatusCode()
: null
]);
}
}