class ActiveMerchant::Billing::NetRegistryGateway

Gateway for netregistry.com.au.

Note that NetRegistry itself uses gateway service providers. At the time of this writing, there are at least two (Quest and Ingenico). This module has only been tested with Quest.

Also note that NetRegistry does not offer a test mode, nor does it have support for the authorize/capture/void functionality by default (you may arrange for this as described in “Programming for NetRegistry's E-commerce Gateway.” [rubyurl.com/hNG]), and no void functionality is documented. As a result, the authorize and capture have not yet been tested through a live gateway, and void will raise an error.

If you have this functionality enabled, please consider contributing to ActiveMerchant by writing tests/code for these methods, and submitting a patch.

In addition to the standard ActiveMerchant functionality, the response will contain a 'receipt' parameter (response.params) if a receipt was issued by the gateway.

Constants

FILTERED_PARAMS
TRANSACTIONS

Public Class Methods

new(options = {}) click to toggle source

Create a new NetRegistry gateway.

Options :login and :password must be given.

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

Public Instance Methods

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

Note that authorize and capture only work if your account vendor is St George, and if your account has been setup as described in “Programming for NetRegistry's E-commerce Gateway.” [rubyurl.com/hNG]

# File lib/active_merchant/billing/gateways/net_registry.rb, line 59
def authorize(money, credit_card, options = {})
  params = {
    'AMOUNT'  => amount(money),
    'CCNUM'   => credit_card.number,
    'CCEXP'   => expiry(credit_card)
  }
  add_request_details(params, options)
  commit(:authorization, params)
end
capture(money, authorization, options = {}) click to toggle source

Note that authorize and capture only work if your account vendor is St George, and if your account has been setup as described in “Programming for NetRegistry's E-commerce Gateway.” [rubyurl.com/hNG]

# File lib/active_merchant/billing/gateways/net_registry.rb, line 73
def capture(money, authorization, options = {})
  requires!(options, :credit_card)
  credit_card = options[:credit_card]

  params = {
    'PREAUTHNUM' => authorization,
    'AMOUNT'     => amount(money),
    'CCNUM'      => credit_card.number,
    'CCEXP'      => expiry(credit_card)
  }
  add_request_details(params, options)
  commit(:capture, params)
end
credit(money, identification, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/net_registry.rb, line 106
def credit(money, identification, options = {})
  ActiveMerchant.deprecated CREDIT_DEPRECATION_MESSAGE
  refund(money, identification, options)
end
purchase(money, credit_card, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/net_registry.rb, line 87
def purchase(money, credit_card, options = {})
  params = {
    'AMOUNT'  => amount(money),
    'CCNUM'   => credit_card.number,
    'CCEXP'   => expiry(credit_card)
  }
  add_request_details(params, options)
  commit(:purchase, params)
end
refund(money, identification, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/net_registry.rb, line 97
def refund(money, identification, options = {})
  params = {
    'AMOUNT'  => amount(money),
    'TXNREF'  => identification
  }
  add_request_details(params, options)
  commit(:refund, params)
end
status(identification) click to toggle source

Specific to NetRegistry.

Run a 'status' command. This lets you view the status of a completed transaction.

# File lib/active_merchant/billing/gateways/net_registry.rb, line 116
def status(identification)
  params = {
    'TXNREF'  => identification
  }

  commit(:status, params)
end

Private Instance Methods

add_request_details(params, options) click to toggle source
# File lib/active_merchant/billing/gateways/net_registry.rb, line 125
def add_request_details(params, options)
  params['COMMENT'] = options[:description] unless options[:description].blank?
end
authorization_from(response, command) click to toggle source
# File lib/active_merchant/billing/gateways/net_registry.rb, line 188
def authorization_from(response, command)
  case command
  when :purchase
    response['txn_ref']
  when :authorization
    response['transaction_no']
  end
end
commit(action, params) click to toggle source

Post the a request with the given parameters and return the response object.

Login and password are added automatically, and the comment is omitted if nil.

# File lib/active_merchant/billing/gateways/net_registry.rb, line 142
def commit(action, params)
  # get gateway response
  response = parse( ssl_post(self.live_url, post_data(action, params)) )

  Response.new(response['status'] == 'approved', message_from(response), response,
    :authorization => authorization_from(response, action)
  )
end
escape_uri(uri) click to toggle source

The upstream is picky and so we can't use CGI.escape like we want to

# File lib/active_merchant/billing/gateways/net_registry.rb, line 158
def escape_uri(uri)
  URI::DEFAULT_PARSER.escape(uri)
end
expiry(credit_card) click to toggle source

Return the expiry for the given creditcard in the required format for a command.

# File lib/active_merchant/billing/gateways/net_registry.rb, line 131
def expiry(credit_card)
  month = format(credit_card.month, :two_digits)
  year  = format(credit_card.year , :two_digits)
  "#{month}/#{year}"
end
message_from(response) click to toggle source
# File lib/active_merchant/billing/gateways/net_registry.rb, line 184
def message_from(response)
  response['response_text']
end
parse(response) click to toggle source
# File lib/active_merchant/billing/gateways/net_registry.rb, line 162
def parse(response)
  params = {}

  lines = response.split("\n")

  # Just incase there is no real response returned
  params['status'] = lines[0]
  params['response_text'] = lines[1]

  started = false
  lines.each do |line|
    if started
      key, val = line.chomp.split(/=/, 2)
      params[key] = val unless FILTERED_PARAMS.include?(key)
    end

    started = line.chomp =~ /^\.$/ unless started
  end

  params
end
post_data(action, params) click to toggle source
# File lib/active_merchant/billing/gateways/net_registry.rb, line 151
def post_data(action, params)
  params['COMMAND'] = TRANSACTIONS[action]
  params['LOGIN'] = "#{@options[:login]}/#{@options[:password]}"
  escape_uri(params.map{|k,v| "#{k}=#{v}"}.join('&'))
end