Class: Spree::ShippingLabels::Refund
- Defined in:
- app/workflows/spree/shipping_labels/refund.rb
Overview
Asks the carrier to refund a purchased label. The carrier answers either way at once (+refunded+) or later (+refund_requested+, settled through Spree::ShippingLabels::ConfirmRefund); an uploaded label has nothing to refund and is deleted instead.
The delivery the label minted is removed only when the consignment never moved — once the parcel has shipped the journey is history and the delivery stays, label or no label.
Instance Method Summary collapse
-
#perform(shipping_label:) ⇒ Spree::ServiceModule::Result
The label on success.
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
Methods included from Workflow::ControlFlow
Instance Method Details
#perform(shipping_label:) ⇒ Spree::ServiceModule::Result
Returns the label on success.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'app/workflows/spree/shipping_labels/refund.rb', line 16 def perform(shipping_label:) super run_hooks :validate step :ensure_refundable # Carrier I/O — never inside a transaction. external_step :refund ApplicationRecord.transaction do step :record_outcome step :remove_delivery_if_never_moved end shipping_label.publish_event('shipping_label.refunded') if shipping_label.refunded? run_hooks :after_refund success(shipping_label.reload) end |