lib/active_merchant/billing/gateways/skip_jack.rb in activemerchant-1.28.0 vs lib/active_merchant/billing/gateways/skip_jack.rb in activemerchant-1.29.0

- old
+ new

@@ -3,25 +3,25 @@ module ActiveMerchant #:nodoc: module Billing #:nodoc: class SkipJackGateway < Gateway API_VERSION = '?.?' - - self.live_url = "https://www.skipjackic.com" + + self.live_url = "https://www.skipjackic.com" self.test_url = "https://developer.skipjackic.com" - + BASIC_PATH = "/scripts/evolvcc.dll" ADVANCED_PATH = "/evolvcc/evolvcc.aspx" - + ACTIONS = { :authorization => 'AuthorizeAPI', :change_status => 'SJAPI_TransactionChangeStatusRequest', :get_status => 'SJAPI_TransactionStatusRequest' } - + SUCCESS_MESSAGE = 'The transaction was successful.' - + MONETARY_CHANGE_STATUSES = ['SETTLE', 'AUTHORIZE', 'AUTHORIZE ADDITIONAL', 'CREDIT', 'SPLITSETTLE'] CARD_CODE_ERRORS = %w( N S "" ) CARD_CODE_MESSAGES = { @@ -85,11 +85,11 @@ '2' => 'Pending Settlement', '3' => 'Pending Authorization', '4' => 'Pending Manual Settlement', '5' => 'Pending Recurring' } - + RETURN_CODE_MESSAGES = { '-1' => 'Data was not by received intact by Skipjack Transaction Network.', '0' => 'Communication Failure. Error in Request and Response at IP level.', '1' => 'Valid Data. Authorization request was valid.', '-35' => 'Invalid credit card number. Retry with correct credit card number.', @@ -159,38 +159,33 @@ '-114' => 'Pos Error Invalid Incoming Eci', '-115' => 'POS Check Invalid Check Type', '-116' => 'POS Check Invalid Lane Number POS Check lane or cash register number is invalid. Use a valid lane or cash register number that has been configured in the Skipjack Merchant Account.', '-117' => 'POS Check Invalid Cashier Number' } - + self.supported_countries = ['US', 'CA'] self.supported_cardtypes = [:visa, :master, :american_express, :jcb, :discover, :diners_club] self.homepage_url = 'http://www.skipjack.com/' self.display_name = 'SkipJack' # Creates a new SkipJackGateway - # + # # The gateway requires that a valid login and password be passed # in the +options+ hash. - # + # # ==== Options # # * <tt>:login</tt> -- The SkipJack Merchant Serial Number. # * <tt>:password</tt> -- The SkipJack Developer Serial Number. # * <tt>:test => +true+ or +false+</tt> -- Use the test or live SkipJack url. # * <tt>:advanced => +true+ or +false+</tt> -- Set to true if you're using an advanced processor # See the SkipJack Integration Guide for details. (default: +false+) def initialize(options = {}) requires!(options, :login, :password) - @options = options super end - - def test? - @options[:test] || super - end - + def authorize(money, creditcard, options = {}) requires!(options, :order_id, :email) post = {} add_invoice(post, options) add_creditcard(post, creditcard) @@ -208,17 +203,17 @@ authorization end end # Captures the funds from an authorized transaction. - # + # # ==== Parameters # # * <tt>money</tt> -- The amount to be capture as an Integer in cents. # * <tt>authorization</tt> -- The authorization returned from the previous authorize request. # * <tt>options</tt> -- A hash of optional parameters. - # + # # ==== Options # # * <tt>:force_settlement</tt> -- 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 def capture(money, authorization, options = {}) post = { } @@ -250,53 +245,53 @@ end def status(order_id) commit(:get_status, nil, :szOrderNumber => order_id) end - + private - + def advanced? @options[:advanced] end - + def add_forced_settlement(post, options) post[:szForceSettlement] = options[:force_settlment] ? 1 : 0 end - + def add_status_action(post, action) post[:szDesiredStatus] = action end - + 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 - + def url_for(action) result = test? ? self.test_url : self.live_url result += advanced? && action == :authorization ? ADVANCED_PATH : BASIC_PATH result += "?#{ACTIONS[action]}" end - + 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 - + 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]) @@ -311,25 +306,25 @@ 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 - + def split_lines(body) body.split(/[\r\n]+/) end def split_line(line) line.split(/","/).collect { |key| key.sub(/"*([^"]*)"*/, '\1').strip; } end - + 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 - + def parse_authorization_response(body) result = authorize_response_map(body) result[:success] = (result[:szIsApproved] == '1') result end @@ -372,11 +367,11 @@ 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 @@ -403,11 +398,11 @@ 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] @@ -415,11 +410,11 @@ 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 @@ -447,10 +442,10 @@ end def message_from_status(response) response[:success] ? SUCCESS_MESSAGE : response[:szErrorMessage] end - + def sanitize_order_id(value) value.to_s.gsub(/[^\w.]/, '') end end end