avtocod/b2b-api-php-laravel
B2B Api client integration for Laravel applications
Install
Require this package with composer using the following command:
$ composer require avtocod/b2b-api-php-laravel "^4.0"
Installed
composeris required (how to install composer).
You need to fix the major version of package.
After that you should "publish" package configuration file using next command:
$ php ./artisan vendor:publish --provider='Avtocod\B2BApi\Laravel\ServiceProvider'
And modify ./config/b2b-api-client.php.
Usage
This package provides:
- Connections factory (
ConnectionsFactoryInterface) - B2B API client factory (configuration for it loads from published configuration file); - Report types repository (
RepositoryInterface) - single entry-point for getting access to the report types information;
In any part of your application you can resolve their implementations. For example, in artisan command:
<?php
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}");
}
}
Events
Also this package proxying B2B Api client events into Laravel events dispatcher. So, feel free for writing own listeners like:
<?php
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
]);
}
}
More information about events listeners can be found here
Testing
For package testing we use phpunit framework and docker-ce + docker-compose as develop environment. So, just write into your terminal after repository cloning:
$ make build
$ make latest # or 'make lowest'
$ make test
Changes log
Changes log can be found here.
Support
If you will find any package errors, please, make an issue in current repository.
License
This is open-sourced software licensed under the MIT License.
Related Packages
Mollie API client wrapper for Laravel & Mollie Connect provider for Laravel Soci...
Cloud native, API first Laravel eCommerce package with integrated AI for ultra-f...
Adds a Laravel specific wrapper for the Hubspot client package
Version History
| Version | Released | PHP | Laravel | License |
|---|---|---|---|---|
| v4.7.0 | ^8.2 | ^11.0 | | MIT | |
| v4.6.0 | ^8.1 | ^10.0 | | MIT | |
| v4.5.0 | ^8.1 | ^10.0 | | MIT | |
| v4.4.0 | ^8.1 | ^10.0 | MIT | |
| v4.3.0 | ^7.3| | ~6.0 | | MIT | |
| v4.2.0 | ^7.2 | ~6.0 | | MIT | |
| v4.1.0 | ^7.2 | ~6.0 | | MIT | |
| v4.0.0 | ^7.2 | ~6.0 | | MIT | |
| v3.4.0 | ^7.2 | ~6.0 | | MIT | |
| v3.3.0 | ^7.1.3 | ^5.5 | | MIT | |
| v3.2.0 | ^7.1.3 | ^5.4 | | MIT | |
| v3.1.0 | ^7.1.3 | ^5.4 | | MIT | |
| v3.0.0 | ^7.1.3 | >=5.4.0 <5.9.0 | MIT | |
| v2.2.0 | ^5.6 | | >=5.4.0 <5.8.0 | MIT | |
| v2.1.0 | ^5.6 | | >=5.4.0 <5.7.0 | MIT | |
| v2.0.4 | ^5.6 | | >=5.4.0 <5.7.0 | MIT | |
| v2.0.3 | ^5.6 | | >=5.4.0 <5.7.0 | MIT | |
| v2.0.2 | ^5.6 | | 5.4.* | | MIT | |
| v2.0.1 | ^5.6 | | ~5.4 | MIT | |
| v2.0.0 | ^5.6 | | ~5.4 | MIT |