1. Go to this page and download the library: Download antonowano/mindbox 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/ */
use Antonowano\Mindbox\Integration;
readonly class CustomIntegration implements Integration
{
public function endpointId(): string
{
return env('MINDBOX_ENDPOINT_ID');
}
public function secretKey(): string
{
return env('MINDBOX_SECRET_KEY');
}
public function defaultPrefix(): string
{
return env('MINDBOX_DEFAULT_PREFIX');
}
public function deviceUuid(): ?string
{
return $_COOKIE['mindboxDeviceUUID'] ?? null;
}
}
use Antonowano\Mindbox\AsyncOperation;
readonly class ViewProduct implements AsyncOperation
{
public function __construct(
private int $productId,
) {
}
public function name(string $defaultPrefix): string
{
return $defaultPrefix . 'ViewProduct';
}
public function needDeviceUuid(): bool
{
return true;
}
public function requestData(): array
{
return [
'viewProduct' => [
'productGroup' => [
'ids' => [
'brandProducts' => $this->productId,
],
],
],
];
}
}
use Antonowano\Mindbox\ApiClient;
use Antonowano\Mindbox\DefaultIntegration;
use Antonowano\Mindbox\Integration;
use Antonowano\Mindbox\MindboxApiClient;
use Antonowano\Mindbox\MindboxEndpointUrl;
use Antonowano\Mindbox\SilentApiClient;
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\HttpFactory;
use Illuminate\Support\Facades\Log;
public function register(): void
{
$this->app->singleton(Integration::class, function () {
return new DefaultIntegration(
endpointId: config('services.mindbox.endpoint_id'),
secretKey: config('services.mindbox.secret_key'),
defaultPrefix: config('services.mindbox.default_prefix'),
deviceUuid: $_COOKIE['mindboxDeviceUUID'] ?? null,
);
});
$this->app->singleton(ApiClient::class, function ($app) {
$integration = $app->make(Integration::class);
$httpFactory = new HttpFactory();
$client = new MindboxApiClient(
integration: $integration,
endpointUrl: new MindboxEndpointUrl($integration),
httpClient: new Client(),
requestFactory: $httpFactory,
streamFactory: $httpFactory,
);
return $client;
// или, если никогда не хотите обрабатывать Exception, тогда так:
// return new SilentApiClient($client, Log::channel());
});
}
public function product(int $productId, ApiClient $client) {
$client = new SilentApiClient($client, Log::channel());
$client->async(new ViewProduct($productId));
}
bash
php artisan config:cache
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.