feat: Add User-Agent header to Allegro API requests
- Implemented buildUserAgent() method in AllegroApiClient, AllegroOAuthClient, and AllegroTrackingService to include User-Agent header in all HTTP requests to Allegro API. - Updated .env.example to include APP_VERSION and ALLEGRO_USER_AGENT_URL for configuration. - Created public /info page to provide application details required by Allegro, including app name, version, description, and contact information. - Added minimalist layout for public pages to ensure a professional appearance. - Ensured all changes comply with Allegro's API requirements for User-Agent header.
This commit is contained in:
27
src/Modules/Info/InfoController.php
Normal file
27
src/Modules/Info/InfoController.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Modules\Info;
|
||||
|
||||
use App\Core\Http\Request;
|
||||
use App\Core\Http\Response;
|
||||
use App\Core\View\Template;
|
||||
|
||||
final class InfoController
|
||||
{
|
||||
public function __construct(
|
||||
private readonly Template $template
|
||||
) {
|
||||
}
|
||||
|
||||
public function show(Request $request): Response
|
||||
{
|
||||
$html = $this->template->render('info/allegro', [
|
||||
'title' => 'orderPRO — Informacje o aplikacji',
|
||||
'appName' => (string) (getenv('APP_NAME') ?: 'orderPRO'),
|
||||
'appVersion' => (string) (getenv('APP_VERSION') ?: '1.0.0'),
|
||||
], 'layouts/public');
|
||||
|
||||
return Response::html($html);
|
||||
}
|
||||
}
|
||||
@@ -187,6 +187,15 @@ final class AllegroApiClient
|
||||
return $opts;
|
||||
}
|
||||
|
||||
private function buildUserAgent(): string
|
||||
{
|
||||
$name = getenv('APP_NAME') ?: 'orderPRO';
|
||||
$version = getenv('APP_VERSION') ?: '1.0.0';
|
||||
$url = getenv('ALLEGRO_USER_AGENT_URL') ?: 'https://orderpro.pl/info';
|
||||
|
||||
return $name . '/' . $version . ' (+' . $url . ')';
|
||||
}
|
||||
|
||||
private function apiBaseUrl(string $environment): string
|
||||
{
|
||||
return trim(strtolower($environment)) === 'production'
|
||||
@@ -217,6 +226,7 @@ final class AllegroApiClient
|
||||
'Accept: application/vnd.allegro.public.v1+json',
|
||||
'Content-Type: application/vnd.allegro.public.v1+json',
|
||||
'Authorization: Bearer ' . $accessToken,
|
||||
'User-Agent: ' . $this->buildUserAgent(),
|
||||
],
|
||||
]));
|
||||
|
||||
@@ -282,6 +292,7 @@ final class AllegroApiClient
|
||||
'Accept: application/vnd.allegro.public.v1+json',
|
||||
'Content-Type: application/vnd.allegro.public.v1+json',
|
||||
'Authorization: Bearer ' . $accessToken,
|
||||
'User-Agent: ' . $this->buildUserAgent(),
|
||||
],
|
||||
]));
|
||||
|
||||
@@ -346,6 +357,7 @@ final class AllegroApiClient
|
||||
'Accept: application/octet-stream',
|
||||
'Content-Type: application/vnd.allegro.public.v1+json',
|
||||
'Authorization: Bearer ' . $accessToken,
|
||||
'User-Agent: ' . $this->buildUserAgent(),
|
||||
],
|
||||
]));
|
||||
|
||||
@@ -393,6 +405,7 @@ final class AllegroApiClient
|
||||
CURLOPT_HTTPHEADER => [
|
||||
'Accept: application/vnd.allegro.public.v1+json',
|
||||
'Authorization: Bearer ' . $accessToken,
|
||||
'User-Agent: ' . $this->buildUserAgent(),
|
||||
],
|
||||
]));
|
||||
|
||||
|
||||
@@ -128,6 +128,15 @@ final class AllegroOAuthClient
|
||||
return trim(strtolower($environment)) === 'production' ? 'production' : 'sandbox';
|
||||
}
|
||||
|
||||
private function buildUserAgent(): string
|
||||
{
|
||||
$name = getenv('APP_NAME') ?: 'orderPRO';
|
||||
$version = getenv('APP_VERSION') ?: '1.0.0';
|
||||
$url = getenv('ALLEGRO_USER_AGENT_URL') ?: 'https://orderpro.pl/info';
|
||||
|
||||
return $name . '/' . $version . ' (+' . $url . ')';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, string> $formData
|
||||
* @return array<string, mixed>
|
||||
@@ -154,6 +163,7 @@ final class AllegroOAuthClient
|
||||
'Accept: application/json',
|
||||
'Content-Type: application/x-www-form-urlencoded',
|
||||
'Authorization: Basic ' . base64_encode($clientId . ':' . $clientSecret),
|
||||
'User-Agent: ' . $this->buildUserAgent(),
|
||||
],
|
||||
CURLOPT_POSTFIELDS => http_build_query($formData),
|
||||
];
|
||||
|
||||
@@ -101,6 +101,7 @@ final class AllegroOrderImportService
|
||||
'source' => IntegrationSources::ALLEGRO,
|
||||
'created' => $wasCreated,
|
||||
'integration_id' => (int) ($mapped['order']['integration_id'] ?? 0),
|
||||
'new_payment_status' => (string) ($mapped['order']['payment_status'] ?? ''),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -275,6 +275,7 @@ final class ShopproOrdersSyncService
|
||||
'source' => 'shoppro',
|
||||
'created' => $wasCreated,
|
||||
'integration_id' => $integrationId,
|
||||
'new_payment_status' => (string) ($aggregate['order']['payment_status'] ?? ''),
|
||||
]);
|
||||
}
|
||||
} catch (Throwable $exception) {
|
||||
|
||||
@@ -136,6 +136,7 @@ final class AllegroTrackingService implements ShipmentTrackingInterface
|
||||
CURLOPT_HTTPHEADER => [
|
||||
'Accept: application/vnd.allegro.internal.v1+json',
|
||||
'Content-Type: application/vnd.allegro.internal.v1+json',
|
||||
'User-Agent: ' . $this->buildUserAgent(),
|
||||
],
|
||||
];
|
||||
|
||||
@@ -186,6 +187,7 @@ final class AllegroTrackingService implements ShipmentTrackingInterface
|
||||
CURLOPT_HTTPHEADER => [
|
||||
'Authorization: Bearer ' . $token,
|
||||
'Accept: application/json',
|
||||
'User-Agent: ' . $this->buildUserAgent(),
|
||||
],
|
||||
];
|
||||
|
||||
@@ -207,4 +209,12 @@ final class AllegroTrackingService implements ShipmentTrackingInterface
|
||||
return is_array($json) ? $json : [];
|
||||
}
|
||||
|
||||
private function buildUserAgent(): string
|
||||
{
|
||||
$name = getenv('APP_NAME') ?: 'orderPRO';
|
||||
$version = getenv('APP_VERSION') ?: '1.0.0';
|
||||
$url = getenv('ALLEGRO_USER_AGENT_URL') ?: 'https://orderpro.pl/info';
|
||||
|
||||
return $name . '/' . $version . ' (+' . $url . ')';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user