Class: Spreedly::GatewayTransaction

Inherits:
Transaction show all
Defined in:
lib/spreedly/transactions/gateway_transaction.rb

Direct Known Subclasses

AuthPurchase, Capture, Refund, Verification, Void

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Transaction

new_from, new_list_from

Methods included from Fields

#field_hash, included, #initialize_fields

Constructor Details

#initialize(xml_doc) ⇒ GatewayTransaction


11
12
13
14
15
16
17
18
# File 'lib/spreedly/transactions/gateway_transaction.rb', line 11

def initialize(xml_doc)
  super
  response_xml_doc = xml_doc.at_xpath('.//response')
  shipping_address_xml_doc = xml_doc.at_xpath('.//shipping_address')
  @response = response_xml_doc ? Response.new(response_xml_doc) : nil
  @shipping_address = shipping_address_xml_doc ? ShippingAddress.new(shipping_address_xml_doc) : nil
  @gateway_specific_fields = parse_gateway_specific_fields(xml_doc)
end

Instance Attribute Details

#gateway_specific_fieldsObject (readonly)

Returns the value of attribute gateway_specific_fields


9
10
11
# File 'lib/spreedly/transactions/gateway_transaction.rb', line 9

def gateway_specific_fields
  @gateway_specific_fields
end

#responseObject (readonly)

Returns the value of attribute response


9
10
11
# File 'lib/spreedly/transactions/gateway_transaction.rb', line 9

def response
  @response
end

#shipping_addressObject (readonly)

Returns the value of attribute shipping_address


9
10
11
# File 'lib/spreedly/transactions/gateway_transaction.rb', line 9

def shipping_address
  @shipping_address
end

Instance Method Details

#parse_gateway_specific_fields(xml_doc) ⇒ Object


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/spreedly/transactions/gateway_transaction.rb', line 20

def parse_gateway_specific_fields(xml_doc)
  result = {}

  xml_doc.at_xpath('.//gateway_specific_fields').xpath('*').each do |node|
    node_name = node.name.to_sym
    if (node.elements.empty?)
      result[node_name] = node.text
    else
      node.elements.each do |childnode|
        result[node_name] ||= {}
        result[node_name][childnode.name.to_sym] = childnode.text
      end
    end
  end

  result
end