class ActiveMerchant::Billing::PacNetRavenGateway

Constants

AVS_ADDRESS_CODES
AVS_POSTAL_CODES
CVV2_CODES

Public Class Methods

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

Public Instance Methods

authorize(money, creditcard, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/pac_net_raven.rb, line 43
def authorize(money, creditcard, options = {})
  post = {}
  add_creditcard(post, creditcard)
  add_currency_code(post, money, options)
  add_address(post, options)
  post['PRN'] = @options[:prn]

  commit('cc_preauth', money, post)
end
capture(money, authorization, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/pac_net_raven.rb, line 71
def capture(money, authorization, options = {})
  post = {}
  post['PreauthNumber'] = authorization
  post['PRN'] = @options[:prn]
  add_currency_code(post, money, options)

  commit('cc_settle', money, post)
end
purchase(money, creditcard, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/pac_net_raven.rb, line 53
def purchase(money, creditcard, options = {})
  post = {}
  add_currency_code(post, money, options)
  add_creditcard(post, creditcard)
  add_address(post, options)
  post['PRN'] = @options[:prn]

  commit('cc_debit', money, post)
end
refund(money, template_number, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/pac_net_raven.rb, line 80
def refund(money, template_number, options = {})
  post = {}
  post['PRN'] = @options[:prn]
  post['TemplateNumber'] = template_number
  add_currency_code(post, money, options)

  commit('cc_refund', money, post)
end
void(authorization, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/pac_net_raven.rb, line 63
def void(authorization, options = {})
  post = {}
  post['TrackingNumber'] = authorization
  post['PymtType'] = options[:pymt_type] || 'cc_debit'

  commit('void', nil, post)
end

Private Instance Methods

add_address(post, options) click to toggle source
# File lib/active_merchant/billing/gateways/pac_net_raven.rb, line 101
def add_address(post, options)
  if address = options[:billing_address] || options[:address]
    post['BillingStreetAddressLineOne']   = address[:address1].to_s
    post['BillingStreetAddressLineFour']  = address[:address2].to_s
    post['BillingPostalCode']             = address[:zip].to_s
  end
end
add_creditcard(post, creditcard) click to toggle source
# File lib/active_merchant/billing/gateways/pac_net_raven.rb, line 91
def add_creditcard(post, creditcard)
  post['CardNumber'] = creditcard.number
  post['Expiry'] = expdate(creditcard)
  post['CVV2'] = creditcard.verification_value if creditcard.verification_value
end
add_currency_code(post, money, options) click to toggle source
# File lib/active_merchant/billing/gateways/pac_net_raven.rb, line 97
def add_currency_code(post, money, options)
  post['Currency'] = options[:currency] || currency(money)
end
commit(action, money, parameters) click to toggle source
# File lib/active_merchant/billing/gateways/pac_net_raven.rb, line 113
def commit(action, money, parameters)
  parameters['Amount'] = amount(money) unless action == 'void'

  data = ssl_post url(action), post_data(action, parameters)

  response = parse(data)
  response[:action] = action

  message = message_from(response)

  test_mode = test? || message =~ /TESTMODE/

  Response.new(success?(response), message, response,
    :test => test_mode,
    :authorization => response['TrackingNumber'],
    :fraud_review => fraud_review?(response),
    :avs_result => {
                    :postal_match => AVS_POSTAL_CODES[response['AVSPostalResponseCode']],
                    :street_match => AVS_ADDRESS_CODES[response['AVSAddressResponseCode']]
                   },
    :cvv_result => CVV2_CODES[response['CVV2ResponseCode']]
  )
end
endpoint(action) click to toggle source
# File lib/active_merchant/billing/gateways/pac_net_raven.rb, line 141
def endpoint(action)
  return 'void' if action == 'void'
  'submit'
end
fraud_review?(response) click to toggle source
# File lib/active_merchant/billing/gateways/pac_net_raven.rb, line 146
def fraud_review?(response)
  false
end
message_from(response) click to toggle source
# File lib/active_merchant/billing/gateways/pac_net_raven.rb, line 158
def message_from(response)
  return response['Message'] if response['Message']

  if response['Status'] == 'Approved'
    "This transaction has been approved"
  elsif response['Status'] == 'Declined'
    "This transaction has been declined"
  elsif response['Status'] == 'Voided'
    "This transaction has been voided"
  else
    response['Status']
  end
end
parse(body) click to toggle source
# File lib/active_merchant/billing/gateways/pac_net_raven.rb, line 109
def parse(body)
  Hash[body.split('&').map{|x| x.split('=').map{|y| CGI.unescape(y)}}]
end
post_data(action, parameters = {}) click to toggle source
# File lib/active_merchant/billing/gateways/pac_net_raven.rb, line 172
def post_data(action, parameters = {})
  post = {}

  post['PymtType']      = action
  post['RAPIVersion']   = '2'
  post['UserName']      = @options[:user]
  post['Timestamp']     = timestamp
  post['RequestID']     = request_id
  post['Signature']     = signature(action, post, parameters)

  request = post.merge(parameters).collect { |key, value| "#{key}=#{CGI.escape(value.to_s)}" }.join("&")
  request
end
request_id() click to toggle source
# File lib/active_merchant/billing/gateways/pac_net_raven.rb, line 190
def request_id
  SecureRandom.uuid
end
signature(action, post, parameters = {}) click to toggle source
# File lib/active_merchant/billing/gateways/pac_net_raven.rb, line 194
def signature(action, post, parameters = {})
  string = if %w(cc_settle cc_debit cc_preauth cc_refund).include?(action)
    post['UserName'] + post['Timestamp'] + post['RequestID'] + post['PymtType'] + parameters['Amount'].to_s + parameters['Currency']
  elsif action == 'void'
    post['UserName'] + post['Timestamp'] + post['RequestID'] + parameters['TrackingNumber']
  else
    post['UserName']
  end
  OpenSSL::HMAC.hexdigest(OpenSSL::Digest::SHA1.new(@options[:secret]), @options[:secret], string)
end
success?(response) click to toggle source
# File lib/active_merchant/billing/gateways/pac_net_raven.rb, line 150
def success?(response)
  if %w(cc_settle cc_debit cc_preauth cc_refund).include?(response[:action])
    !response['ApprovalCode'].nil? and response['ErrorCode'].nil? and response['Status'] == 'Approved'
  elsif response[:action] = 'void'
    !response['ApprovalCode'].nil? and response['ErrorCode'].nil? and response['Status'] == 'Voided'
  end
end
timestamp() click to toggle source
# File lib/active_merchant/billing/gateways/pac_net_raven.rb, line 186
def timestamp
  Time.now.strftime("%Y-%m-%dT%H:%M:%S.Z")
end
url(action) click to toggle source
# File lib/active_merchant/billing/gateways/pac_net_raven.rb, line 137
def url(action)
  (test? ? self.test_url : self.live_url) + endpoint(action)
end