class ActiveMerchant::Billing::BarclaysEpdqGateway::Document

Constants

EPDQ_CARD_TYPES
PAYMENT_INTERVALS

Attributes

type[R]
xml[R]

Public Class Methods

new(gateway, options = {}, document_options = {}, &block) click to toggle source
# File lib/active_merchant/billing/gateways/barclays_epdq.rb, line 190
def initialize(gateway, options = {}, document_options = {}, &block)
  @gateway = gateway
  @options = options
  @document_options = document_options
  @xml = Builder::XmlMarkup.new(:indent => 2)
  build(&block)
end

Public Instance Methods

add_consumer(options=nil, &block) click to toggle source
# File lib/active_merchant/billing/gateways/barclays_epdq.rb, line 234
def add_consumer(options=nil, &block)
  xml.Consumer do
    if options
      xml.Email(options[:email]) if options[:email]
      billing_address = options[:billing_address] || options[:address]
      if billing_address
        xml.BillTo do
          xml.Location do
            xml.Address do
              xml.Street1 billing_address[:address1]
              xml.Street2 billing_address[:address2]
              xml.City billing_address[:city]
              xml.StateProv billing_address[:state]
              xml.PostalCode billing_address[:zip]
              xml.Country billing_address[:country_code]
            end
          end
        end
      end
    end
    instance_eval(&block)
  end
end
add_creditcard(creditcard) click to toggle source
# File lib/active_merchant/billing/gateways/barclays_epdq.rb, line 258
def add_creditcard(creditcard)
  xml.PaymentMech do
    xml.CreditCard do
      xml.Type({ :DataType => 'S32' }, EPDQ_CARD_TYPES[creditcard.brand.to_sym])
      xml.Number creditcard.number
      xml.Expires({ :DataType => 'ExpirationDate', :Locale => 826 }, format_expiry_date(creditcard))
      if creditcard.verification_value.present?
        xml.Cvv2Indicator 1
        xml.Cvv2Val creditcard.verification_value
      else
        xml.Cvv2Indicator 5
      end
      xml.IssueNum(creditcard.issue_number) if creditcard.issue_number.present?
    end
  end
end
add_order_form(order_id=nil, group_id=nil, &block) click to toggle source
# File lib/active_merchant/billing/gateways/barclays_epdq.rb, line 225
def add_order_form(order_id=nil, group_id=nil, &block)
  xml.OrderFormDoc do
    xml.Mode 'P'
    xml.Id(order_id) if order_id
    xml.GroupId(group_id) if group_id
    instance_eval(&block)
  end
end
add_transaction(auth_type, amount = nil, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/barclays_epdq.rb, line 275
def add_transaction(auth_type, amount = nil, options = {})
  @auth_type = auth_type
  xml.Transaction do
    xml.Type @auth_type.to_s
    if options[:payment_number] && options[:payment_number] > 1
      xml.CardholderPresentCode({ :DataType => 'S32' }, 8)
    else
      xml.CardholderPresentCode({ :DataType => 'S32' }, 7)
    end
    if options[:payment_number]
      xml.PaymentNumber({ :DataType => 'S32' }, options[:payment_number])
    end
    if options[:total_payments]
      xml.TotalNumberPayments({ :DataType => 'S32' }, options[:total_payments])
    end
    if amount
      xml.CurrentTotals do
        xml.Totals do
          xml.Total({ :DataType => 'Money', :Currency => 826 }, amount)
        end
      end
    end
  end
end
build(&block) click to toggle source
# File lib/active_merchant/billing/gateways/barclays_epdq.rb, line 202
def build(&block)
  xml.instruct!(:xml, :version => '1.0')
  xml.EngineDocList do
    xml.DocVersion "1.0"
    xml.EngineDoc do
      xml.ContentType "OrderFormDoc"
      xml.User do
        xml.Name(@options[:login])
        xml.Password(@options[:password])
        xml.ClientId({ :DataType => "S32" }, @options[:client_id])
      end
      xml.Instructions do
        if @document_options[:no_fraud]
          xml.Pipeline "PaymentNoFraud"
        else
          xml.Pipeline "Payment"
        end
      end
      instance_eval(&block)
    end
  end
end
format_expiry_date(creditcard) click to toggle source

date must be formatted MM/YY

# File lib/active_merchant/billing/gateways/barclays_epdq.rb, line 301
def format_expiry_date(creditcard)
  month_str = "%02d" % creditcard.month
  if match = creditcard.year.to_s.match(/^\d{2}(\d{2})$/)
    year_str = "%02d" % match[1].to_i
  else
    year_str = "%02d" % creditcard.year
  end
  "#{month_str}/#{year_str}"
end
to_xml() click to toggle source
# File lib/active_merchant/billing/gateways/barclays_epdq.rb, line 198
def to_xml
  @xml.target!
end