---
phase: 57-payment-automation-event
plan: 01
status: complete
completed: 2026-03-30
---

# Phase 57 Plan 01: Payment Automation Event Summary

**Event automatyzacji `payment.status_changed` z warunkiem `payment_status` — emisja z recznego dodania platnosci i cron sync shopPRO**

## Acceptance Criteria Results

| Criterion | Status | Notes |
|-----------|--------|-------|
| AC-1: Event payment.status_changed dostepny w formularzu | Pass | Opcja "Zmiana statusu platnosci" w dropdown zdarzenia |
| AC-2: Warunek payment_status dostepny w formularzu | Pass | Checkboxy: Nieoplacone, Czesciowo oplacone, Oplacone |
| AC-3: Event emitowany przy recznym dodaniu platnosci | Pass | trigger() w OrdersController::addPayment() po zapisie |
| AC-4: Event emitowany przy sync platnosci z shopPRO | Pass | trigger() w ShopproPaymentStatusSyncService po zmianie statusu |
| AC-5: Warunek filtruje poprawnie | Pass | evaluatePaymentStatusCondition porownuje new_payment_status z status_keys |

## Files Created/Modified

| File | Change | Purpose |
|------|--------|---------|
| src/Modules/Automation/AutomationController.php | Modified | ALLOWED_EVENTS + payment.status_changed, ALLOWED_CONDITION_TYPES + payment_status, PAYMENT_STATUS_OPTIONS, parseConditions branch, paymentStatusOptions w widoku |
| src/Modules/Automation/AutomationService.php | Modified | evaluatePaymentStatusCondition() + branch w evaluateSingleCondition |
| src/Modules/Orders/OrdersController.php | Modified | AutomationService dep + trigger event w addPayment() |
| src/Modules/Settings/ShopproPaymentStatusSyncService.php | Modified | AutomationService dep + trigger event w syncSingleOrderPayment() |
| src/Modules/Cron/CronHandlerFactory.php | Modified | Przeniesienie tworzenia $automationService przed $shopproPaymentSyncService, przekazanie dep |
| routes/web.php | Modified | $automationService przekazany do OrdersController |
| resources/views/automation/form.php | Modified | Event label, warunek payment_status z checkboxami, paymentStatusOptions w JS data |
| public/assets/js/modules/automation-form.js | Modified | buildPaymentStatusCheckboxes(), opcja w addCondition + onConditionTypeChange |
| DOCS/ARCHITECTURE.md | Modified | Dokumentacja eventu i warunku |
| DOCS/TECH_CHANGELOG.md | Modified | Wpis Phase 57 |

## Decisions Made

| Decision | Rationale | Impact |
|----------|-----------|--------|
| Warunek payment_status uzywa prostego porownania string (nie mapowanie jak shipment_status) | Statusy platnosci to proste wartosci 0/1/2, nie wymagaja mapowania wielopoziomowego | Prostsza implementacja, latwiejsze debugowanie |
| $automationService przeniesiony wyzej w CronHandlerFactory | ShopproPaymentSyncService potrzebuje go jako dep — musi byc utworzony wczesniej | Zmiana kolejnosci tworzenia obiektow w factory |
| Emisja eventu non-blocking (try/catch) | Blad automatyzacji nie powinien blokowac zapisu platnosci ani sync crona | Odpornosc na bledy regul |

## Deviations from Plan

None — plan executed exactly as written.

## Next Phase Readiness

**Ready:**
- Event payment.status_changed dziala z obu zrodel (reczne + cron)
- Warunek payment_status pozwala filtrowac po statusie
- Wszystkie istniejace akcje (send_email, issue_receipt, update_order_status, update_shipment_status) dzialaja z nowym eventem

**Concerns:**
- Brak — standardowy wzorzec automatyzacji

**Blockers:**
- None
