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
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
)
ActiveMerchant::Billing::Gateway::new
# File lib/active_merchant/billing/gateways/skip_jack.rb, line 180 def initialize(options = {}) requires!(options, :login, :password) super end
Public Instance Methods
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 215 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
# File lib/active_merchant/billing/gateways/skip_jack.rb, line 239 def credit(money, identification, options = {}) ActiveMerchant.deprecated CREDIT_DEPRECATION_MESSAGE refund(money, identification, options) end
# File lib/active_merchant/billing/gateways/skip_jack.rb, line 195 def purchase(money, creditcard, options = {}) authorization = authorize(money, creditcard, options) if authorization.success? capture(money, authorization.authorization) else authorization end end
# File lib/active_merchant/billing/gateways/skip_jack.rb, line 231 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
# File lib/active_merchant/billing/gateways/skip_jack.rb, line 244 def status(order_id) commit(:get_status, nil, :szOrderNumber => order_id) end
# File lib/active_merchant/billing/gateways/skip_jack.rb, line 223 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
# File lib/active_merchant/billing/gateways/skip_jack.rb, line 389 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
# File lib/active_merchant/billing/gateways/skip_jack.rb, line 290 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
# File lib/active_merchant/billing/gateways/skip_jack.rb, line 280 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
# File lib/active_merchant/billing/gateways/skip_jack.rb, line 377 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
# File lib/active_merchant/billing/gateways/skip_jack.rb, line 385 def add_customer_data(post, options) post[:Email] = options[:email] end
# File lib/active_merchant/billing/gateways/skip_jack.rb, line 254 def add_forced_settlement(post, options) post[:szForceSettlement] = options[:force_settlment] ? 1 : 0 end
# File lib/active_merchant/billing/gateways/skip_jack.rb, line 364 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
# File lib/active_merchant/billing/gateways/skip_jack.rb, line 258 def add_status_action(post, action) post[:szDesiredStatus] = action end
# File lib/active_merchant/billing/gateways/skip_jack.rb, line 360 def add_transaction_id(post, transaction_id) post[:szTransactionId] = transaction_id end
# File lib/active_merchant/billing/gateways/skip_jack.rb, line 250 def advanced? @options[:advanced] end
# File lib/active_merchant/billing/gateways/skip_jack.rb, line 262 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
# File lib/active_merchant/billing/gateways/skip_jack.rb, line 419 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
# File lib/active_merchant/billing/gateways/skip_jack.rb, line 441 def message_from_status(response) response[:success] ? SUCCESS_MESSAGE : response[:szErrorMessage] end
# File lib/active_merchant/billing/gateways/skip_jack.rb, line 298 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
# File lib/active_merchant/billing/gateways/skip_jack.rb, line 329 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
# File lib/active_merchant/billing/gateways/skip_jack.rb, line 353 def post_data(action, money, params = {}) add_credentials(params, action) add_amount(params, action, money) sorted_params = params.to_a.sort_by(&:to_s).reverse sorted_params.collect { |key, value| "#{key}=#{CGI.escape(value.to_s)}" }.join('&') end
# File lib/active_merchant/billing/gateways/skip_jack.rb, line 445 def sanitize_order_id(value) value.to_s.gsub(/[^\w.]/, '') end
# File lib/active_merchant/billing/gateways/skip_jack.rb, line 313 def split_line(line) line.split(/","/).collect { |key| key.sub(/"*([^"]*)"*/, '\1').strip; } end
# File lib/active_merchant/billing/gateways/skip_jack.rb, line 309 def split_lines(body) body.split(/[\r\n]+/) end
# File lib/active_merchant/billing/gateways/skip_jack.rb, line 274 def url_for(action) result = test? ? self.test_url : self.live_url result += advanced? && action == :authorization ? ADVANCED_PATH : BASIC_PATH result + "?#{ACTIONS[action]}" end