Sha256: 93058ae87fe74347083f42e3ccd7661e7b3373afbd2398b9d9c614998542f767

Contents?: true

Size: 1.74 KB

Versions: 2

Compression:

Stored size: 1.74 KB

Contents

module Spreedly

  class GatewayClass
    include Fields

    field :gateway_type, :name, :homepage, :company_name, :display_api_url
    field :supports_purchase, :supports_authorize, :supports_capture, :supports_credit,
          :supports_void, :supports_verify, :supports_reference_purchase,
          :supports_purchase_via_preauthorization, :supports_offsite_purchase,
          :supports_offsite_authorize, :supports_3dsecure_purchase, :supports_3dsecure_authorize,
          :supports_3dsecure_2_purchase, :supports_3dsecure_2_authorize,
          :supports_store, :supports_remove, :supports_general_credit,
          :supports_fraud_review, type: :boolean

    attr_reader :supported_countries, :payment_methods, :auth_modes, :regions

    def initialize(xml_doc)
      initialize_fields(xml_doc)
      init_supported_countries(xml_doc)
      init_regions(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_regions(xml_doc)
      list = xml_doc.at_xpath(".//regions").inner_html.strip
      @regions = 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

2 entries across 2 versions & 1 rubygems

Version Path
spreedly-2.0.22 lib/spreedly/gateway_class.rb
spreedly-2.0.21 lib/spreedly/gateway_class.rb