Sha256: 67404189b6a302df5dfcdfa66b89c7772542bf44d503bd255788f2b859427961

Contents?: true

Size: 1.35 KB

Versions: 1

Compression:

Stored size: 1.35 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, :fraud_review, 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.15 lib/spreedly/transactions/gateway_transaction.rb