This commit is contained in:
2026-04-09 00:51:24 +02:00
parent 633da52880
commit 854adc32c1
11 changed files with 366 additions and 45 deletions

View File

@@ -197,6 +197,11 @@ final class AllegroOrderImportService
$updatedAt = StringHelper::normalizeDateTime((string) ($payload['updatedAt'] ?? ''));
$fetchedAt = date('Y-m-d H:i:s');
$mappedPaymentStatus = $this->mapPaymentStatus($paymentStatusRaw);
if ($mappedPaymentStatus === null) {
$mappedPaymentStatus = $this->derivePaymentStatusFromAmounts($totalWithTax, $totalPaid);
}
$order = [
'integration_id' => $this->integrationRepository->getActiveIntegrationId(),
'source' => IntegrationSources::ALLEGRO,
@@ -206,7 +211,7 @@ final class AllegroOrderImportService
'external_platform_account_id' => null,
'external_status_id' => $externalStatus,
'external_payment_type_id' => trim((string) ($payment['type'] ?? '')),
'payment_status' => $this->mapPaymentStatus($paymentStatusRaw),
'payment_status' => $mappedPaymentStatus,
'external_carrier_id' => $deliveryForm !== '' ? $deliveryForm : null,
'external_carrier_account_id' => $deliveryMethodId !== '' ? $deliveryMethodId : null,
'customer_login' => trim((string) ($buyer['login'] ?? '')),
@@ -714,13 +719,28 @@ final class AllegroOrderImportService
private function mapPaymentStatus(string $status): ?int
{
return match ($status) {
'paid', 'finished', 'completed' => 2,
'partially_paid', 'in_progress' => 1,
'paid', 'finished', 'completed', 'ready_for_processing' => 2,
'partially_paid', 'in_progress', 'bought', 'filled_in' => 1,
'cancelled', 'canceled', 'failed', 'unpaid' => 0,
default => null,
};
}
private function derivePaymentStatusFromAmounts(?float $totalWithTax, ?float $totalPaid): ?int
{
if ($totalWithTax === null || $totalWithTax <= 0.0) {
return null;
}
if ($totalPaid === null || $totalPaid <= 0.0) {
return 0;
}
if ($totalPaid >= $totalWithTax) {
return 2;
}
return 1;
}
private function amountToFloat(mixed $amountNode): ?float
{
if (!is_array($amountNode)) {