ver. 0.313: fix sync płatności Apilo + logowanie decyzji sync
Fix: (int) cast na apilo_order_id (format "PPxxxxxx") dawał 0, przez co syncApiloPayment() i syncApiloStatus() pomijały wywołanie API Apilo. Zmiana na empty() w obu metodach. New: logowanie ApiloLogger w syncApiloPaymentIfNeeded() i syncApiloStatusIfNeeded() — każda ścieżka decyzyjna zapisuje wpis do pp_log z kontekstem. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -89,6 +89,19 @@ $orderId = (int)($this -> order['id'] ?? 0);
|
|||||||
<div>
|
<div>
|
||||||
<b><?= $this -> order[ 'payment_method' ];?> </b>
|
<b><?= $this -> order[ 'payment_method' ];?> </b>
|
||||||
</div>
|
</div>
|
||||||
|
<? if ( !empty($this -> order['apilo_order_id']) ):?>
|
||||||
|
<br/>
|
||||||
|
<div>
|
||||||
|
<i class="fa fa-cloud"></i> Apilo: <b style="color: #27ae60;">tak</b>
|
||||||
|
— ID: <b id="order-apilo-id"><?= htmlspecialchars((string)$this -> order['apilo_order_id'], ENT_QUOTES, 'UTF-8');?></b>
|
||||||
|
<i class="fa fa-copy" onclick="copyToClipboard( 'order-apilo-id' ); return false;"></i>
|
||||||
|
</div>
|
||||||
|
<? else:?>
|
||||||
|
<br/>
|
||||||
|
<div>
|
||||||
|
<i class="fa fa-cloud"></i> Apilo: <b style="color: #c0392b;">nie</b>
|
||||||
|
</div>
|
||||||
|
<? endif;?>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="paid-status panel">
|
<div class="paid-status panel">
|
||||||
|
|||||||
@@ -393,17 +393,38 @@ class OrderAdminService
|
|||||||
global $mdb;
|
global $mdb;
|
||||||
|
|
||||||
if ($orderId <= 0) {
|
if ($orderId <= 0) {
|
||||||
|
\Domain\Integrations\ApiloLogger::log(
|
||||||
|
$mdb,
|
||||||
|
'resend_order',
|
||||||
|
$orderId,
|
||||||
|
'Nieprawidlowe ID zamowienia (orderId <= 0)',
|
||||||
|
['order_id' => $orderId]
|
||||||
|
);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$order = $this->orders->findForAdmin($orderId);
|
$order = $this->orders->findForAdmin($orderId);
|
||||||
if (empty($order) || empty($order['apilo_order_id'])) {
|
if (empty($order) || empty($order['apilo_order_id'])) {
|
||||||
|
\Domain\Integrations\ApiloLogger::log(
|
||||||
|
$mdb,
|
||||||
|
'resend_order',
|
||||||
|
$orderId,
|
||||||
|
'Brak zamowienia lub brak apilo_order_id',
|
||||||
|
['order_found' => !empty($order), 'apilo_order_id' => $order['apilo_order_id'] ?? null]
|
||||||
|
);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$integrationsRepository = new \Domain\Integrations\IntegrationsRepository( $mdb );
|
$integrationsRepository = new \Domain\Integrations\IntegrationsRepository( $mdb );
|
||||||
$accessToken = $integrationsRepository -> apiloGetAccessToken();
|
$accessToken = $integrationsRepository -> apiloGetAccessToken();
|
||||||
if (!$accessToken) {
|
if (!$accessToken) {
|
||||||
|
\Domain\Integrations\ApiloLogger::log(
|
||||||
|
$mdb,
|
||||||
|
'resend_order',
|
||||||
|
$orderId,
|
||||||
|
'Nie udalo sie uzyskac tokenu Apilo (access token)',
|
||||||
|
['apilo_order_id' => $order['apilo_order_id']]
|
||||||
|
);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -641,6 +662,17 @@ class OrderAdminService
|
|||||||
$apilo_settings = $integrationsRepository->getSettings('apilo');
|
$apilo_settings = $integrationsRepository->getSettings('apilo');
|
||||||
|
|
||||||
if (!$apilo_settings['enabled'] || !$apilo_settings['access-token'] || !$apilo_settings['sync_orders']) {
|
if (!$apilo_settings['enabled'] || !$apilo_settings['access-token'] || !$apilo_settings['sync_orders']) {
|
||||||
|
\Domain\Integrations\ApiloLogger::log(
|
||||||
|
$db,
|
||||||
|
'payment_sync',
|
||||||
|
(int)$order['id'],
|
||||||
|
'Pominięto sync płatności — Apilo wyłączone lub brak tokenu/sync_orders',
|
||||||
|
[
|
||||||
|
'enabled' => $apilo_settings['enabled'] ?? false,
|
||||||
|
'has_token' => !empty($apilo_settings['access-token']),
|
||||||
|
'sync_orders' => $apilo_settings['sync_orders'] ?? false,
|
||||||
|
]
|
||||||
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -650,8 +682,22 @@ class OrderAdminService
|
|||||||
|
|
||||||
if (!$order['apilo_order_id']) {
|
if (!$order['apilo_order_id']) {
|
||||||
// Zamówienie jeszcze nie wysłane do Apilo — kolejkuj sync płatności na później
|
// Zamówienie jeszcze nie wysłane do Apilo — kolejkuj sync płatności na później
|
||||||
|
\Domain\Integrations\ApiloLogger::log(
|
||||||
|
$db,
|
||||||
|
'payment_sync',
|
||||||
|
(int)$order['id'],
|
||||||
|
'Brak apilo_order_id — płatność zakolejkowana do sync',
|
||||||
|
['apilo_order_id' => $order['apilo_order_id'] ?? null]
|
||||||
|
);
|
||||||
self::queueApiloSync((int)$order['id'], true, null, 'awaiting_apilo_order');
|
self::queueApiloSync((int)$order['id'], true, null, 'awaiting_apilo_order');
|
||||||
} elseif (!$this->syncApiloPayment($order)) {
|
} elseif (!$this->syncApiloPayment($order)) {
|
||||||
|
\Domain\Integrations\ApiloLogger::log(
|
||||||
|
$db,
|
||||||
|
'payment_sync',
|
||||||
|
(int)$order['id'],
|
||||||
|
'Sync płatności nieudany — zakolejkowano ponowną próbę',
|
||||||
|
['apilo_order_id' => $order['apilo_order_id']]
|
||||||
|
);
|
||||||
self::queueApiloSync((int)$order['id'], true, null, 'payment_sync_failed');
|
self::queueApiloSync((int)$order['id'], true, null, 'payment_sync_failed');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -665,6 +711,18 @@ class OrderAdminService
|
|||||||
$apilo_settings = $integrationsRepository->getSettings('apilo');
|
$apilo_settings = $integrationsRepository->getSettings('apilo');
|
||||||
|
|
||||||
if (!$apilo_settings['enabled'] || !$apilo_settings['access-token'] || !$apilo_settings['sync_orders']) {
|
if (!$apilo_settings['enabled'] || !$apilo_settings['access-token'] || !$apilo_settings['sync_orders']) {
|
||||||
|
\Domain\Integrations\ApiloLogger::log(
|
||||||
|
$db,
|
||||||
|
'status_sync',
|
||||||
|
(int)$order['id'],
|
||||||
|
'Pominięto sync statusu — Apilo wyłączone lub brak tokenu/sync_orders',
|
||||||
|
[
|
||||||
|
'target_status' => $status,
|
||||||
|
'enabled' => $apilo_settings['enabled'] ?? false,
|
||||||
|
'has_token' => !empty($apilo_settings['access-token']),
|
||||||
|
'sync_orders' => $apilo_settings['sync_orders'] ?? false,
|
||||||
|
]
|
||||||
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -674,8 +732,22 @@ class OrderAdminService
|
|||||||
|
|
||||||
if (!$order['apilo_order_id']) {
|
if (!$order['apilo_order_id']) {
|
||||||
// Zamówienie jeszcze nie wysłane do Apilo — kolejkuj sync statusu na później
|
// Zamówienie jeszcze nie wysłane do Apilo — kolejkuj sync statusu na później
|
||||||
|
\Domain\Integrations\ApiloLogger::log(
|
||||||
|
$db,
|
||||||
|
'status_sync',
|
||||||
|
(int)$order['id'],
|
||||||
|
'Brak apilo_order_id — status zakolejkowany do sync',
|
||||||
|
['apilo_order_id' => $order['apilo_order_id'] ?? null, 'target_status' => $status]
|
||||||
|
);
|
||||||
self::queueApiloSync((int)$order['id'], false, $status, 'awaiting_apilo_order');
|
self::queueApiloSync((int)$order['id'], false, $status, 'awaiting_apilo_order');
|
||||||
} elseif (!$this->syncApiloStatus($order, $status)) {
|
} elseif (!$this->syncApiloStatus($order, $status)) {
|
||||||
|
\Domain\Integrations\ApiloLogger::log(
|
||||||
|
$db,
|
||||||
|
'status_sync',
|
||||||
|
(int)$order['id'],
|
||||||
|
'Sync statusu nieudany — zakolejkowano ponowną próbę',
|
||||||
|
['apilo_order_id' => $order['apilo_order_id'], 'target_status' => $status]
|
||||||
|
);
|
||||||
self::queueApiloSync((int)$order['id'], false, $status, 'status_sync_failed');
|
self::queueApiloSync((int)$order['id'], false, $status, 'status_sync_failed');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -687,7 +759,7 @@ class OrderAdminService
|
|||||||
$db = $this->orders->getDb();
|
$db = $this->orders->getDb();
|
||||||
$integrationsRepository = new \Domain\Integrations\IntegrationsRepository($db);
|
$integrationsRepository = new \Domain\Integrations\IntegrationsRepository($db);
|
||||||
|
|
||||||
if (!(int)$order['apilo_order_id']) {
|
if (empty($order['apilo_order_id'])) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -754,7 +826,7 @@ class OrderAdminService
|
|||||||
$db = $this->orders->getDb();
|
$db = $this->orders->getDb();
|
||||||
$integrationsRepository = new \Domain\Integrations\IntegrationsRepository($db);
|
$integrationsRepository = new \Domain\Integrations\IntegrationsRepository($db);
|
||||||
|
|
||||||
if (!(int)$order['apilo_order_id']) {
|
if (empty($order['apilo_order_id'])) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,13 @@ Logi zmian z migracji na Domain-Driven Architecture. Najnowsze na gorze.
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
## ver. 0.313 (2026-02-23) - Fix sync płatności Apilo + logowanie
|
||||||
|
|
||||||
|
- **FIX**: `syncApiloPayment()` i `syncApiloStatus()` — `(int)` cast na `apilo_order_id` (format `"PPxxxxxx"`) dawał `0`, przez co metody pomijały sync z API Apilo. Zmiana na `empty()`
|
||||||
|
- **NEW**: Logowanie w `syncApiloPaymentIfNeeded()` i `syncApiloStatusIfNeeded()` — każda ścieżka decyzyjna (Apilo wyłączone, brak tokenu, brak `apilo_order_id`, sync nieudany) zapisuje wpis do `pp_log` z kontekstem
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## ver. 0.312 (2026-02-23) - Fix krytycznych bugów integracji Apilo
|
## ver. 0.312 (2026-02-23) - Fix krytycznych bugów integracji Apilo
|
||||||
|
|
||||||
- **FIX**: `curl_getinfo()` wywoływane po `curl_close()` — HTTP code zawsze wynosił 0, uniemożliwiając prawidłową obsługę odpowiedzi Apilo
|
- **FIX**: `curl_getinfo()` wywoływane po `curl_close()` — HTTP code zawsze wynosił 0, uniemożliwiając prawidłową obsługę odpowiedzi Apilo
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<?
|
<?
|
||||||
$current_ver = 312;
|
$current_ver = 313;
|
||||||
|
|
||||||
for ($i = 1; $i <= $current_ver; $i++)
|
for ($i = 1; $i <= $current_ver; $i++)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user