Sha256: 650660f0a7cae9c8794420e41286383d118449acb6870deb642df79856cb856b

Contents?: true

Size: 1.41 KB

Versions: 1

Compression:

Stored size: 1.41 KB

Contents

module Spreedly

  class GatewayClass
    include Fields

    field :gateway_type, :name, :supported_countries, :homepage, :company_name
    field :supports_purchase, :supports_authorize, :supports_capture, :supports_credit,
          :supports_void, :supports_reference_purchase, :supports_purchase_via_preauthorization,
          :supports_offsite_purchase, :supports_offsite_authorize, :supports_3dsecure_purchase,
          :supports_3dsecure_authorize, :supports_store, :supports_remove, type: :boolean

    attr_reader :supported_countries, :payment_methods, :auth_modes

    def initialize(xml_doc)
      initialize_fields(xml_doc)
      init_supported_countries(xml_doc)
      init_payment_methods(xml_doc)
      init_auth_modes(xml_doc)
    end

    def self.new_list_from(xml_doc)
      gateways = xml_doc.xpath('.//gateways/gateway')
      gateways.map do |each|
        self.new(each)
      end
    end

    private

    def init_supported_countries(xml_doc)
      list = xml_doc.at_xpath(".//supported_countries").inner_html.strip
      @supported_countries = list.split(/\s*,\s*/)
    end

    def init_payment_methods(xml_doc)
      @payment_methods = xml_doc.xpath('.//payment_methods/payment_method').map do |each|
        each.text
      end
    end

    def init_auth_modes(xml_doc)
      @auth_modes = xml_doc.xpath(".//auth_modes/auth_mode").map do |each|
        Spreedly::AuthMode.new(each)
      end
    end

  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
spreedly-2.0.7 lib/spreedly/gateway_class.rb