Sha256: 7f4c39f5aea6bb35c8376709b0310006be830f4f078cb0ac6c11de60191201eb

Contents?: true

Size: 1.33 KB

Versions: 1

Compression:

Stored size: 1.33 KB

Contents

module Spreedly

  class GatewayTransaction < Transaction

    field :order_id, :ip, :description, :gateway_token, :gateway_transaction_id
    field :merchant_name_descriptor, :merchant_location_descriptor
    field :on_test_gateway, type: :boolean

    attr_reader :response, :gateway_specific_fields

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

    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
  end

  class Response
    include Fields

    field :success, :pending, :cancelled, type: :boolean
    field :created_at, :updated_at, type: :date_time
    field :message, :avs_code, :avs_message, :cvv_code, :cvv_message, :error_code, :error_detail

    def initialize(xml_doc)
      initialize_fields(xml_doc)
    end

  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
spreedly-2.0.14 lib/spreedly/transactions/gateway_transaction.rb