Completed
Pull Request — master (#91)
by
unknown
01:57
created

Response.direct_response()   A

Complexity

Conditions 2

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
c 1
b 0
f 0
dl 0
loc 3
rs 10
1
module AuthorizeNet::CIM
2
3
  # The CIM response class.
4
  class Response < AuthorizeNet::XmlResponse
5
    
6
    include AuthorizeNet::CIM::Fields
7
    
8
    # Constructs a new response object from raw_response in the context of transaction.
9
    # You don‘t typically construct this object yourself, as AuthorizeNet::CIM::Transaction
10
    # will build one for you when it makes the request to the gateway.
11
    def initialize(raw_response, transaction)
12
      super
13
      unless connection_failure?
14
        begin
15
          @customer_profile_id = node_content_unless_nil(@root.at_css('customerProfileId'))
16
          @customer_payment_profile_id = node_content_unless_nil(@root.at_css('customerPaymentProfileId'))
17
          @customer_payment_profile_id_list = node_child_content_unless_nil(@root.at_css('customerPaymentProfileIdList'))
18
          @customer_shipping_address_id_list = node_child_content_unless_nil(@root.at_css('customerShippingAddressIdList'))
19
          @customer_address_id = node_content_unless_nil(@root.at_css('customerAddressId'))
20
          @validation_direct_response_list = @root.at_css('validationDirectResponseList')
21
          @validation_direct_response = @root.at_css('validationDirectResponse')
22
          @direct_response = @root.at_css('directResponse')
23
          @customer_profile_id_list = node_child_content_unless_nil(@root.at_css('ids'))
24
          @address = @root.at_css('address')
25
          @payment_profile = @root.at_css('paymentProfile')
26
          @profile = @root.at_css('profile')
27
          @token = node_content_unless_nil(@root.at_css('token'))
28
        rescue
29
          @raw_response = $!
30
        end
31
      end
32
    end
33
    
34
    # Returns a CustomerProfile ID if one was returned by the gateway. Returns nil otherwise.
35
    # Note that this method will return nil if we got back a list of IDs (see profile_ids).
36
    def profile_id
37
      @customer_profile_id
38
    end
39
    
40
    # Returns a list of CustomerProfile IDs if any were returned by the gateway. Returns nil otherwise.
41
    def profile_ids
42
      @customer_profile_id_list
43
    end
44
    
45
    # Returns an Address ID if one was returned by the gateway. Returns nil otherwise.
46
    # Note that this method will return nil if we got back a list of IDs (see address_ids).
47
    def address_id
48
      @customer_address_id
49
    end
50
    
51
    # Returns a list of Address IDs if any were returned by the gateway. Returns nil otherwise.
52
    def address_ids
53
      @customer_shipping_address_id_list
54
    end
55
    
56
    # Returns a PaymentProfile ID if one was returned by the gateway. Returns nil otherwise.
57
    # Note that this method will return nil if we got back a list of IDs (see payment_profile_ids).
58
    def payment_profile_id
59
      @customer_payment_profile_id
60
    end
61
    
62
    # Returns a list of PaymentProfile IDs if any were returned by the gateway. Returns nil otherwise.
63
    def payment_profile_ids
64
      @customer_payment_profile_id_list
65
    end
66
67
    # Returns hosted profile access token when requested. Returns nil otherwise.
68
    def token
69
      @token
70
    end
71
    
72
    # Returns a validation response as an AuthorizeNet::AIM::Response object if a validation response was returned
73
    # by the gateway. Returns nil otherwise.
74
    # Note that this method will return nil if we got back a list of IDs (see validation_responses).
75
    def validation_response
76
      AuthorizeNet::AIM::Response.new(@validation_direct_response.dup, @transaction) unless @validation_direct_response.nil?
77
    end
78
    
79
    # Returns a list of validation response as an AuthorizeNet::AIM::Response objects if a list of validation response was returned
80
    # by the gateway. Returns nil otherwise.
81 View Code Duplication
    def validation_responses
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
82
      unless @validation_direct_response_list.nil?
83
        responses = []
84
        @validation_direct_response_list.element_children.each do |child|
85
          responses <<= AuthorizeNet::AIM::Response.new(child.dup, @transaction) unless child.nil?
86
        end
87
        return responses unless responses.length == 0
88
      end
89
    end
90
    
91
    # Returns the direct response as an AuthorizeNet::AIM::Response object if a direct response was returned
92
    # by the gateway. Returns nil otherwise.
93
    def direct_response
94
      AuthorizeNet::AIM::Response.new(@direct_response.dup, @transaction) unless @direct_response.nil?
95
    end
96
    
97
    # Returns a CustomerProfile built from the entity returned by the gateway. Returns nil otherwise.
98
    def profile
99
      build_entity(@profile, Fields::PROFILE_ENTITY_DESCRIPTION) unless @profile.nil?
100
    end
101
    
102
    # Returns a PaymentProfile built from the entity returned by the gateway. Returns nil otherwise.
103
    def payment_profile
104
      build_entity(@payment_profile, Fields::PAYMENT_PROFILE_ENTITY_DESCRIPTION) unless @payment_profile.nil?
105
    end
106
    
107
    # Returns an Address built from the entity returned by the gateway. Returns nil otherwise.
108
    def address
109
      build_entity(@address, Fields::ADDRESS_ENTITY_DESCRIPTION) unless @address.nil?
110
    end
111
    
112
    #:enddoc:
113
    protected
114
    
115
  end
116
end