class ActiveMerchant::Billing::ExactGateway

Constants

API_VERSION
ENVELOPE_NAMESPACES
POST_HEADERS
SEND_AND_COMMIT_ATTRIBUTES
SEND_AND_COMMIT_SOURCE_ATTRIBUTES
SENSITIVE_FIELDS
SUCCESS
TEST_LOGINS
TRANSACTIONS

Public Class Methods

new(options = {}) click to toggle source
Calls superclass method ActiveMerchant::Billing::Gateway::new
# File lib/active_merchant/billing/gateways/exact.rb, line 42
def initialize(options = {})
  requires!(options, :login, :password)

  super
end

Public Instance Methods

authorize(money, credit_card, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/exact.rb, line 48
def authorize(money, credit_card, options = {})
  commit(:authorization, build_sale_or_authorization_request(money, credit_card, options))
end
capture(money, authorization, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/exact.rb, line 56
def capture(money, authorization, options = {})
  commit(:capture, build_capture_or_credit_request(money, authorization, options))
end
credit(money, authorization, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/exact.rb, line 60
def credit(money, authorization, options = {})
  ActiveMerchant.deprecated CREDIT_DEPRECATION_MESSAGE
  refund(money, authorization, options)
end
purchase(money, credit_card, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/exact.rb, line 52
def purchase(money, credit_card, options = {})
  commit(:sale, build_sale_or_authorization_request(money, credit_card, options))
end
refund(money, authorization, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/exact.rb, line 65
def refund(money, authorization, options = {})
  commit(:credit, build_capture_or_credit_request(money, authorization, options))
end

Private Instance Methods

add_address(xml, options) click to toggle source
# File lib/active_merchant/billing/gateways/exact.rb, line 147
def add_address(xml, options)
  if address = options[:billing_address] || options[:address]
    xml.tag! 'ZipCode', address[:zip]
  end
end
add_amount(xml, money) click to toggle source
# File lib/active_merchant/billing/gateways/exact.rb, line 126
def add_amount(xml, money)
  xml.tag! 'DollarAmount', amount(money)
end
add_credentials(xml) click to toggle source
# File lib/active_merchant/billing/gateways/exact.rb, line 110
def add_credentials(xml)
  xml.tag! 'ExactID', @options[:login]
  xml.tag! 'Password', @options[:password]
end
add_credit_card(xml, credit_card) click to toggle source
# File lib/active_merchant/billing/gateways/exact.rb, line 130
def add_credit_card(xml, credit_card)
  xml.tag! 'Card_Number', credit_card.number
  xml.tag! 'Expiry_Date', expdate(credit_card)
  xml.tag! 'CardHoldersName', credit_card.name

  if credit_card.verification_value?
    xml.tag! 'CVD_Presence_Ind', '1'
    xml.tag! 'VerificationStr2', credit_card.verification_value
  end
end
add_customer_data(xml, options) click to toggle source
# File lib/active_merchant/billing/gateways/exact.rb, line 141
def add_customer_data(xml, options)
  xml.tag! 'Customer_Ref', options[:customer]
  xml.tag! 'Client_IP', options[:ip]
  xml.tag! 'Client_Email', options[:email]
end
add_identification(xml, identification) click to toggle source
# File lib/active_merchant/billing/gateways/exact.rb, line 119
def add_identification(xml, identification)
  authorization_num, transaction_tag = identification.split(';')

  xml.tag! 'Authorization_Num', authorization_num
  xml.tag! 'Transaction_Tag', transaction_tag
end
add_invoice(xml, options) click to toggle source
# File lib/active_merchant/billing/gateways/exact.rb, line 153
def add_invoice(xml, options)
  xml.tag! 'Reference_No', options[:order_id]
  xml.tag! 'Reference_3',  options[:description]
end
add_transaction_type(xml, action) click to toggle source
# File lib/active_merchant/billing/gateways/exact.rb, line 115
def add_transaction_type(xml, action)
  xml.tag! 'Transaction_Type', TRANSACTIONS[action]
end
authorization_from(response) click to toggle source
# File lib/active_merchant/billing/gateways/exact.rb, line 184
def authorization_from(response)
  if response[:authorization_num] && response[:transaction_tag]
    "#{response[:authorization_num]};#{response[:transaction_tag]}"
  else
    ''
  end
end
build_capture_or_credit_request(money, identification, options) click to toggle source
# File lib/active_merchant/billing/gateways/exact.rb, line 100
def build_capture_or_credit_request(money, identification, options)
  xml = Builder::XmlMarkup.new

  add_identification(xml, identification)
  add_amount(xml, money)
  add_customer_data(xml, options)

  xml.target!
end
build_request(action, body) click to toggle source
# File lib/active_merchant/billing/gateways/exact.rb, line 71
def build_request(action, body)
  xml = Builder::XmlMarkup.new

  xml.instruct!
  xml.tag! 'env:Envelope', ENVELOPE_NAMESPACES do
    xml.tag! 'env:Body' do
      xml.tag! 'n1:SendAndCommit', SEND_AND_COMMIT_ATTRIBUTES do
        xml.tag! 'SendAndCommitSource', SEND_AND_COMMIT_SOURCE_ATTRIBUTES do
          add_credentials(xml)
          add_transaction_type(xml, action)
          xml << body
        end
      end
    end
  end
  xml.target!
end
build_sale_or_authorization_request(money, credit_card, options) click to toggle source
# File lib/active_merchant/billing/gateways/exact.rb, line 89
def build_sale_or_authorization_request(money, credit_card, options)
  xml = Builder::XmlMarkup.new

  add_amount(xml, money)
  add_credit_card(xml, credit_card)
  add_customer_data(xml, options)
  add_invoice(xml, options)

  xml.target!
end
commit(action, request) click to toggle source
# File lib/active_merchant/billing/gateways/exact.rb, line 162
def commit(action, request)
  response = parse(ssl_post(self.live_url, build_request(action, request), POST_HEADERS))

  Response.new(successful?(response), message_from(response), response,
    :test => test?,
    :authorization => authorization_from(response),
    :avs_result => { :code => response[:avs] },
    :cvv_result => response[:cvv2]
  )
rescue ResponseError => e
  case e.response.code
  when '401'
    return Response.new(false, "Invalid Login: #{e.response.body}", {}, :test => test?)
  else
    raise
  end
end
expdate(credit_card) click to toggle source
# File lib/active_merchant/billing/gateways/exact.rb, line 158
def expdate(credit_card)
  "#{format(credit_card.month, :two_digits)}#{format(credit_card.year, :two_digits)}"
end
message_from(response) click to toggle source
# File lib/active_merchant/billing/gateways/exact.rb, line 192
def message_from(response)
  if response[:faultcode] && response[:faultstring]
    response[:faultstring]
  elsif response[:error_number] != '0'
    response[:error_description]
  else
    result = response[:exact_message] || ''
    result << " - #{response[:bank_message]}" unless response[:bank_message].blank?
    result
  end
end
parse(xml) click to toggle source
# File lib/active_merchant/billing/gateways/exact.rb, line 204
def parse(xml)
  response = {}
  xml = REXML::Document.new(xml)

  if root = REXML::XPath.first(xml, '//types:TransactionResult')
    parse_elements(response, root)
  elsif root = REXML::XPath.first(xml, '//soap:Fault')
    parse_elements(response, root)
  end

  response.delete_if { |k, v| SENSITIVE_FIELDS.include?(k) }
end
parse_elements(response, root) click to toggle source
# File lib/active_merchant/billing/gateways/exact.rb, line 217
def parse_elements(response, root)
  root.elements.to_a.each do |node|
    response[node.name.gsub(/EXact/, 'Exact').underscore.to_sym] = (node.text || '').strip
  end
end
successful?(response) click to toggle source
# File lib/active_merchant/billing/gateways/exact.rb, line 180
def successful?(response)
  response[:transaction_approved] == SUCCESS
end