Class: Delivery::Transitions::AfterInvoicedHandler
- Inherits:
-
BaseService
- Object
- BaseService
- Delivery::Transitions::AfterInvoicedHandler
- Includes:
- AfterCommitEverywhere
- Defined in:
- app/services/delivery/transitions/after_invoiced_handler.rb
Overview
Handles post-invoicing tasks after a delivery transitions to the 'invoiced' state.
This is an AFTER_TRANSITION handler - the invoice has already been created
and saved. It runs one synchronous step (order state transition), then
publishes Events::DeliveryInvoiced so async subscribers handle the rest.
== Execution Order
- trigger_order_invoiced - Transition parent order if all deliveries invoiced [sync]
↳ MUST run first — order state must be updated before any downstream work
assumes the order is invoiced (e.g., payment capture). - publish Events::DeliveryInvoiced (after_commit)
→ Shipping::InsurancePurchaseHandler - Purchase shipment insurance [async]
→ Shipping::PackagingDiscrepancyHandler - Flag packaging mismatches [async]
→ Customs::CommercialInvoiceHandler - Submit customs documents [async]
NOTE: lock_delivery was moved to Delivery#lock_after_invoiced (after_commit callback)
to avoid triggering the deferred constraint before the transaction commits.
Instance Method Summary collapse
-
#initialize(delivery) ⇒ AfterInvoicedHandler
constructor
A new instance of AfterInvoicedHandler.
- #process ⇒ Object
Constructor Details
#initialize(delivery) ⇒ AfterInvoicedHandler
Returns a new instance of AfterInvoicedHandler.
28 29 30 31 32 |
# File 'app/services/delivery/transitions/after_invoiced_handler.rb', line 28 def initialize(delivery) super() @delivery = delivery @order = delivery.order end |
Instance Method Details
#process ⇒ Object
34 35 36 37 38 39 |
# File 'app/services/delivery/transitions/after_invoiced_handler.rb', line 34 def process logger.tagged("Delivery #{@delivery.id} AfterInvoicedHandler") do trigger_order_invoiced publish_delivery_invoiced_event end end |