class ActiveMerchant::Billing::NetaxeptGateway

Public Class Methods

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

Public Instance Methods

authorize(money, creditcard, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/netaxept.rb, line 39
def authorize(money, creditcard, options = {})
  requires!(options, :order_id)

  MultiResponse.run do |r|
    r.process { setup_transaction(money, options) }
    r.process { add_and_auth_credit_card(r.authorization, creditcard, options) }
    r.process { query_transaction(r.authorization, options) }
  end
end
capture(money, authorization, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/netaxept.rb, line 49
def capture(money, authorization, options = {})
  post = {}
  add_credentials(post, options)
  add_authorization(post, authorization, money)
  post[:operation] = 'Capture'
  commit('Netaxept/process.aspx', post)
end
purchase(money, creditcard, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/netaxept.rb, line 30
def purchase(money, creditcard, options = {})
  requires!(options, :order_id)

  MultiResponse.run do |r|
    r.process { authorize(money, creditcard, options) }
    r.process { capture(money, r.authorization, options) }
  end
end
refund(money, authorization, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/netaxept.rb, line 57
def refund(money, authorization, options = {})
  post = {}
  add_credentials(post, options)
  add_authorization(post, authorization, money)
  post[:operation] = 'Credit'
  commit('Netaxept/process.aspx', post)
end
void(authorization, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/netaxept.rb, line 65
def void(authorization, options = {})
  post = {}
  add_credentials(post, options)
  add_authorization(post, authorization)
  post[:operation] = 'Annul'
  commit('Netaxept/process.aspx', post)
end

Private Instance Methods

add_and_auth_credit_card(authorization, creditcard, options) click to toggle source
# File lib/active_merchant/billing/gateways/netaxept.rb, line 82
def add_and_auth_credit_card(authorization, creditcard, options)
  post = {}
  add_credentials(post, options, false)
  add_authorization(post, authorization)
  add_creditcard(post, creditcard)
  commit('terminal/default.aspx', post, false)
end
add_authorization(post, authorization, money = nil) click to toggle source
# File lib/active_merchant/billing/gateways/netaxept.rb, line 102
def add_authorization(post, authorization, money = nil)
  post[:transactionId] = authorization
  post[:transactionAmount] = amount(money) if money
end
add_credentials(post, options, secure = true) click to toggle source
# File lib/active_merchant/billing/gateways/netaxept.rb, line 97
def add_credentials(post, options, secure = true)
  post[:merchantId] = @options[:login]
  post[:token] = @options[:password] if secure
end
add_creditcard(post, options) click to toggle source
# File lib/active_merchant/billing/gateways/netaxept.rb, line 115
def add_creditcard(post, options)
  post[:pan] = options.number
  post[:expiryDate] = format(options.month, :two_digits) + format(options.year, :two_digits)
  post[:securityCode] = options.verification_value
end
add_order(post, money, options) click to toggle source
# File lib/active_merchant/billing/gateways/netaxept.rb, line 107
def add_order(post, money, options)
  post[:serviceType] = 'M'
  post[:orderNumber] = options[:order_id]
  post[:amount] = amount(money)
  post[:currencyCode] = (options[:currency] || currency(money))
  post[:autoAuth] = 'true'
end
build_url(base, parameters = nil) click to toggle source
# File lib/active_merchant/billing/gateways/netaxept.rb, line 165
def build_url(base, parameters = nil)
  url = (test? ? self.test_url : self.live_url).dup
  url << base
  if parameters
    url << '?'
    url << encode(parameters)
  end
  url
end
commit(path, parameters, xml = true) click to toggle source
# File lib/active_merchant/billing/gateways/netaxept.rb, line 121
def commit(path, parameters, xml = true)
  raw = parse(ssl_get(build_url(path, parameters)), xml)

  success = false
  authorization = (raw['TransactionId'] || parameters[:transactionId])
  if /Exception|Error/.match?(raw[:container])
    message = (raw['Message'] || raw['Error']['Message'])
  elsif raw['Error'] && !raw['Error'].empty?
    message = (raw['Error']['ResponseText'] || raw['Error']['ResponseCode'])
  else
    message = (raw['ResponseText'] || raw['ResponseCode'] || 'OK')
    success = true
  end

  Response.new(
    success,
    message,
    raw,
    test: test?,
    authorization: authorization
  )
end
encode(hash) click to toggle source
# File lib/active_merchant/billing/gateways/netaxept.rb, line 175
def encode(hash)
  hash.collect { |(k, v)| "#{CGI.escape(k.to_s)}=#{CGI.escape(v.to_s)}" }.join('&')
end
extract_xml(element) click to toggle source
# File lib/active_merchant/billing/gateways/netaxept.rb, line 153
def extract_xml(element)
  if element.has_elements?
    hash = {}
    element.elements.each do |e|
      hash[e.name] = extract_xml(e)
    end
    hash
  else
    element.text
  end
end
parse(result, expects_xml = true) click to toggle source
# File lib/active_merchant/billing/gateways/netaxept.rb, line 144
def parse(result, expects_xml = true)
  if expects_xml
    doc = REXML::Document.new(result)
    extract_xml(doc.root).merge(container: doc.root.name)
  else
    { result: result }
  end
end
query_transaction(authorization, options) click to toggle source
# File lib/active_merchant/billing/gateways/netaxept.rb, line 90
def query_transaction(authorization, options)
  post = {}
  add_credentials(post, options)
  add_authorization(post, authorization)
  commit('Netaxept/query.aspx', post)
end
setup_transaction(money, options) click to toggle source
# File lib/active_merchant/billing/gateways/netaxept.rb, line 75
def setup_transaction(money, options)
  post = {}
  add_credentials(post, options)
  add_order(post, money, options)
  commit('Netaxept/Register.aspx', post)
end