|
1
|
|
|
module AuthorizeNet::Reporting |
|
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::Reeporting::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
|
|
|
@batch_list = @root.at_css('batchList') |
|
16
|
|
|
@transactions = @root.at_css('transactions') |
|
17
|
|
|
@transaction = @root.at_css('transaction') |
|
18
|
|
|
rescue |
|
19
|
|
|
@raw_response = $! |
|
20
|
|
|
end |
|
21
|
|
|
end |
|
22
|
|
|
end |
|
23
|
|
|
|
|
24
|
|
|
|
|
25
|
|
|
# Returns an Array of Batch objects built from the entities returned in the response. Returns nil if no batchList was returned. |
|
26
|
|
View Code Duplication |
def batch_list |
|
|
|
|
|
|
27
|
|
|
unless @batch_list.nil? |
|
28
|
|
|
batches = [] |
|
29
|
|
|
@batch_list.element_children.each do |child| |
|
30
|
|
|
batches <<= build_entity(child, Fields::BATCH_ENTITY_DESCRIPTION) unless child.nil? |
|
31
|
|
|
end |
|
32
|
|
|
return batches unless batches.length == 0 |
|
33
|
|
|
end |
|
34
|
|
|
end |
|
35
|
|
|
|
|
36
|
|
|
# Returns an Array of TransactionDetail objects built from the entities returned in the response. Returns nil if no transactions were returned. |
|
37
|
|
View Code Duplication |
def transactions |
|
|
|
|
|
|
38
|
|
|
unless @transactions.nil? |
|
39
|
|
|
transactions = [] |
|
40
|
|
|
@transactions.element_children.each do |child| |
|
41
|
|
|
unless child.nil? |
|
42
|
|
|
transaction = build_entity(child, Fields::TRANSACTION_DETAILS_ENTITY_DESCRIPTION) |
|
43
|
|
|
|
|
44
|
|
|
# handle some stuff thats too tricky for EntityDecription to handle |
|
45
|
|
|
first_name = node_content_unless_nil(child.at_css('firstName')) |
|
46
|
|
|
last_name = node_content_unless_nil(child.at_css('lastName')) |
|
47
|
|
|
unless first_name.nil? && last_name.nil? |
|
48
|
|
|
address = AuthorizeNet::Address.new(:first_name => first_name, :last_name => last_name) |
|
49
|
|
|
transaction.customer = AuthorizeNet::Customer.new(:address => address) |
|
50
|
|
|
end |
|
51
|
|
|
invoice_number = node_content_unless_nil(child.at_css('invoiceNumber')) |
|
52
|
|
|
unless invoice_number.nil? |
|
53
|
|
|
transaction.order = AuthorizeNet::Order.new(:invoice_num => invoice_number) |
|
54
|
|
|
end |
|
55
|
|
|
subscription = child.at_css('subscription') |
|
56
|
|
|
unless subscription.nil? |
|
57
|
|
|
subscription_id = node_content_unless_nil(child.at_css('subscription').at_css('id')) |
|
58
|
|
|
transaction.subscription_id = subscription_id unless subscription_id.nil? |
|
59
|
|
|
|
|
60
|
|
|
pay_num = node_content_unless_nil(child.at_css('subscription').at_css('payNum')) |
|
61
|
|
|
transaction.subscription_paynum = pay_num unless pay_num.nil? |
|
62
|
|
|
end |
|
63
|
|
|
|
|
64
|
|
|
|
|
65
|
|
|
transactions <<= transaction |
|
66
|
|
|
end |
|
67
|
|
|
end |
|
68
|
|
|
return transactions unless transactions.length == 0 |
|
69
|
|
|
end |
|
70
|
|
|
end |
|
71
|
|
|
|
|
72
|
|
|
# Builds and returns a TransactionDetail entity built from the response. If no transaction was found, returns nil. |
|
73
|
|
|
def transaction |
|
74
|
|
|
unless @transaction.nil? |
|
75
|
|
|
transaction = build_entity(@transaction, Fields::TRANSACTION_DETAILS_ENTITY_DESCRIPTION) |
|
76
|
|
|
|
|
77
|
|
|
ip = node_content_unless_nil(@transaction.at_css('customerIP')) |
|
78
|
|
|
unless ip.nil? |
|
79
|
|
|
transaction.customer ||= AuthorizeNet::CIM::CustomerProfile.new() |
|
80
|
|
|
transaction.customer.ip = ip |
|
81
|
|
|
end |
|
82
|
|
|
|
|
83
|
|
|
tax_exempt = node_content_unless_nil(@transaction.at_css('taxExempt')) |
|
84
|
|
|
unless tax_exempt.nil? |
|
85
|
|
|
transaction.order ||= AuthorizeNet::Order.new() |
|
86
|
|
|
transaction.order.tax_exempt = value_to_boolean(tax_exempt) |
|
87
|
|
|
end |
|
88
|
|
|
|
|
89
|
|
|
tax = @transaction.at_css('tax') |
|
90
|
|
View Code Duplication |
unless tax.nil? |
|
|
|
|
|
|
91
|
|
|
transaction.order ||= AuthorizeNet::Order.new() |
|
92
|
|
|
tax_amount = node_content_unless_nil(tax.at_css('amount')) |
|
93
|
|
|
transaction.order.tax_amount = value_to_decimal(tax_amount) unless tax_amount.nil? |
|
94
|
|
|
transaction.order.tax_name = node_content_unless_nil(tax.at_css('name')) |
|
95
|
|
|
transaction.order.tax_description = node_content_unless_nil(tax.at_css('description')) |
|
96
|
|
|
end |
|
97
|
|
|
|
|
98
|
|
|
shipping = @transaction.at_css('shipping') |
|
99
|
|
View Code Duplication |
unless shipping.nil? |
|
|
|
|
|
|
100
|
|
|
transaction.order ||= AuthorizeNet::Order.new() |
|
101
|
|
|
shipping_amount = node_content_unless_nil(shipping.at_css('amount')) |
|
102
|
|
|
transaction.order.shipping_amount = value_to_decimal(shipping_amount) unless shipping_amount.nil? |
|
103
|
|
|
transaction.order.shipping_name = node_content_unless_nil(shipping.at_css('name')) |
|
104
|
|
|
transaction.order.shipping_description = node_content_unless_nil(shipping.at_css('description')) |
|
105
|
|
|
end |
|
106
|
|
|
|
|
107
|
|
|
duty = @transaction.at_css('duty') |
|
108
|
|
View Code Duplication |
unless duty.nil? |
|
|
|
|
|
|
109
|
|
|
transaction.order ||= AuthorizeNet::Order.new() |
|
110
|
|
|
duty_amount = node_content_unless_nil(duty.at_css('amount')) |
|
111
|
|
|
transaction.order.duty_amount = value_to_decimal(duty_amount) unless duty_amount.nil? |
|
112
|
|
|
transaction.order.duty_name = node_content_unless_nil(duty.at_css('name')) |
|
113
|
|
|
transaction.order.duty_description = node_content_unless_nil(duty.at_css('description')) |
|
114
|
|
|
end |
|
115
|
|
|
|
|
116
|
|
|
line_items = @transaction.at_css('lineItems') |
|
117
|
|
|
unless line_items.nil? |
|
118
|
|
|
transaction.order ||= AuthorizeNet::Order.new() |
|
119
|
|
|
line_items.element_children.each do |child| |
|
120
|
|
|
line_item = build_entity(child, Fields::LINE_ITEM_ENTITY_DESCRIPTION) |
|
121
|
|
|
transaction.order.add_line_item(line_item) |
|
122
|
|
|
end |
|
123
|
|
|
end |
|
124
|
|
|
|
|
125
|
|
|
# Really not sure what to do with customer type here. It should go on a payment |
|
126
|
|
|
customer_type = node_content_unless_nil(@transaction.at_css('customer type')) |
|
127
|
|
|
unless customer_type.nil? |
|
128
|
|
|
transaction.customer ||= AuthorizeNet::CIM::CustomerProfile.new() |
|
129
|
|
|
transaction.customer.payment_profiles = [AuthorizeNet::CIM::PaymentProfile.new(:cust_type => customer_type)] |
|
130
|
|
|
end |
|
131
|
|
|
|
|
132
|
|
|
subscription = @transaction.at_css('subscription') |
|
133
|
|
View Code Duplication |
unless subscription.nil? |
|
|
|
|
|
|
134
|
|
|
subscription_id = node_content_unless_nil(@transaction.at_css('subscription').at_css('id')) |
|
135
|
|
|
transaction.subscription_id = value_to_decimal(subscription_id) unless subscription_id.nil? |
|
136
|
|
|
|
|
137
|
|
|
pay_num = node_content_unless_nil(@transaction.at_css('subscription').at_css('payNum')) |
|
138
|
|
|
transaction.subscription_paynum = value_to_decimal(pay_num) unless pay_num.nil? |
|
139
|
|
|
end |
|
140
|
|
|
|
|
141
|
|
|
solution = @transaction.at_css('solution') |
|
142
|
|
View Code Duplication |
unless solution.nil? |
|
|
|
|
|
|
143
|
|
|
solution_id = node_content_unless_nil(@transaction.at_css('solution').at_css('id')) |
|
144
|
|
|
transaction.solution_id = value_to_decimal(solution_id) unless solution_id.nil? |
|
145
|
|
|
|
|
146
|
|
|
transaction.solution_name = node_content_unless_nil(@transaction.at_css('solution').at_css('name')) |
|
147
|
|
|
end |
|
148
|
|
|
|
|
149
|
|
|
returned_items = @transaction.at_css('returnedItems') |
|
150
|
|
|
unless returned_items.nil? |
|
151
|
|
|
transaction.returns ||= AuthorizeNet::Reporting::ReturnedItem.new |
|
152
|
|
|
returned_items.element_children.each do |child| |
|
153
|
|
|
returned_item = build_entity(child, Fields::RETURNED_ITEM_ENTITY_DESCRIPTION) |
|
154
|
|
|
transaction.returns.add_returned_item(returned_item) |
|
155
|
|
|
end |
|
156
|
|
|
end |
|
157
|
|
|
|
|
158
|
|
|
return transaction |
|
159
|
|
|
end |
|
160
|
|
|
end |
|
161
|
|
|
|
|
162
|
|
|
end |
|
163
|
|
|
end |