Class: Spree::ShippingLabels::Record

Inherits:
Workflow
  • Object
show all
Defined in:
app/workflows/spree/shipping_labels/record.rb

Overview

Records a label the merchant bought elsewhere — postage from a carrier site, a 3PL's PDF — so the parcel still has its file, its tracking number and what it cost, with no carrier integration involved.

The uploaded label mints its delivery like a purchased one; what it cannot do is be refunded through Spree, so deleting it is the way out.

Instance Attribute Summary collapse

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 Spree::ServiceModule::Base

#call, prepended

Methods included from Workflow::ControlFlow

#failure

Instance Attribute Details

#shipping_label ⇒ Object (readonly)

The label that was recorded, readable by hook handlers.



13
14
15
# File 'app/workflows/spree/shipping_labels/record.rb', line 13

def shipping_label
  @shipping_label
end

Instance Method Details

#perform(owner:, file:, tracking_number:, carrier: nil, service: nil, cost: nil, currency: nil, file_format: nil, tracking_url: nil) ⇒ Spree::ServiceModule::Result

Returns the shipping label on success.

Parameters:

  • owner (Spree::Fulfillment, Spree::Return)
  • file (ActionDispatch::Http::UploadedFile, String) —

    the file, or a signed id from POST /files

  • tracking_number (String) —

    the number printed on the label

  • carrier (String, nil) (defaults to: nil) —

    free text; detected from the number when omitted

  • service (String, nil) (defaults to: nil)
  • cost (Numeric, nil) (defaults to: nil) —

    what the merchant paid; 0 when unknown

  • currency (String, nil) (defaults to: nil)
  • file_format (String, nil) (defaults to: nil) —

    pdf | png | zpl; taken from the file when omitted

  • tracking_url (String, nil) (defaults to: nil)

Returns:



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/workflows/spree/shipping_labels/record.rb', line 25

def perform(owner:, file:, tracking_number:, carrier: nil, service: nil, cost: nil, currency: nil, file_format: nil, tracking_url: nil)
  super

  run_hooks :validate

  step :ensure_recordable

  ApplicationRecord.transaction do
    step :record_label
    step :record_delivery
  end

  run_hooks :after_record
  success(shipping_label.reload)
end