Class: Customs::CommercialInvoiceHandler

Inherits:
ApplicationJob
  • Object
show all
Includes:
RailsEventStore::AsyncHandler
Defined in:
app/subscribers/customs/commercial_invoice_handler.rb

Overview

Submits the commercial invoice to the carrier for international shipments.

Subscribes to: Events::DeliveryInvoiced

WHY async: Customs document submission calls an external carrier API and
can fail without invalidating the sale. Running independently means a
carrier API outage can be retried without re-triggering insurance purchase
or packaging discrepancy checks.

WHY after invoicing: Customs documents must reflect the final, committed
invoice values. Submitting before invoicing risks sending stale pricing.

Instance Method Summary collapse

Instance Method Details

#perform(event) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'app/subscribers/customs/commercial_invoice_handler.rb', line 18

def perform(event)
  delivery = Delivery.find_by(id: event.data[:delivery_id])
  return unless delivery
  return unless delivery.should_send_commercial_invoice_to_carrier?

  delivery.send_commercial_invoice_to_carrier
rescue StandardError => e
  ErrorReporting.error(e)
  raise
end