Class: ActiveMerchant::Billing::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/mongoid/active_merchant/billing_response.rb

Constant Summary collapse

ATTRIBUTES_FOR_MONGOID_OPTIONS_SERIALIZATION =
[
  :test,
  :authorization,
  :fraud_review,
  :error_code,
  :emv_authorization,
  :avs_result
]

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.demongoize(object) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/mongoid/active_merchant/billing_response.rb', line 39

def demongoize(object)
  return nil if object.blank?

  options = object['options'].symbolize_keys

  if options[:avs_result].present?
    options[:avs_result] = options[:avs_result].symbolize_keys
  end

  Response.new(
    object['success'],
    object['message'],
    object['params'],
    options
  )
end

.evolve(object) ⇒ Object



63
64
65
# File 'lib/mongoid/active_merchant/billing_response.rb', line 63

def evolve(object)
  raise 'querying on an ActiveMerchant::Billing::Response is unsupported at this time'
end

.mongoize(object) ⇒ Object



56
57
58
59
60
61
# File 'lib/mongoid/active_merchant/billing_response.rb', line 56

def mongoize(object)
  case object
  when Response then object.mongoize
  else object
  end
end

Instance Method Details

#as_jsonObject Also known as: mongoize



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/mongoid/active_merchant/billing_response.rb', line 13

def as_json(*)
  options = ATTRIBUTES_FOR_MONGOID_OPTIONS_SERIALIZATION.reduce({}) do |result, attr|
    value = instance_variable_get(:"@#{attr}")
    value = send(attr) if value.nil? && respond_to?(attr)
    result[attr.to_s] = value unless value.nil?
    result
  end

  # ActiveMerchant::Billing::CvvResult doesn't take a hash to initialize,
  # but it sets the Response's cvv_result instance variable to a hash.
  options['cvv_result'] = @cvv_result['code'] if @cvv_result.present?

  {
    'success' => success?,
    'message' => message,
    'params' => params,
    'options' => options
  }
end

#to_json(*args) ⇒ Object



34
35
36
# File 'lib/mongoid/active_merchant/billing_response.rb', line 34

def to_json(*args)
  as_json.to_json(*args)
end