Initialize the Gateway
The gateway requires that a valid login and password be passed in the options hash.
:login — Merchant ID
:password — PIN
:user — Specify a subuser of the account (optional)
:test => true or false — Force test transactions
# File lib/active_merchant/billing/gateways/viaklix.rb, line 33 33: def initialize(options = {}) 34: requires!(options, :login, :password) 35: @options = options 36: super 37: 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
# File lib/active_merchant/billing/gateways/viaklix.rb, line 51 51: def credit(money, creditcard, options = {}) 52: if creditcard.is_a?(String) 53: raise ArgumentError, "Reference credits are not supported. Please supply the original credit card" 54: end 55: 56: form = {} 57: add_invoice(form, options) 58: add_creditcard(form, creditcard) 59: add_address(form, options) 60: add_customer_data(form, options) 61: commit(:credit, money, form) 62: end
Make a purchase
# File lib/active_merchant/billing/gateways/viaklix.rb, line 40 40: def purchase(money, creditcard, options = {}) 41: form = {} 42: add_invoice(form, options) 43: add_creditcard(form, creditcard) 44: add_address(form, options) 45: add_customer_data(form, options) 46: commit(:purchase, money, form) 47: end
# File lib/active_merchant/billing/gateways/viaklix.rb, line 75 75: def add_address(form,options) 76: billing_address = options[:billing_address] || options[:address] 77: 78: if billing_address 79: form[:avs_address] = billing_address[:address1].to_s.slice(0, 30) 80: form[:address2] = billing_address[:address2].to_s.slice(0, 30) 81: form[:avs_zip] = billing_address[:zip].to_s.slice(0, 10) 82: form[:city] = billing_address[:city].to_s.slice(0, 30) 83: form[:state] = billing_address[:state].to_s.slice(0, 10) 84: form[:company] = billing_address[:company].to_s.slice(0, 50) 85: form[:phone] = billing_address[:phone].to_s.slice(0, 20) 86: form[:country] = billing_address[:country].to_s.slice(0, 50) 87: end 88: 89: if shipping_address = options[:shipping_address] 90: first_name, last_name = parse_first_and_last_name(shipping_address[:name]) 91: form[:ship_to_first_name] = first_name.to_s.slice(0, 20) 92: form[:ship_to_last_name] = last_name.to_s.slice(0, 30) 93: form[:ship_to_address] = shipping_address[:address1].to_s.slice(0, 30) 94: form[:ship_to_city] = shipping_address[:city].to_s.slice(0, 30) 95: form[:ship_to_state] = shipping_address[:state].to_s.slice(0, 10) 96: form[:ship_to_company] = shipping_address[:company].to_s.slice(0, 50) 97: form[:ship_to_country] = shipping_address[:country].to_s.slice(0, 50) 98: form[:ship_to_zip] = shipping_address[:zip].to_s.slice(0, 10) 99: end 100: end
# File lib/active_merchant/billing/gateways/viaklix.rb, line 110 110: def add_creditcard(form, creditcard) 111: form[:card_number] = creditcard.number 112: form[:exp_date] = expdate(creditcard) 113: 114: if creditcard.verification_value? 115: add_verification_value(form, creditcard) 116: end 117: 118: form[:first_name] = creditcard.first_name.to_s.slice(0, 20) 119: form[:last_name] = creditcard.last_name.to_s.slice(0, 30) 120: end
# File lib/active_merchant/billing/gateways/viaklix.rb, line 65 65: def add_customer_data(form, options) 66: form[:email] = options[:email].to_s.slice(0, 100) unless options[:email].blank? 67: form[:customer_code] = options[:customer].to_s.slice(0, 10) unless options[:customer].blank? 68: end
# File lib/active_merchant/billing/gateways/viaklix.rb, line 70 70: def add_invoice(form,options) 71: form[:invoice_number] = (options[:order_id] || options[:invoice]).to_s.slice(0, 10) 72: form[:description] = options[:description].to_s.slice(0, 255) 73: end
# File lib/active_merchant/billing/gateways/viaklix.rb, line 122 122: def add_verification_value(form, creditcard) 123: form[:cvv2cvc2] = creditcard.verification_value 124: form[:cvv2] = 'present' 125: end
# File lib/active_merchant/billing/gateways/viaklix.rb, line 144 144: def commit(action, money, parameters) 145: parameters[:amount] = amount(money) 146: parameters[:transaction_type] = self.actions[action] 147: 148: response = parse( ssl_post(test? ? self.test_url : self.live_url, post_data(parameters)) ) 149: 150: Response.new(response['result'] == APPROVED, message_from(response), response, 151: :test => @options[:test] || test?, 152: :authorization => authorization_from(response), 153: :avs_result => { :code => response['avs_response'] }, 154: :cvv_result => response['cvv2_response'] 155: ) 156: end
# File lib/active_merchant/billing/gateways/viaklix.rb, line 172 172: def expdate(creditcard) 173: year = sprintf("%.4i", creditcard.year) 174: month = sprintf("%.2i", creditcard.month) 175: "#{month}#{year[2..3]}" 176: end
# File lib/active_merchant/billing/gateways/viaklix.rb, line 162 162: def message_from(response) 163: response['result_message'] 164: end
Parse the response message
# File lib/active_merchant/billing/gateways/viaklix.rb, line 179 179: def parse(msg) 180: resp = {} 181: msg.split(self.delimiter).collect{|li| 182: key, value = li.split("=") 183: resp[key.strip.gsub(/^ssl_/, '')] = value.to_s.strip 184: } 185: resp 186: end
# File lib/active_merchant/billing/gateways/viaklix.rb, line 102 102: def parse_first_and_last_name(value) 103: name = value.to_s.split(' ') 104: 105: last_name = name.pop || '' 106: first_name = name.join(' ') 107: [ first_name, last_name ] 108: end
# File lib/active_merchant/billing/gateways/viaklix.rb, line 166 166: def post_data(parameters) 167: result = preamble 168: result.merge!(parameters) 169: result.collect { |key, value| "ssl_#{key}=#{CGI.escape(value.to_s)}" }.join("&") 170: end
# File lib/active_merchant/billing/gateways/viaklix.rb, line 127 127: def preamble 128: result = { 129: 'merchant_id' => @options[:login], 130: 'pin' => @options[:password], 131: 'show_form' => 'false', 132: 'test_mode' => test? ? 'TRUE' : 'FALSE', 133: 'result_format' => 'ASCII', 134: } 135: 136: result['user_id'] = @options[:user] unless @options[:user].blank? 137: result 138: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.