class ActiveMerchant::Billing::QvalentGateway

Constants

CURRENCY_CODES
STANDARD_ERROR_CODE_MAPPING
SUCCESS_CODES

Public Class Methods

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

Public Instance Methods

purchase(amount, payment_method, options={}) click to toggle source
# File lib/active_merchant/billing/gateways/qvalent.rb, line 20
def purchase(amount, payment_method, options={})
  post = {}
  add_invoice(post, amount, options)
  add_order_number(post, options)
  add_payment_method(post, payment_method)
  add_verification_value(post, payment_method)
  add_customer_data(post, options)

  commit("capture", post)
end
refund(amount, authorization, options={}) click to toggle source
# File lib/active_merchant/billing/gateways/qvalent.rb, line 31
def refund(amount, authorization, options={})
  post = {}
  add_invoice(post, amount, options)
  add_reference(post, authorization, options)
  add_customer_data(post, options)

  commit("refund", post)
end
scrub(transcript) click to toggle source
# File lib/active_merchant/billing/gateways/qvalent.rb, line 52
def scrub(transcript)
  transcript.
    gsub(%r((&?customer.password=)[^&]*), '\1[FILTERED]').
    gsub(%r((&?card.PAN=)[^&]*), '\1[FILTERED]').
    gsub(%r((&?card.CVN=)[^&]*), '\1[FILTERED]')
end
store(payment_method, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/qvalent.rb, line 40
def store(payment_method, options = {})
  post = {}
  add_payment_method(post, payment_method)
  add_card_reference(post)

  commit("registerAccount", post)
end
supports_scrubbing?() click to toggle source
# File lib/active_merchant/billing/gateways/qvalent.rb, line 48
def supports_scrubbing?
  true
end

Private Instance Methods

add_card_reference(post) click to toggle source
# File lib/active_merchant/billing/gateways/qvalent.rb, line 82
def add_card_reference(post)
  post["customer.customerReferenceNumber"] = options[:order_id]
end
add_customer_data(post, options) click to toggle source
# File lib/active_merchant/billing/gateways/qvalent.rb, line 95
def add_customer_data(post, options)
  post["order.ipAddress"] = options[:ip]
end
add_invoice(post, money, options) click to toggle source
# File lib/active_merchant/billing/gateways/qvalent.rb, line 65
def add_invoice(post, money, options)
  post["order.amount"] = amount(money)
  post["card.currency"] = CURRENCY_CODES[options[:currency] || currency(money)]
  post["order.ECI"] = "SSL"
end
add_order_number(post, options) click to toggle source
# File lib/active_merchant/billing/gateways/qvalent.rb, line 91
def add_order_number(post, options)
  post["customer.orderNumber"] = options[:order_id] || SecureRandom.uuid
end
add_payment_method(post, payment_method) click to toggle source
# File lib/active_merchant/billing/gateways/qvalent.rb, line 71
def add_payment_method(post, payment_method)
  post["card.cardHolderName"] = payment_method.name
  post["card.PAN"] = payment_method.number
  post["card.expiryYear"] = format(payment_method.year, :two_digits)
  post["card.expiryMonth"] = format(payment_method.month, :two_digits)
end
add_reference(post, authorization, options) click to toggle source
# File lib/active_merchant/billing/gateways/qvalent.rb, line 86
def add_reference(post, authorization, options)
  post["customer.originalOrderNumber"] = authorization
  add_order_number(post, options)
end
add_verification_value(post, payment_method) click to toggle source
# File lib/active_merchant/billing/gateways/qvalent.rb, line 78
def add_verification_value(post, payment_method)
  post["card.CVN"] = payment_method.verification_value
end
build_request(post) click to toggle source
# File lib/active_merchant/billing/gateways/qvalent.rb, line 125
def build_request(post)
  post.to_query + "&message.end"
end
commit(action, post) click to toggle source
# File lib/active_merchant/billing/gateways/qvalent.rb, line 99
def commit(action, post)
  post["customer.username"] = @options[:username]
  post["customer.password"] = @options[:password]
  post["customer.merchant"] = @options[:merchant]
  post["order.type"] = action

  data = build_request(post)
  raw = parse(ssl_post(url(action), data, headers))

  succeeded = success_from(raw["response.responseCode"])
  Response.new(
    succeeded,
    message_from(succeeded, raw),
    raw,
    authorization: raw["response.orderNumber"] || raw["response.customerReferenceNumber"],
    error_code: error_code_from(succeeded, raw),
    test: test?
  )
end
error_code_from(succeeded, response) click to toggle source
# File lib/active_merchant/billing/gateways/qvalent.rb, line 174
def error_code_from(succeeded, response)
  succeeded ? nil : STANDARD_ERROR_CODE_MAPPING[response["response.responseCode"]]
end
headers() click to toggle source
# File lib/active_merchant/billing/gateways/qvalent.rb, line 119
def headers
  {
    "Content-Type"  => "application/x-www-form-urlencoded"
  }
end
message_from(succeeded, response) click to toggle source
# File lib/active_merchant/billing/gateways/qvalent.rb, line 155
def message_from(succeeded, response)
  if succeeded
    "Succeeded"
  else
    response["response.text"] || "Unable to read error message"
  end
end
parse(body) click to toggle source
# File lib/active_merchant/billing/gateways/qvalent.rb, line 133
def parse(body)
  result = {}
  body.to_s.each_line do |pair|
    result[$1] = $2 if pair.strip =~ /\A([^=]+)=(.+)\Z/im
  end
  result
end
parse_element(response, node) click to toggle source
# File lib/active_merchant/billing/gateways/qvalent.rb, line 141
def parse_element(response, node)
  if node.has_elements?
    node.elements.each{|element| parse_element(response, element) }
  else
    response[node.name.underscore.to_sym] = node.text
  end
end
success_from(response) click to toggle source
# File lib/active_merchant/billing/gateways/qvalent.rb, line 151
def success_from(response)
  SUCCESS_CODES.include?(response)
end
url(action) click to toggle source
# File lib/active_merchant/billing/gateways/qvalent.rb, line 129
def url(action)
  (test? ? test_url : live_url)
end