Class: AuthorizeNet::Reporting::Response

Inherits:
XmlResponse show all
Includes:
CIM::Fields
Defined in:
lib/authorize_net/reporting/response.rb

Overview

The CIM response class.

Constant Summary

Constants included from CIM::Fields

CIM::Fields::ADDRESS_ENTITY_DESCRIPTION, CIM::Fields::ADDRESS_FIELDS, CIM::Fields::BILL_TO_FIELDS, CIM::Fields::CREATE_ADDRESS_FIELDS, CIM::Fields::CREATE_PAYMENT_FIELDS, CIM::Fields::CREATE_PROFILE_FIELDS, CIM::Fields::CREATE_TRANSACTION_FIELDS, CIM::Fields::CREDIT_CARD_ENTITY_DESCRIPTION, CIM::Fields::CUSTOMER_PAYMENT_PROFILE_ID_FIELDS, CIM::Fields::CUSTOMER_PROFILE_ID_FIELDS, CIM::Fields::DELETE_ADDRESS_FIELDS, CIM::Fields::DELETE_PAYMENT_FIELDS, CIM::Fields::DELETE_PROFILE_FIELDS, CIM::Fields::ECHECK_ENTITY_DESCRIPTION, CIM::Fields::FIELDS, CIM::Fields::GET_ADDRESS_FIELDS, CIM::Fields::GET_PAYMENT_FIELDS, CIM::Fields::GET_PROFILE_FIELDS, CIM::Fields::GET_PROFILE_IDS_FIELDS, CIM::Fields::PAYMENT_PROFILE_ENTITY_DESCRIPTION, CIM::Fields::PAYMENT_PROFILE_FIELDS, CIM::Fields::PROFILE_ENTITY_DESCRIPTION, CIM::Fields::PROFILE_FIELDS, CIM::Fields::REFID_FIELDS, CIM::Fields::SHIP_TO_FIELDS, CIM::Fields::TRANSACTION_AUTH_CAPTURE_FIELDS, CIM::Fields::TRANSACTION_AUTH_FIELDS, CIM::Fields::TRANSACTION_CAPTURE_FIELDS, CIM::Fields::TRANSACTION_FIELDS, CIM::Fields::TRANSACTION_PRIOR_AUTH_CAPTURE_FIELDS, CIM::Fields::TRANSACTION_REFUND_FIELDS, CIM::Fields::TRANSACTION_VOID_FIELDS, CIM::Fields::UPDATE_ADDRESS_FIELDS, CIM::Fields::UPDATE_PAYMENT_FIELDS, CIM::Fields::UPDATE_PROFILE_FIELDS, CIM::Fields::UPDATE_SPLIT_FIELDS, CIM::Fields::VALIDATE_PAYMENT_FIELDS, CIM::Fields::VALIDATION_MODE_FIELDS

Constants included from TypeConversions

TypeConversions::API_FIELD_PREFIX

Instance Method Summary collapse

Methods inherited from XmlResponse

#connection_failure?, #message_code, #message_text, #raw, #reference_id, #response_code, #response_reason_code, #response_reason_text, #result_code, #success?, #xml

Methods inherited from AuthorizeNet::Response

#success?

Methods included from TypeConversions

#boolean_to_value, #date_to_value, #datetime_to_value, #decimal_to_value, #integer_to_value, #to_external_field, #to_internal_field, #to_param, #value_to_boolean, #value_to_date, #value_to_datetime, #value_to_decimal, #value_to_integer

Constructor Details

#initialize(raw_response, transaction) ⇒ Response

Constructs a new response object from raw_response in the context of transaction. You don‘t typically construct this object yourself, as AuthorizeNet::Reeporting::Transaction will build one for you when it makes the request to the gateway.



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/authorize_net/reporting/response.rb', line 11

def initialize(raw_response, transaction)
  super
  unless connection_failure?
    begin
      @batch_list = @root.at_css('batchList')
      @transactions = @root.at_css('transactions')
      @transaction = @root.at_css('transaction')
    rescue
      @raw_response = $!
    end
  end
end

Instance Method Details

#batch_listObject

Returns an Array of Batch objects built from the entities returned in the response. Returns nil if no batchList was returned.



26
27
28
29
30
31
32
33
34
# File 'lib/authorize_net/reporting/response.rb', line 26

def batch_list
  unless @batch_list.nil?
    batches = []
    @batch_list.element_children.each do |child|
      batches <<= build_entity(child, Fields::BATCH_ENTITY_DESCRIPTION) unless child.nil?
    end
    return batches unless batches.length == 0
  end
end

#transactionObject

Builds and returns a TransactionDetail entity built from the response. If no transaction was found, returns nil.



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/authorize_net/reporting/response.rb', line 63

def transaction
  unless @transaction.nil?
    transaction = build_entity(@transaction, Fields::TRANSACTION_DETAILS_ENTITY_DESCRIPTION)
    
    ip = node_content_unless_nil(@transaction.at_css('customerIP'))
    unless ip.nil?
      transaction.customer ||= AuthorizeNet::CIM::CustomerProfile.new()
      transaction.customer.ip = ip
    end
    
    tax_exempt = node_content_unless_nil(@transaction.at_css('taxExempt'))
    unless tax_exempt.nil?
      transaction.order ||= AuthorizeNet::Order.new()
      transaction.order.tax_exempt = value_to_boolean(tax_exempt)
    end
    
    tax = @transaction.at_css('tax')
    unless tax.nil?
      transaction.order ||= AuthorizeNet::Order.new()
      tax_amount = node_content_unless_nil(tax.at_css('amount'))
      transaction.order.tax_amount = value_to_decimal(tax_amount) unless tax_amount.nil?
      transaction.order.tax_name = node_content_unless_nil(tax.at_css('name'))
      transaction.order.tax_description = node_content_unless_nil(tax.at_css('description'))
    end
    
    shipping = @transaction.at_css('shipping')
    unless shipping.nil?
      transaction.order ||= AuthorizeNet::Order.new()
      shipping_amount = node_content_unless_nil(shipping.at_css('amount'))
      transaction.order.shipping_amount = value_to_decimal(shipping_amount) unless shipping_amount.nil?
      transaction.order.shipping_name = node_content_unless_nil(shipping.at_css('name'))
      transaction.order.shipping_description = node_content_unless_nil(shipping.at_css('description'))
    end
    
    duty = @transaction.at_css('duty')
    unless duty.nil?
      transaction.order ||= AuthorizeNet::Order.new()
      duty_amount = node_content_unless_nil(duty.at_css('amount'))
      transaction.order.duty_amount = value_to_decimal(duty_amount) unless duty_amount.nil?
      transaction.order.duty_name = node_content_unless_nil(duty.at_css('name'))
      transaction.order.duty_description = node_content_unless_nil(duty.at_css('description'))
    end
    
    line_items = @transaction.at_css('lineItems')
    unless line_items.nil?
      transaction.order ||= AuthorizeNet::Order.new()
      line_items.element_children.each do |child|
        line_item = build_entity(child, Fields::LINE_ITEM_ENTITY_DESCRIPTION)
        transaction.order.add_line_item(line_item)
      end
    end
    
    # Really not sure what to do with customer type here. It should go on a payment
    customer_type = node_content_unless_nil(@transaction.at_css('customer type'))
    unless customer_type.nil?
      transaction.customer ||= AuthorizeNet::CIM::CustomerProfile.new()
      transaction.customer.payment_profiles = [AuthorizeNet::CIM::PaymentProfile.new(:cust_type => customer_type)]
    end
    
    return transaction
  end
end

#transactionsObject

Returns an Array of TransactionDetail objects built from the entities returned in the response. Returns nil if no transactions were returned.



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/authorize_net/reporting/response.rb', line 37

def transactions
  unless @transactions.nil?
    transactions = []
    @transactions.element_children.each do |child|
      unless child.nil?
        transaction = build_entity(child, Fields::TRANSACTION_DETAILS_ENTITY_DESCRIPTION)
        
        # handle some stuff thats too tricky for EntityDecription to handle
        first_name = node_content_unless_nil(child.at_css('firstName'))
        last_name = node_content_unless_nil(child.at_css('lastName'))
        unless first_name.nil? && last_name.nil?
          address = AuthorizeNet::Address.new(:first_name => first_name, :last_name => last_name)
          transaction.customer = AuthorizeNet::Customer.new(:address => address)
        end
        invoice_number = node_content_unless_nil(child.at_css('invoiceNumber'))
        unless invoice_number.nil?
          transaction.order = AuthorizeNet::Order.new(:invoice_num => invoice_number)
        end
        transactions <<= transaction
      end
    end
    return transactions unless transactions.length == 0
  end
end