summaryrefslogtreecommitdiff
path: root/app/services/solidus_subscriptions/payment_failed_dispatcher.rb
blob: 29eb29131561f59a9b487c0bbe2bc4f8586aab44 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# frozen_string_literal: true

# Handles payment failures for subscription installments.
module SolidusSubscriptions
  class PaymentFailedDispatcher < Dispatcher
    def dispatch
      order.touch(:completed_at)
      order.cancel
      installments.each do |installment|
        installment.payment_failed!(order)
      end

      ::Spree::Event.fire(
        'solidus_subscriptions.installments_failed_payment',
        installments: installments,
        order: order,
      )
    end
  end
end