class ActiveMerchant::Billing::MetricsGlobalGateway

For more information on the Metrics Global Payment Gateway, visit the Metrics Global website. Further documentation on AVS and CVV response codes are available under the support section of the Metrics Global control panel.

Metrics Global Payment Gateway Authentication

The login and password for the gateway are the same as the username and password used to log in to the Metrics Global control panel. Contact Metrics Global support to receive credentials for the control panel.

Demo Account

There is a public demo account available with the following credentials:

Login: demo Password: password

Constants

API_VERSION
AVS_ERRORS
AVS_REASON_CODES
CARD_CODE_ERRORS
CARD_CODE_RESPONSE_CODE
FRAUD_REVIEW
RESPONSE_REASON_TEXT

Public Class Methods

new(options = {}) click to toggle source

Creates a new MetricsGlobalGateway

The gateway requires that a valid login and password be passed in the options hash.

Options

  • :login – The username required to access the Metrics Global control panel. (REQUIRED)

  • :password – The password required to access the Metrics Global control panel. (REQUIRED)

  • :testtrue or false. If true, perform transactions against the test server. Otherwise, perform transactions against the production server.

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

Public Instance Methods

authorize(money, creditcard, options = {}) click to toggle source

Performs an authorization, which reserves the funds on the customer’s credit card, but does not charge the card.

Parameters

  • money – The amount to be authorized as an Integer value in cents.

  • creditcard – The CreditCard details for the transaction.

  • options – A hash of optional parameters.

# File lib/active_merchant/billing/gateways/metrics_global.rb, line 66
def authorize(money, creditcard, options = {})
  post = {}
  add_invoice(post, options)
  add_creditcard(post, creditcard)
  add_address(post, options)
  add_customer_data(post, options)
  add_duplicate_window(post)

  commit('AUTH_ONLY', money, post)
end
capture(money, authorization, options = {}) click to toggle source

Captures the funds from an authorized transaction.

Parameters

  • money – The amount to be captured as an Integer value in cents.

  • authorization – The authorization returned from the previous authorize request.

# File lib/active_merchant/billing/gateways/metrics_global.rb, line 101
def capture(money, authorization, options = {})
  post = { trans_id: authorization }
  add_customer_data(post, options)
  commit('PRIOR_AUTH_CAPTURE', money, post)
end
credit(money, identification, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/metrics_global.rb, line 151
def credit(money, identification, options = {})
  ActiveMerchant.deprecated CREDIT_DEPRECATION_MESSAGE
  refund(money, identification, options)
end
purchase(money, creditcard, options = {}) click to toggle source

Perform a purchase, which is essentially an authorization and capture in a single operation.

Parameters

  • money – The amount to be purchased as an Integer value in cents.

  • creditcard – The CreditCard details for the transaction.

  • options – A hash of optional parameters.

# File lib/active_merchant/billing/gateways/metrics_global.rb, line 84
def purchase(money, creditcard, options = {})
  post = {}
  add_invoice(post, options)
  add_creditcard(post, creditcard)
  add_address(post, options)
  add_customer_data(post, options)
  add_duplicate_window(post)

  commit('AUTH_CAPTURE', money, post)
end
refund(money, identification, options = {}) click to toggle source

Refund a transaction.

This transaction indicates to the gateway that money should flow from the merchant to the customer.

Parameters

  • money – The amount to be credited to the customer as an Integer value in cents.

  • identification – The ID of the original transaction against which the refund is being issued.

  • options – A hash of parameters.

Options

  • :card_number – The credit card number the refund is being issued to. (REQUIRED)

  • :first_name – The first name of the account being refunded.

  • :last_name – The last name of the account being refunded.

  • :zip – The postal code of the account being refunded.

# File lib/active_merchant/billing/gateways/metrics_global.rb, line 135
def refund(money, identification, options = {})
  requires!(options, :card_number)

  post = { trans_id: identification,
           card_num: options[:card_number] }

  post[:first_name] = options[:first_name] if options[:first_name]
  post[:last_name] = options[:last_name] if options[:last_name]
  post[:zip] = options[:zip] if options[:zip]

  add_invoice(post, options)
  add_duplicate_window(post)

  commit('CREDIT', money, post)
end
void(authorization, options = {}) click to toggle source

Void a previous transaction

Parameters

  • authorization - The authorization returned from the previous authorize request.

# File lib/active_merchant/billing/gateways/metrics_global.rb, line 112
def void(authorization, options = {})
  post = { trans_id: authorization }
  add_duplicate_window(post)
  commit('VOID', nil, post)
end

Private Instance Methods

add_address(post, options) click to toggle source
# File lib/active_merchant/billing/gateways/metrics_global.rb, line 257
def add_address(post, options)
  if address = options[:billing_address] || options[:address]
    post[:address] = address[:address1].to_s
    post[:company] = address[:company].to_s
    post[:phone]   = address[:phone].to_s
    post[:zip]     = address[:zip].to_s
    post[:city]    = address[:city].to_s
    post[:country] = address[:country].to_s
    post[:state]   = address[:state].blank? ? 'n/a' : address[:state]
  end

  if address = options[:shipping_address]
    post[:ship_to_first_name] = address[:first_name].to_s
    post[:ship_to_last_name] = address[:last_name].to_s
    post[:ship_to_address] = address[:address1].to_s
    post[:ship_to_company] = address[:company].to_s
    post[:ship_to_phone]   = address[:phone].to_s
    post[:ship_to_zip]     = address[:zip].to_s
    post[:ship_to_city]    = address[:city].to_s
    post[:ship_to_country] = address[:country].to_s
    post[:ship_to_state]   = address[:state].blank? ? 'n/a' : address[:state]
  end
end
add_creditcard(post, creditcard) click to toggle source
# File lib/active_merchant/billing/gateways/metrics_global.rb, line 232
def add_creditcard(post, creditcard)
  post[:card_num]   = creditcard.number
  post[:card_code]  = creditcard.verification_value if creditcard.verification_value?
  post[:exp_date]   = expdate(creditcard)
  post[:first_name] = creditcard.first_name
  post[:last_name]  = creditcard.last_name
end
add_customer_data(post, options) click to toggle source
# File lib/active_merchant/billing/gateways/metrics_global.rb, line 240
def add_customer_data(post, options)
  if options.has_key? :email
    post[:email] = options[:email]
    post[:email_customer] = false
  end

  post[:cust_id] = options[:customer] if options.has_key? :customer

  post[:customer_ip] = options[:ip] if options.has_key? :ip
end
add_duplicate_window(post) click to toggle source

x_duplicate_window won’t be sent by default, because sending it changes the response. “If this field is present in the request with or without a value, an enhanced duplicate transaction response will be sent.”

# File lib/active_merchant/billing/gateways/metrics_global.rb, line 253
def add_duplicate_window(post)
  post[:duplicate_window] = duplicate_window unless duplicate_window.nil?
end
add_invoice(post, options) click to toggle source
# File lib/active_merchant/billing/gateways/metrics_global.rb, line 227
def add_invoice(post, options)
  post[:invoice_num] = options[:order_id]
  post[:description] = options[:description]
end
commit(action, money, parameters) click to toggle source
# File lib/active_merchant/billing/gateways/metrics_global.rb, line 158
def commit(action, money, parameters)
  parameters[:amount] = amount(money) unless action == 'VOID'

  # Only activate the test_request when the :test option is passed in
  parameters[:test_request] = @options[:test] ? 'TRUE' : 'FALSE'

  url = test? ? self.test_url : self.live_url
  data = ssl_post url, post_data(action, parameters)

  response = parse(data)

  message = message_from(response)

  # Return the response. The authorization can be taken out of the transaction_id
  # Test Mode on/off is something we have to parse from the response text.
  # It usually looks something like this
  #
  #   (TESTMODE) Successful Sale
  test_mode = test? || message =~ /TESTMODE/

  Response.new(
    success?(response),
    message,
    response,
    test: test_mode,
    authorization: response[:transaction_id],
    fraud_review: fraud_review?(response),
    avs_result: { code: response[:avs_result_code] },
    cvv_result: response[:card_code]
  )
end
fraud_review?(response) click to toggle source
# File lib/active_merchant/billing/gateways/metrics_global.rb, line 194
def fraud_review?(response)
  response[:response_code] == FRAUD_REVIEW
end
message_from(results) click to toggle source
# File lib/active_merchant/billing/gateways/metrics_global.rb, line 281
def message_from(results)
  if results[:response_code] == DECLINED
    return CVVResult.messages[results[:card_code]] if CARD_CODE_ERRORS.include?(results[:card_code])
    return AVSResult.messages[results[:avs_result_code]] if AVS_REASON_CODES.include?(results[:response_reason_code]) && AVS_ERRORS.include?(results[:avs_result_code])
  end

  (results[:response_reason_text] ? results[:response_reason_text].chomp('.') : '')
end
parse(body) click to toggle source
# File lib/active_merchant/billing/gateways/metrics_global.rb, line 198
def parse(body)
  fields = split(body)

  {
    response_code: fields[RESPONSE_CODE].to_i,
    response_reason_code: fields[RESPONSE_REASON_CODE],
    response_reason_text: fields[RESPONSE_REASON_TEXT],
    avs_result_code: fields[AVS_RESULT_CODE],
    transaction_id: fields[TRANSACTION_ID],
    card_code: fields[CARD_CODE_RESPONSE_CODE]
  }
end
post_data(action, parameters = {}) click to toggle source
# File lib/active_merchant/billing/gateways/metrics_global.rb, line 211
def post_data(action, parameters = {})
  post = {}

  post[:version]        = API_VERSION
  post[:login]          = @options[:login]
  post[:tran_key]       = @options[:password]
  post[:relay_response] = 'FALSE'
  post[:type]           = action
  post[:delim_data]     = 'TRUE'
  post[:delim_char]     = ','
  post[:encap_char]     = '$'
  post[:solution_ID]    = application_id if application_id

  post.merge(parameters).collect { |key, value| "x_#{key}=#{CGI.escape(value.to_s)}" }.join('&')
end
split(response) click to toggle source
# File lib/active_merchant/billing/gateways/metrics_global.rb, line 290
def split(response)
  response[1..-2].split(/\$,\$/)
end
success?(response) click to toggle source
# File lib/active_merchant/billing/gateways/metrics_global.rb, line 190
def success?(response)
  response[:response_code] == APPROVED
end