class ActiveMerchant::Billing::NetbillingGateway

To perform PCI Compliant Repeat Billing

 Ensure that PCI Compliant Repeat Billing is enabled on your merchant account:
  "Enable PCI Compliant Repeat Billing, Up-selling and Cross-selling" in Step 6 of the Credit Cards setup page

Instead of passing a credit_card to authorize or purchase, pass the transaction id (res.authorization)
of a past Netbilling transaction

To store billing information without performing an operation, use the 'store' method which invokes the tran_type 'Q' (Quasi) operation and returns a transaction id to use in future Repeat Billing operations

Constants

FAILURE_MESSAGE
SUCCESS_CODES
SUCCESS_MESSAGE
TEST_LOGIN
TRANSACTIONS

Public Class Methods

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

Public Instance Methods

authorize(money, payment_source, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/netbilling.rb, line 41
def authorize(money, payment_source, options = {})
  post = {}
  add_amount(post, money)
  add_invoice(post, options)
  add_payment_source(post, payment_source)
  add_address(post, payment_source, options)
  add_customer_data(post, options)
  add_user_data(post, options)

  commit(:authorization, post)
end
capture(money, authorization, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/netbilling.rb, line 65
def capture(money, authorization, options = {})
  post = {}
  add_reference(post, authorization)
  commit(:capture, post)
end
credit(money, credit_card, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/netbilling.rb, line 78
def credit(money, credit_card, options = {})
  post = {}
  add_amount(post, money)
  add_invoice(post, options)
  add_credit_card(post, credit_card)
  add_address(post, credit_card, options)
  add_customer_data(post, options)
  add_user_data(post, options)

  commit(:credit, post)
end
purchase(money, payment_source, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/netbilling.rb, line 53
def purchase(money, payment_source, options = {})
  post = {}
  add_amount(post, money)
  add_invoice(post, options)
  add_payment_source(post, payment_source)
  add_address(post, payment_source, options)
  add_customer_data(post, options)
  add_user_data(post, options)

  commit(:purchase, post)
end
refund(money, source, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/netbilling.rb, line 71
def refund(money, source, options = {})
  post = {}
  add_amount(post, money)
  add_reference(post, source)
  commit(:refund, post)
end
scrub(transcript) click to toggle source
# File lib/active_merchant/billing/gateways/netbilling.rb, line 114
def scrub(transcript)
  transcript.
    gsub(%r((Authorization: Basic )\w+), '\1[FILTERED]').
    gsub(%r((&?card_number=)[^&]*), '\1[FILTERED]').
    gsub(%r((&?card_cvv2=)[^&]*), '\1[FILTERED]')
end
store(credit_card, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/netbilling.rb, line 96
def store(credit_card, options = {})
  post = {}
  add_amount(post, 0)
  add_payment_source(post, credit_card)
  add_address(post, credit_card, options)
  add_customer_data(post, options)

  commit(:quasi, post)
end
supports_scrubbing() click to toggle source
# File lib/active_merchant/billing/gateways/netbilling.rb, line 110
def supports_scrubbing
  true
end
test?() click to toggle source
Calls superclass method ActiveMerchant::Billing::Gateway#test?
# File lib/active_merchant/billing/gateways/netbilling.rb, line 106
def test?
  (@options[:login] == TEST_LOGIN || super)
end
void(source, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/netbilling.rb, line 90
def void(source, options = {})
  post = {}
  add_reference(post, source)
  commit(:void, post)
end

Private Instance Methods

add_address(post, credit_card, options) click to toggle source
# File lib/active_merchant/billing/gateways/netbilling.rb, line 136
def add_address(post, credit_card, options)
  if billing_address = options[:billing_address] || options[:address]
    post[:bill_street]     = billing_address[:address1]
    post[:cust_phone]      = billing_address[:phone]
    post[:bill_zip]        = billing_address[:zip]
    post[:bill_city]       = billing_address[:city]
    post[:bill_country]    = billing_address[:country]
    post[:bill_state]      = billing_address[:state]
  end

  if shipping_address = options[:shipping_address]
    post[:ship_name1], post[:ship_name2] = split_names(shipping_address[:name])
    post[:ship_street]     = shipping_address[:address1]
    post[:ship_zip]        = shipping_address[:zip]
    post[:ship_city]       = shipping_address[:city]
    post[:ship_country]    = shipping_address[:country]
    post[:ship_state]      = shipping_address[:state]
  end
end
add_amount(post, money) click to toggle source
# File lib/active_merchant/billing/gateways/netbilling.rb, line 123
def add_amount(post, money)
  post[:amount] = amount(money)
end
add_credit_card(post, credit_card) click to toggle source
# File lib/active_merchant/billing/gateways/netbilling.rb, line 178
def add_credit_card(post, credit_card)
  post[:bill_name1] = credit_card.first_name
  post[:bill_name2] = credit_card.last_name
  post[:card_number] = credit_card.number
  post[:card_expire] = expdate(credit_card)
  post[:card_cvv2] = credit_card.verification_value
end
add_customer_data(post, options) click to toggle source
# File lib/active_merchant/billing/gateways/netbilling.rb, line 131
def add_customer_data(post, options)
  post[:cust_email] = options[:email]
  post[:cust_ip] = options[:ip]
end
add_invoice(post, options) click to toggle source
# File lib/active_merchant/billing/gateways/netbilling.rb, line 156
def add_invoice(post, options)
  post[:description] = options[:description]
end
add_payment_source(params, source) click to toggle source
# File lib/active_merchant/billing/gateways/netbilling.rb, line 160
def add_payment_source(params, source)
  if source.is_a?(String)
    add_transaction_id(params, source)
  else
    add_credit_card(params, source)
  end
end
add_reference(post, reference) click to toggle source
# File lib/active_merchant/billing/gateways/netbilling.rb, line 127
def add_reference(post, reference)
  post[:orig_id] = reference
end
add_transaction_id(post, transaction_id) click to toggle source
# File lib/active_merchant/billing/gateways/netbilling.rb, line 174
def add_transaction_id(post, transaction_id)
  post[:card_number] = 'CS:' + transaction_id
end
add_user_data(post, options) click to toggle source
# File lib/active_merchant/billing/gateways/netbilling.rb, line 168
def add_user_data(post, options)
  if options[:order_id]
    post[:user_data] = "order_id:#{options[:order_id]}"
  end
end
commit(action, parameters) click to toggle source
# File lib/active_merchant/billing/gateways/netbilling.rb, line 195
def commit(action, parameters)
  response = parse(ssl_post(self.live_url, post_data(action, parameters)))

  Response.new(success?(response), message_from(response), response,
    :test => test_response?(response),
    :authorization => response[:trans_id],
    :avs_result => { :code => response[:avs_code]},
    :cvv_result => response[:cvv2_code]
  )
rescue ActiveMerchant::ResponseError => e
  raise unless(e.response.code =~ /^[67]\d\d$/)
  return Response.new(false, e.response.message, {:status_code => e.response.code}, :test => test?)
end
message_from(response) click to toggle source
# File lib/active_merchant/billing/gateways/netbilling.rb, line 217
def message_from(response)
  success?(response) ? SUCCESS_MESSAGE : (response[:auth_msg] || FAILURE_MESSAGE)
end
parse(body) click to toggle source
# File lib/active_merchant/billing/gateways/netbilling.rb, line 186
def parse(body)
  results = {}
  body.split(/&/).each do |pair|
    key, val = pair.split(/\=/)
    results[key.to_sym] = CGI.unescape(val)
  end
  results
end
post_data(action, parameters = {}) click to toggle source
# File lib/active_merchant/billing/gateways/netbilling.rb, line 221
def post_data(action, parameters = {})
  parameters[:account_id] = @options[:login]
  parameters[:site_tag] = @options[:site_tag] if @options[:site_tag].present?
  parameters[:pay_type] = 'C'
  parameters[:tran_type] = TRANSACTIONS[action]

  parameters.reject { |k, v| v.blank? }.collect { |key, value| "#{key}=#{CGI.escape(value.to_s)}" }.join('&')
end
success?(response) click to toggle source
# File lib/active_merchant/billing/gateways/netbilling.rb, line 213
def success?(response)
  SUCCESS_CODES.include?(response[:status_code])
end
test_response?(response) click to toggle source
# File lib/active_merchant/billing/gateways/netbilling.rb, line 209
def test_response?(response)
  !!(test? || response[:auth_msg] =~ /TEST/)
end