Class: SpreeCmCommissioner::PinCodeCreator

Inherits:
BaseInteractor show all
Defined in:
app/interactors/spree_cm_commissioner/pin_code_creator.rb

Instance Method Summary collapse

Instance Method Details

#callObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/interactors/spree_cm_commissioner/pin_code_creator.rb', line 3

def call
  set_contact
  set_application

  attrs = { contact: context.contact,
            contact_type: context.contact_type,
            type: context.type
          }

  # Only set application if cm_pin_codes.application_id exists (some test schemas may not include it)
  if SpreeCmCommissioner::PinCode.column_names.include?('application_id') && context.application.present?
    attrs[:application] = context.application
  end
  new_pin_code = SpreeCmCommissioner::PinCode.new(attrs)

  if new_pin_code.save
    context.pin_code = new_pin_code
  else
    context.fail!(message: new_pin_code.errors.full_messages.join(', '))
  end
end