lib/active_merchant/billing/gateways/viaklix.rb in activemerchant-1.4.2 vs lib/active_merchant/billing/gateways/viaklix.rb in activemerchant-1.5.0
- old
+ new
@@ -1,11 +1,19 @@
module ActiveMerchant #:nodoc:
module Billing #:nodoc:
class ViaklixGateway < Gateway
- TEST_URL = 'https://demo.viaklix.com/process.asp'
- LIVE_URL = 'https://www.viaklix.com/process.asp'
+ class_inheritable_accessor :test_url, :live_url, :delimiter, :actions
+
+ self.test_url = 'https://demo.viaklix.com/process.asp'
+ self.live_url = 'https://www.viaklix.com/process.asp'
+ self.delimiter = "\r\n"
+ self.actions = {
+ :purchase => 'SALE',
+ :credit => 'CREDIT'
+ }
+
APPROVED = '0'
self.supported_cardtypes = [:visa, :master, :american_express]
self.supported_countries = ['US']
self.display_name = 'ViaKLIX'
@@ -33,11 +41,11 @@
form = {}
add_invoice(form, options)
add_creditcard(form, creditcard)
add_address(form, options)
add_customer_data(form, options)
- commit('SALE', money, form)
+ commit(:purchase, money, form)
end
# Make a credit to a card (Void can only be done from the virtual terminal)
# Viaklix does not support credits by reference. You must pass in the credit card
def credit(money, creditcard, options = {})
@@ -48,17 +56,17 @@
form = {}
add_invoice(form, options)
add_creditcard(form, creditcard)
add_address(form, options)
add_customer_data(form, options)
- commit('CREDIT', money, form)
+ commit(:credit, money, form)
end
private
def add_customer_data(form, options)
form[:email] = options[:email].to_s.slice(0, 100) unless options[:email].blank?
- form[:customer_code] = options[:customer].to_s.slice(0, 17) unless options[:customer].blank?
+ form[:customer_code] = options[:customer].to_s.slice(0, 10) unless options[:customer].blank?
end
def add_invoice(form,options)
form[:invoice_number] = (options[:order_id] || options[:invoice]).to_s.slice(0, 10)
form[:description] = options[:description].to_s.slice(0, 255)
@@ -102,45 +110,61 @@
def add_creditcard(form, creditcard)
form[:card_number] = creditcard.number
form[:exp_date] = expdate(creditcard)
if creditcard.verification_value?
- form[:cvv2cvc2] = creditcard.verification_value
- form[:cvv2] = 'present'
+ add_verification_value(form, creditcard)
end
form[:first_name] = creditcard.first_name.to_s.slice(0, 20)
form[:last_name] = creditcard.last_name.to_s.slice(0, 30)
end
+ def add_verification_value(form, creditcard)
+ form[:cvv2cvc2] = creditcard.verification_value
+ form[:cvv2] = 'present'
+ end
+
def preamble
result = {
'merchant_id' => @options[:login],
'pin' => @options[:password],
'show_form' => 'false',
- 'test_mode' => @options[:test] ? 'TRUE' : 'FALSE',
+ 'test_mode' => test? ? 'TRUE' : 'FALSE',
'result_format' => 'ASCII',
}
result['user_id'] = @options[:user] unless @options[:user].blank?
result
end
+ def test?
+ @options[:test] || super
+ end
+
def commit(action, money, parameters)
parameters[:amount] = amount(money)
- parameters[:transaction_type] = action
+ parameters[:transaction_type] = self.actions[action]
- response = parse( ssl_post(test? ? TEST_URL : LIVE_URL, post_data(parameters)) )
+ response = parse( ssl_post(test? ? self.test_url : self.live_url, post_data(parameters)) )
- Response.new(response['result'] == APPROVED, response['result_message'], response,
+ Response.new(response['result'] == APPROVED, message_from(response), response,
:test => @options[:test] || test?,
- :authorization => response['txn_id'],
+ :authorization => authorization_from(response),
:avs_result => { :code => response['avs_response'] },
:cvv_result => response['cvv2_response']
)
end
+ def authorization_from(response)
+ response['txn_id']
+ end
+
+ def message_from(response)
+ response['result_message']
+ end
+
def post_data(parameters)
result = preamble
result.merge!(parameters)
result.collect { |key, value| "ssl_#{key}=#{CGI.escape(value.to_s)}" }.join("&")
end
@@ -152,12 +176,12 @@
end
# Parse the response message
def parse(msg)
resp = {}
- msg.split("\r\n").collect{|li|
+ msg.split(self.delimiter).collect{|li|
key, value = li.split("=")
- resp[key.gsub(/^ssl_/, '')] = value.to_s.strip
+ resp[key.strip.gsub(/^ssl_/, '')] = value.to_s.strip
}
resp
end
end
end
\ No newline at end of file