Class: Spree::Payments::HandleModificationWebhook
- Defined in:
- app/workflows/spree/payments/handle_modification_webhook.rb
Overview
Applies a provider's answer to a capture, void or refund it accepted
earlier: the outcome a gateway that answered requested? reports by
webhook.
A repeat delivery changes nothing: an outcome for a record already past
requested is ignored, except a failure arriving after a success, which
providers may send days later and which takes the money back.
Constant Summary collapse
- RECORD_CLASSES =
The record each outcome settles, as PaymentMethod#modification_record finds it.
{ 'capture_event' => 'Spree::PaymentCaptureEvent', 'payment' => 'Spree::Payment', 'refund' => 'Spree::Refund' }.freeze
- OUTCOME_RECORDS =
{ capture_succeeded: 'capture_event', capture_failed: 'capture_event', void_succeeded: 'payment', void_failed: 'payment', refund_succeeded: 'refund', refund_failed: 'refund' }.freeze
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 Method Details
#perform(payment_method:, action:, record:, metadata: {}) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/workflows/spree/payments/handle_modification_webhook.rb', line 28 def perform(payment_method:, action:, record:, metadata: {}) super @payment = record.is_a?(Spree::Payment) ? record : record.payment @events = [] step :ensure_known_outcome step :ensure_payment_method_owns_record step :apply_outcome external_step :authorize_remainder step :rederive_order_figures @events.each { |(publisher, name, )| publisher.publish_event(name, nil, || {}) } success(record) end |