Class: AuthorizeNet::Reporting::Response
- Inherits:
-
XmlResponse
- Object
- AuthorizeNet::Response
- XmlResponse
- AuthorizeNet::Reporting::Response
- 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_HOSTED_PROFILE_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 Attribute Summary
Attributes inherited from XmlResponse
#message_code, #message_text, #reference_id, #result_code
Instance Method Summary collapse
-
#batch_list ⇒ Object
Returns an Array of Batch objects built from the entities returned in the response.
-
#initialize(raw_response, transaction) ⇒ Response
constructor
Constructs a new response object from raw_response in the context of transaction.
-
#transaction ⇒ Object
Builds and returns a TransactionDetail entity built from the response.
-
#transactions ⇒ Object
Returns an Array of TransactionDetail objects built from the entities returned in the response.
Methods inherited from XmlResponse
#connection_failure?, #raw, #response_code, #response_reason_code, #response_reason_text, #success?, #xml
Methods inherited from AuthorizeNet::Response
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.
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/authorize_net/reporting/response.rb', line 9 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 StandardError @raw_response = $ERROR_INFO end end end |
Instance Method Details
#batch_list ⇒ Object
Returns an Array of Batch objects built from the entities returned in the response. Returns nil if no batchList was returned.
23 24 25 26 27 28 29 30 31 |
# File 'lib/authorize_net/reporting/response.rb', line 23 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.empty? end end |
#transaction ⇒ Object
Builds and returns a TransactionDetail entity built from the response. If no transaction was found, returns nil.
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 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/authorize_net/reporting/response.rb', line 68 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 = 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.freight = value_to_decimal(shipping_amount) unless shipping_amount.nil? transaction.order.freight_name = node_content_unless_nil(shipping.at_css('name')) transaction.order.freight_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 = 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 subscription = @transaction.at_css('subscription') unless subscription.nil? subscription_id = node_content_unless_nil(@transaction.at_css('subscription').at_css('id')) transaction.subscription_id = value_to_decimal(subscription_id) unless subscription_id.nil? pay_num = node_content_unless_nil(@transaction.at_css('subscription').at_css('payNum')) transaction.subscription_paynum = value_to_decimal(pay_num) unless pay_num.nil? end solution = @transaction.at_css('solution') unless solution.nil? solution_id = node_content_unless_nil(@transaction.at_css('solution').at_css('id')) transaction.solution_id = solution_id unless solution_id.nil? transaction.solution_name = node_content_unless_nil(@transaction.at_css('solution').at_css('name')) end returned_items = @transaction.at_css('returnedItems') unless returned_items.nil? transaction.returns ||= AuthorizeNet::Reporting::ReturnedItem.new returned_items.element_children.each do |child| returned_item = build_entity(child, Fields::RETURNED_ITEM_ENTITY_DESCRIPTION) transaction.returns.add_returned_item(returned_item) end end transaction end end |
#transactions ⇒ Object
Returns an Array of TransactionDetail objects built from the entities returned in the response. Returns nil if no transactions were returned.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/authorize_net/reporting/response.rb', line 34 def transactions unless @transactions.nil? transactions = [] @transactions.element_children.each do |child| next if 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 subscription = child.at_css('subscription') unless subscription.nil? subscription_id = node_content_unless_nil(child.at_css('subscription').at_css('id')) transaction.subscription_id = subscription_id unless subscription_id.nil? pay_num = node_content_unless_nil(child.at_css('subscription').at_css('payNum')) transaction.subscription_paynum = pay_num unless pay_num.nil? end transactions <<= transaction end return transactions unless transactions.empty? end end |