Class: Spree::Deliveries::UpdateTracking

Inherits:
Workflow
  • Object
show all
Defined in:
app/workflows/spree/deliveries/update_tracking.rb

Overview

Records what the carrier says about one consignment in flight.

This is the carrier axis: it never moves the owner backwards and never contradicts the merchant. A parcel that bounces or is damaged shows up here as return_to_sender or failure while the fulfillment still says fulfilled — the merchant did hand it over. The one status that crosses over is delivered: when every delivery of a fulfillment has arrived, the fulfillment is marked delivered through Spree::Fulfillments::MarkDelivered. A Return owner never transitions — goods arriving is not goods inspected, and Spree::Returns::Receive stays a staff act; anything that wants to react hangs on after_update_tracking.

Providers call this from their webhook handlers, so it accepts the already-normalized vocabulary rather than any carrier's raw payload: translating a provider's status names is the provider gem's job.

Instance Method Summary collapse

Methods inherited from Workflow

#call, define_argument_readers, #errors, #halt!, hooks, inherited, model_name, #read_attribute_for_validation, #reject!, workflow_key

Methods included from ServiceModule::Base

#call, prepended

Methods included from Workflow::ControlFlow

#failure

Instance Method Details

#perform(delivery:, tracking_status: nil, estimated_delivery_at: nil, delivered_at: nil, details: nil, notify_customer: true) ⇒ Spree::ServiceModule::Result

Returns the updated delivery on success.

Parameters:

  • delivery (Spree::Delivery) —

    the consignment being tracked

  • tracking_status (String, nil) (defaults to: nil) —
  • estimated_delivery_at (Time, nil) (defaults to: nil) —

    carrier's current estimate

  • delivered_at (Time, nil) (defaults to: nil) —

    when the carrier says it arrived; used only when tracking_status is delivered, defaulting to now

  • details (Hash, nil) (defaults to: nil) —

    provider payload worth keeping — scan events, the signature, the failure reason

  • notify_customer (Boolean) (defaults to: true) —

    passed through to MarkDelivered when this update completes the fulfillment's delivery

Returns:



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/workflows/spree/deliveries/update_tracking.rb', line 32

def perform(delivery:, tracking_status: nil, estimated_delivery_at: nil, delivered_at: nil,
            details: nil, notify_customer: true)
  super

  run_hooks :validate

  step :ensure_known_status
  step :apply_carrier_report
  step :roll_up_owner_delivery

  run_hooks :after_update_tracking
  success(delivery.reload)
end