class ActiveMerchant::Billing::SkipJackGateway

Constants

ACTIONS
ADVANCED_PATH
API_VERSION
AVS_ERRORS
AVS_MESSAGES
BASIC_PATH
CARD_CODE_ERRORS
CARD_CODE_MESSAGES
CHANGE_STATUS_ERROR_MESSAGES
MONETARY_CHANGE_STATUSES
RETURN_CODE_MESSAGES
SUCCESS_MESSAGE
TRANSACTION_CURRENT_STATUS
TRANSACTION_PENDING_STATUS

Public Class Methods

new(options = {}) click to toggle source

Creates a new SkipJackGateway

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

Options

  • :login – The SkipJack Merchant Serial Number.

  • :password – The SkipJack Developer Serial Number.

  • :test => true or false – Use the test or live SkipJack url.

  • :advanced => true or false – Set to true if you’re using an advanced processor

See the SkipJack Integration Guide for details. (default: false)

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

Public Instance Methods

authorize(money, creditcard, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/skip_jack.rb, line 187
def authorize(money, creditcard, options = {})
  requires!(options, :order_id, :email)
  post = {}
  add_invoice(post, options)
  add_creditcard(post, creditcard)
  add_address(post, options)
  add_customer_data(post, options)
  commit(:authorization, money, post)
end
capture(money, authorization, options = {}) click to toggle source

Captures the funds from an authorized transaction.

Parameters

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

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

  • options – A hash of optional parameters.

Options

  • :force_settlement – Force the settlement to occur as soon as possible. This option is not supported by other gateways. See the SkipJack API reference for more details

# File lib/active_merchant/billing/gateways/skip_jack.rb, line 217
def capture(money, authorization, options = {})
  post = { }
  add_status_action(post, 'SETTLE')
  add_forced_settlement(post, options)
  add_transaction_id(post, authorization)
  commit(:change_status, money, post)
end
credit(money, identification, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/skip_jack.rb, line 241
def credit(money, identification, options = {})
  ActiveMerchant.deprecated CREDIT_DEPRECATION_MESSAGE
  refund(money, identification, options)
end
purchase(money, creditcard, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/skip_jack.rb, line 197
def purchase(money, creditcard, options = {})
  authorization = authorize(money, creditcard, options)
  if authorization.success?
    capture(money, authorization.authorization)
  else
    authorization
  end
end
refund(money, identification, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/skip_jack.rb, line 233
def refund(money, identification, options = {})
  post = {}
  add_status_action(post, 'CREDIT')
  add_forced_settlement(post, options)
  add_transaction_id(post, identification)
  commit(:change_status, money, post)
end
status(order_id) click to toggle source
# File lib/active_merchant/billing/gateways/skip_jack.rb, line 246
def status(order_id)
  commit(:get_status, nil, :szOrderNumber => order_id)
end
void(authorization, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/skip_jack.rb, line 225
def void(authorization, options = {})
  post = {}
  add_status_action(post, 'DELETE')
  add_forced_settlement(post, options)
  add_transaction_id(post, authorization)
  commit(:change_status, nil, post)
end

Private Instance Methods

add_address(post, options) click to toggle source
# File lib/active_merchant/billing/gateways/skip_jack.rb, line 391
def add_address(post, options)
  if address = options[:billing_address] || options[:address]
    post[:StreetAddress]  = address[:address1]
    post[:StreetAddress2] = address[:address2]
    post[:City]           = address[:city]
    post[:State]          = address[:state] || 'XX'
    post[:ZipCode]        = address[:zip]
    post[:Country]        = address[:country]
    post[:Phone]          = address[:phone]
    post[:Fax]            = address[:fax]
  end

  if address = options[:shipping_address]
    post[:ShipToName]           = address[:name]
    post[:ShipToStreetAddress]  = address[:address1]
    post[:ShipToStreetAddress2] = address[:address2]
    post[:ShipToCity]           = address[:city]
    post[:ShipToState]          = address[:state] || 'XX'
    post[:ShipToZipCode]        = address[:zip]
    post[:ShipToCountry]        = address[:country]
    post[:ShipToPhone]          = address[:phone]
    post[:ShipToFax]            = address[:fax]
  end

  # The phone number for the shipping address is required
  # Use the billing address phone number if a shipping address
  # phone number wasn't provided
  post[:ShipToPhone] = post[:Phone] if post[:ShipToPhone].blank?
end
add_amount(params, action, money) click to toggle source
# File lib/active_merchant/billing/gateways/skip_jack.rb, line 292
def add_amount(params, action, money)
  if action == :authorization
    params[:TransactionAmount] = amount(money)
  else
    params[:szAmount] = amount(money) if MONETARY_CHANGE_STATUSES.include?(params[:szDesiredStatus])
  end
end
add_credentials(params, action) click to toggle source
# File lib/active_merchant/billing/gateways/skip_jack.rb, line 282
def add_credentials(params, action)
  if action == :authorization
    params[:SerialNumber] = @options[:login]
    params[:DeveloperSerialNumber] = @options[:password]
  else
    params[:szSerialNumber] = @options[:login]
    params[:szDeveloperSerialNumber] = @options[:password]
  end
end
add_creditcard(post, creditcard) click to toggle source
# File lib/active_merchant/billing/gateways/skip_jack.rb, line 379
def add_creditcard(post, creditcard)
  post[:AccountNumber]  = creditcard.number
  post[:Month] = creditcard.month
  post[:Year] = creditcard.year
  post[:CVV2] = creditcard.verification_value if creditcard.verification_value?
  post[:SJName] = creditcard.name
end
add_customer_data(post, options) click to toggle source
# File lib/active_merchant/billing/gateways/skip_jack.rb, line 387
def add_customer_data(post, options)
  post[:Email] = options[:email]
end
add_forced_settlement(post, options) click to toggle source
# File lib/active_merchant/billing/gateways/skip_jack.rb, line 256
def add_forced_settlement(post, options)
  post[:szForceSettlement] = options[:force_settlment] ? 1 : 0
end
add_invoice(post, options) click to toggle source
# File lib/active_merchant/billing/gateways/skip_jack.rb, line 366
def add_invoice(post, options)
  post[:OrderNumber] = sanitize_order_id(options[:order_id])
  post[:CustomerCode] = options[:customer].to_s.slice(0, 17)
  post[:InvoiceNumber] = options[:invoice]
  post[:OrderDescription] = options[:description]

  if order_items = options[:items]
    post[:OrderString] = order_items.collect { |item| "#{item[:sku]}~#{item[:description].tr('~','-')}~#{item[:declared_value]}~#{item[:quantity]}~#{item[:taxable]}~~~~~~~~#{item[:tax_rate]}~||"}.join
  else
    post[:OrderString] = '1~None~0.00~0~N~||'
  end
end
add_status_action(post, action) click to toggle source
# File lib/active_merchant/billing/gateways/skip_jack.rb, line 260
def add_status_action(post, action)
  post[:szDesiredStatus] = action
end
add_transaction_id(post, transaction_id) click to toggle source
# File lib/active_merchant/billing/gateways/skip_jack.rb, line 362
def add_transaction_id(post, transaction_id)
  post[:szTransactionId] = transaction_id
end
advanced?() click to toggle source
# File lib/active_merchant/billing/gateways/skip_jack.rb, line 252
def advanced?
  @options[:advanced]
end
authorize_response_map(body) click to toggle source
# File lib/active_merchant/billing/gateways/skip_jack.rb, line 319
def authorize_response_map(body)
  lines = split_lines(body)
  keys, values = split_line(lines[0]), split_line(lines[1])
  Hash[*(keys.zip(values).flatten)].symbolize_keys
end
commit(action, money, parameters) click to toggle source
# File lib/active_merchant/billing/gateways/skip_jack.rb, line 264
def commit(action, money, parameters)
  response = parse( ssl_post( url_for(action), post_data(action, money, parameters) ), action )

  # Pass along the original transaction id in the case an update transaction
  Response.new(response[:success], message_from(response, action), response,
    :test => test?,
    :authorization => response[:szTransactionFileName] || parameters[:szTransactionId],
    :avs_result => { :code => response[:szAVSResponseCode] },
    :cvv_result => response[:szCVV2ResponseCode]
  )
end
message_from(response, action) click to toggle source
# File lib/active_merchant/billing/gateways/skip_jack.rb, line 421
def message_from(response, action)
  case action
  when :authorization
    message_from_authorization(response)
  when :get_status
    message_from_status(response)
  else
    message_from_status(response)
  end
end
message_from_authorization(response) click to toggle source
# File lib/active_merchant/billing/gateways/skip_jack.rb, line 432
def message_from_authorization(response)
  if response[:success]
    return SUCCESS_MESSAGE
  else
    return CARD_CODE_MESSAGES[response[:szCVV2ResponseCode]] if CARD_CODE_ERRORS.include?(response[:szCVV2ResponseCode])
    return AVS_MESSAGES[response[:szAVSResponseMessage]] if AVS_ERRORS.include?(response[:szAVSResponseCode])
    return RETURN_CODE_MESSAGES[response[:szReturnCode]] if response[:szReturnCode] != '1'
    return response[:szAuthorizationDeclinedMessage]
  end
end
message_from_status(response) click to toggle source
# File lib/active_merchant/billing/gateways/skip_jack.rb, line 443
def message_from_status(response)
  response[:success] ? SUCCESS_MESSAGE : response[:szErrorMessage]
end
parse(body, action) click to toggle source
# File lib/active_merchant/billing/gateways/skip_jack.rb, line 300
def parse(body, action)
  case action
  when :authorization
    parse_authorization_response(body)
  when :get_status
    parse_status_response(body, [ :SerialNumber, :TransactionAmount, :TransactionStatusCode, :TransactionStatusMessage, :OrderNumber, :TransactionDateTime, :TransactionID, :ApprovalCode, :BatchNumber ])
  else
    parse_status_response(body, [ :SerialNumber, :TransactionAmount, :DesiredStatus, :StatusResponse, :StatusResponseMessage, :OrderNumber, :AuditID ])
  end
end
parse_authorization_response(body) click to toggle source
# File lib/active_merchant/billing/gateways/skip_jack.rb, line 325
def parse_authorization_response(body)
  result = authorize_response_map(body)
  result[:success] = (result[:szIsApproved] == '1')
  result
end
parse_status_response(body, response_keys) click to toggle source
# File lib/active_merchant/billing/gateways/skip_jack.rb, line 331
def parse_status_response(body, response_keys)
  lines = split_lines(body)

  keys = [ :szSerialNumber, :szErrorCode, :szNumberRecords]
  values = split_line(lines[0])[0..2]

  result = Hash[*(keys.zip(values).flatten)]

  result[:szErrorMessage] = ''
  result[:success] = (result[:szErrorCode] == '0')

  if result[:success]
    lines[1..-1].each do |line|
      values = split_line(line)
      response_keys.each_with_index do |key, index|
        result[key] = values[index]
      end
    end
  else
    result[:szErrorMessage] = lines[1]
  end
  result
end
post_data(action, money, params = {}) click to toggle source
# File lib/active_merchant/billing/gateways/skip_jack.rb, line 355
def post_data(action, money, params = {})
  add_credentials(params, action)
  add_amount(params, action, money)
  sorted_params = params.to_a.sort{|a,b| a.to_s <=> b.to_s}.reverse
  sorted_params.collect { |key, value| "#{key.to_s}=#{CGI.escape(value.to_s)}" }.join("&")
end
sanitize_order_id(value) click to toggle source
# File lib/active_merchant/billing/gateways/skip_jack.rb, line 447
def sanitize_order_id(value)
  value.to_s.gsub(/[^\w.]/, '')
end
split_line(line) click to toggle source
# File lib/active_merchant/billing/gateways/skip_jack.rb, line 315
def split_line(line)
  line.split(/","/).collect { |key| key.sub(/"*([^"]*)"*/, '\1').strip; }
end
split_lines(body) click to toggle source
# File lib/active_merchant/billing/gateways/skip_jack.rb, line 311
def split_lines(body)
  body.split(/[\r\n]+/)
end
url_for(action) click to toggle source
# File lib/active_merchant/billing/gateways/skip_jack.rb, line 276
def url_for(action)
  result = test? ? self.test_url : self.live_url
  result += advanced? && action == :authorization ? ADVANCED_PATH : BASIC_PATH
  result += "?#{ACTIONS[action]}"
end