Sha256: 23c7fc38b1d491575efefed0716974a7929b99546a795b488657bfa271524768

Contents?: true

Size: 1.27 KB

Versions: 1

Compression:

Stored size: 1.27 KB

Contents

class PaymentechOrbitalRequest
  attr_reader :gateway, :options

  def initialize(options={})
    @options = options
  end

  def to_xml
    @_xml ||= build_request(options)
  end

  private
  # Delegate these to options hash.
  [:login, :password, :merchant_id, 
   :bin, :terminal_id, :currency_code,
   :currency_exponent, :customer_ref_num,
   :order_id].each do |attr|
    define_method(:"#{attr}") do
      options[:"#{attr}"]
    end
  end

  def address
    @_address ||= options[:billing_address] || options[:address] || {}
  end

  def full_street_address
    "#{address[:address1]} #{address[:address2]}".strip
  end

  # Implement me. I should be the parent tag for the request.
  def request_type; "RequestType"; end

  def build_request(options={})
    xml = Builder::XmlMarkup.new(:indent => 2)

    xml.instruct!(:xml, :version => '1.0', :encoding => 'UTF-8')
    xml.tag! "Request" do
      xml.tag! request_type do
        add_authentication(xml)

        request_body(xml)
      end
    end

    xml.target!
  end

  # Implement me. I should take the provided
  # xml builder and add tags to the request.
  def request_body(xml); xml; end

  def add_authentication(xml)
    xml.tag! "OrbitalConnectionUsername", login
    xml.tag! "OrbitalConnectionPassword", password
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
johnideal-activemerchant-1.4.8 lib/active_merchant/billing/gateways/paymentech_orbital/paymentech_orbital_request.rb