Module: DiscoApp::Concerns::SynchroniseCarrierServiceJob

Extended by:
ActiveSupport::Concern
Included in:
SynchroniseCarrierServiceJob
Defined in:
app/jobs/disco_app/concerns/synchronise_carrier_service_job.rb

Instance Method Summary collapse

Instance Method Details

#perform(_shop) ⇒ Object

Ensure that any carrier service required by our app is registered.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/jobs/disco_app/concerns/synchronise_carrier_service_job.rb', line 6

def perform(_shop)
  # Don't proceed unless we have a name and callback url.
  return unless carrier_service_name && callback_url

  # Registered the carrier service if it hasn't been registered yet.
  unless current_carrier_service_names.include?(carrier_service_name)
    ShopifyAPI::CarrierService.create(
      name: carrier_service_name,
      callback_url: callback_url,
      service_discovery: true,
      format: :json
    )
  end

  # Ensure any existing carrier services (with the correct name) are active
  # and have a current callback URL.
  current_carrier_services.each do |carrier_service|
    next unless carrier_service.name == carrier_service_name

    carrier_service.callback_url = callback_url
    carrier_service.active = true
    carrier_service.save
  end
end