Completed
Pull Request — master (#156)
by
unknown
02:20
created

Response.token()   A

Complexity

Conditions 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

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