Sha256: fc3acd3bbc56c7627b4f81320638a5baf7f8b2d3b164ba53d31aa3417f358f18

Contents?: true

Size: 851 Bytes

Versions: 5

Compression:

Stored size: 851 Bytes

Contents

# frozen_string_literal: true

module SolidusSubscriptions
  module Spree
    module WalletPaymentSource
      module ReportDefaultChangeToSubscriptions
        def self.prepended(base)
          base.after_save :report_default_change_to_subscriptions
        end

        private

        def report_default_change_to_subscriptions
          return if !previous_changes.key?('default') || !default?

          user.subscriptions.with_default_payment_source.each do |subscription|
            ::SolidusSupport::LegacyEventCompat::Bus.publish(
              :'solidus_subscriptions.subscription_payment_method_changed',
              subscription: subscription,
            )
          end
        end
      end
    end
  end
end

Spree::WalletPaymentSource.prepend(SolidusSubscriptions::Spree::WalletPaymentSource::ReportDefaultChangeToSubscriptions)

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
solidus_subscriptions-2.0.2 app/decorators/models/solidus_subscriptions/spree/wallet_payment_source/report_default_change_to_subscriptions.rb
solidus_subscriptions-2.0.1 app/decorators/models/solidus_subscriptions/spree/wallet_payment_source/report_default_change_to_subscriptions.rb
solidus_subscriptions-2.0.0 app/decorators/models/solidus_subscriptions/spree/wallet_payment_source/report_default_change_to_subscriptions.rb
solidus_subscriptions-1.1.0 app/decorators/models/solidus_subscriptions/spree/wallet_payment_source/report_default_change_to_subscriptions.rb
solidus_subscriptions-1.0.1 app/decorators/models/solidus_subscriptions/spree/wallet_payment_source/report_default_change_to_subscriptions.rb