Class: Spree::Refunds::Create
- Defined in:
- app/workflows/spree/refunds/create.rb
Overview
Creates a refund and credits it back at the gateway.
In the workflow tier because the credit is network I/O. The refund row commits first, then the gateway is called from an external_step — a row with no transaction_id is recoverable, a gateway credit with no record is not. On a clean gateway failure the uncredited row is destroyed (credit_allowed sums every refund row, so a dangling one would block the retry); a crash between the two leaves the row for reconciliation.
Instance Attribute Summary collapse
-
#refund ⇒ Object
readonly
The created refund — hook handlers read it (nil during :validate).
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
Methods included from Workflow::ControlFlow
Instance Attribute Details
#refund ⇒ Object (readonly)
The created refund — hook handlers read it (nil during :validate).
15 16 17 |
# File 'app/workflows/spree/refunds/create.rb', line 15 def refund @refund end |
Instance Method Details
#perform(payment:, amount: nil, reason: nil, refunder: nil, originator: nil, order: nil, tax_amount: 0) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'app/workflows/spree/refunds/create.rb', line 31 def perform(payment:, amount: nil, reason: nil, refunder: nil, originator: nil, order: nil, tax_amount: 0) super step :ensure_refundable @amount_to_refund = amount || payment.credit_allowed step :ensure_amount_within_balance # Veto point — before the refund record exists and before any money # moves back. run_hooks :validate run_hooks :before_refund step :create_refund, on_flow_failure: :destroy_uncredited_refund external_step :credit_at_gateway run_hooks :after_refund # A requested refund is confirmed by the provider's webhook, which # publishes payment.refunded then. if refund.requested? refund.publish_event('refund.requested') else payment.publish_event('payment.refunded', nil, refund_id: refund.prefixed_id) end success(refund) end |