Sha256: 62b935ec94b3acc43de921bf867838cb70a4ffddfd8c0b4697b85ebe224303ef

Contents?: true

Size: 806 Bytes

Versions: 13

Compression:

Stored size: 806 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 :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

13 entries across 13 versions & 1 rubygems

Version Path
pay-5.0.4 lib/pay/billable/sync_customer.rb
pay-5.0.3 lib/pay/billable/sync_customer.rb
pay-5.0.2 lib/pay/billable/sync_customer.rb
pay-5.0.1 lib/pay/billable/sync_customer.rb
pay-5.0.0 lib/pay/billable/sync_customer.rb
pay-4.2.1 lib/pay/billable/sync_customer.rb
pay-4.2.0 lib/pay/billable/sync_customer.rb
pay-4.1.1 lib/pay/billable/sync_customer.rb
pay-4.1.0 lib/pay/billable/sync_customer.rb
pay-4.0.4 lib/pay/billable/sync_customer.rb
pay-4.0.2 lib/pay/billable/sync_customer.rb
pay-4.0.1 lib/pay/billable/sync_customer.rb
pay-4.0.0 lib/pay/billable/sync_customer.rb