Sha256: ad994ce87be96eb64395b19e635cc2a9828ace02ea5d8790f8e4be491499d53b

Contents?: true

Size: 813 Bytes

Versions: 40

Compression:

Stored size: 813 Bytes

Contents

module Pay
  module Billable
    module SyncCustomer
      # Syncs customer details to the payment processor.
      # This way they're kept in sync and email notifications are
      # always sent to the correct email address after an update.

      extend ActiveSupport::Concern

      included do
        after_update_commit :enqeue_customer_sync_job, if: :pay_should_sync_customer?
      end

      def pay_should_sync_customer?
        try(:saved_change_to_email?)
      end

      private

      def enqeue_customer_sync_job
        if pay_should_sync_customer?
          # Queue job to update each payment processor for this customer
          pay_customers.pluck(:id).each do |pay_customer_id|
            CustomerSyncJob.perform_later(pay_customer_id)
          end
        end
      end
    end
  end
end

Version data entries

40 entries across 40 versions & 1 rubygems

Version Path
pay-8.3.0 lib/pay/billable/sync_customer.rb
pay-8.2.2 lib/pay/billable/sync_customer.rb
pay-8.2.1 lib/pay/billable/sync_customer.rb
pay-8.2.0 lib/pay/billable/sync_customer.rb
pay-8.1.3 lib/pay/billable/sync_customer.rb
pay-8.1.2 lib/pay/billable/sync_customer.rb
pay-8.1.1 lib/pay/billable/sync_customer.rb
pay-8.1.0 lib/pay/billable/sync_customer.rb
pay-8.0.0 lib/pay/billable/sync_customer.rb
pay-7.3.0 lib/pay/billable/sync_customer.rb
pay-7.2.1 lib/pay/billable/sync_customer.rb
pay-7.1.1 lib/pay/billable/sync_customer.rb
pay-7.1.0 lib/pay/billable/sync_customer.rb
pay-7.0.0 lib/pay/billable/sync_customer.rb
pay-6.8.1 lib/pay/billable/sync_customer.rb
pay-6.8.0 lib/pay/billable/sync_customer.rb
pay-6.7.2 lib/pay/billable/sync_customer.rb
pay-6.7.1 lib/pay/billable/sync_customer.rb
pay-6.7.0 lib/pay/billable/sync_customer.rb
pay-6.6.1 lib/pay/billable/sync_customer.rb