Class: SpreeAdyen::Webhooks::EventProcessors::CaptureEventProcessor
- Inherits:
-
Object
- Object
- SpreeAdyen::Webhooks::EventProcessors::CaptureEventProcessor
- Defined in:
- app/services/spree_adyen/webhooks/event_processors/capture_event_processor.rb
Defined Under Namespace
Classes: Error
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(event) ⇒ CaptureEventProcessor
constructor
A new instance of CaptureEventProcessor.
Constructor Details
#initialize(event) ⇒ CaptureEventProcessor
Returns a new instance of CaptureEventProcessor.
9 10 11 |
# File 'app/services/spree_adyen/webhooks/event_processors/capture_event_processor.rb', line 9 def initialize(event) @event = event end |
Instance Method Details
#call ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'app/services/spree_adyen/webhooks/event_processors/capture_event_processor.rb', line 13 def call Rails.logger.info("[SpreeAdyen][#{event_id}]: Started processing") order = Spree::Order.find_by!(number: event.order_number) order.with_lock do payment_method = SpreeAdyen::Gateway.find(event.payment_method_id) payment = Spree::Payment.find_by!(response_code: event.fetch('originalReference'), payment_method: payment_method) if event.success? payment.(SpreeAdyen::Gateway::CAPTURE_PSP_REFERENCE_METAFIELD_KEY, event.psp_reference) payment.capture! else payment.add_gateway_processing_error("Capture failed: #{event.fetch('reason')}") payment.started_processing! if payment.can_started_processing? payment.failure! if payment.can_failure? Rails.error.report( SpreeAdyen::CaptureError.new(event.fetch('reason')), context: { order_id: order.id, event: event.payload }, source: 'spree_adyen' ) end end Rails.logger.info("[SpreeAdyen][#{event_id}]: Finished processing") end |