Class: Spree::ExactorSettingsValidator

Inherits:
ActiveModel::Validator
  • Object
show all
Defined in:
app/models/spree/exactor_setting.rb

Instance Method Summary collapse

Instance Method Details

#validate(record) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'app/models/spree/exactor_setting.rb', line 6

def validate(record)
  unless record.errors.empty?
    return
  end
  connector = SpreeExactorConnector::SpreeExactorConnector.new
  response = connector.send_test_transaction(record.get_ship_from, record.merchant_id, record.user_id)
  if (response.nil?)
    record.errors[:base] << "We are unable to communicate with Exactor"
  elsif response.has_key? 'ErrorResponse'
    record.errors[:base] << "Invalid Exactor Settings: #{response['ErrorResponse'][0]['ErrorDescription'][0]}. (Code #{response['ErrorResponse'][0]['ErrorCode'][0]}) "
  end


end