Sha256: 2b243c6e117f744356a9cfb6d8210e64a00be849c32ff114384a7e8ef87e31a0

Contents?: true

Size: 1.37 KB

Versions: 8

Compression:

Stored size: 1.37 KB

Contents

module Spreedly
  class GatewayTransaction < Transaction
    field :order_id, :ip, :description, :gateway_token, :gateway_transaction_id, :email, :transaction_type
    field :merchant_name_descriptor, :merchant_location_descriptor
    field :on_test_gateway, type: :boolean

    attr_reader :response, :gateway_specific_fields, :gateway_specific_response_fields, :shipping_address

    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_fields(xml_doc, './/gateway_specific_fields')
      @gateway_specific_response_fields = parse_gateway_fields(xml_doc, './/gateway_specific_response_fields')
    end

    def parse_gateway_fields(xml_doc, path)
      result = {}

      xml_doc.at_xpath(path).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
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
spreedly-2.0.28 lib/spreedly/transactions/gateway_transaction.rb
spreedly-2.0.27 lib/spreedly/transactions/gateway_transaction.rb
spreedly-2.0.26 lib/spreedly/transactions/gateway_transaction.rb
spreedly-2.0.25 lib/spreedly/transactions/gateway_transaction.rb
spreedly-2.0.24 lib/spreedly/transactions/gateway_transaction.rb
spreedly-2.0.23 lib/spreedly/transactions/gateway_transaction.rb
spreedly-2.0.22 lib/spreedly/transactions/gateway_transaction.rb
spreedly-2.0.21 lib/spreedly/transactions/gateway_transaction.rb