Module: Vindi::Synchronizable

Extended by:
ActiveSupport::Concern
Defined in:
lib/vindi/integrations/concerns/synchronizable.rb

Instance Method Summary collapse

Instance Method Details

#sync_vindi_customer!Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/vindi/integrations/concerns/synchronizable.rb', line 15

def sync_vindi_customer!
  return unless synchronizable?
  return if vindi_customer_id?

  params = vindi_customer_attributes
  customer = Vindi::Customer.create(params)
  
  update_columns(vindi_customer_id: customer.id.to_s)
rescue Vindi::Error => e
  Rails.logger.error("Failed to sync customer to Vindi: #{e.message}")
end

#synchronizable?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/vindi/integrations/concerns/synchronizable.rb', line 41

def synchronizable?
  respond_to?(:vindi_customer_id) && self.class.name != "Vindi::PendingSync"
end

#update_vindi_customer!Object



27
28
29
30
31
32
33
34
35
# File 'lib/vindi/integrations/concerns/synchronizable.rb', line 27

def update_vindi_customer!
  return unless synchronizable?
  return unless vindi_customer_id?

  params = vindi_customer_attributes
  Vindi::Customer.update(vindi_customer_id, params)
rescue Vindi::Error => e
  Rails.logger.error("Failed to update customer in Vindi: #{e.message}")
end

#use_vindi_outbox?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/vindi/integrations/concerns/synchronizable.rb', line 37

def use_vindi_outbox?
  synchronizable? && Vindi.configuration.respond_to?(:use_outbox) && Vindi.configuration.use_outbox
end