Skip to content

Instantly share code, notes, and snippets.

@theCrab
Created April 3, 2013 16:10
Show Gist options
  • Save theCrab/5302611 to your computer and use it in GitHub Desktop.
Save theCrab/5302611 to your computer and use it in GitHub Desktop.
Verifone UK Spree Payment Gateway Integration
# encoding: utf-8
require "rubygems"
require "net/telnet"
# request_params = "T,,01,0000,,,,,,,10.00,0.00000,,,,,,,,,,,\n"
begin
puts 'Trying.....'
printo = Net::Telnet::new( "Host" => "192.168.2.37", "Port" => 25000, "Telnetmode" => true )
puts 'Connected...'
printo.cmd(
{"String" => "T,,01,0000,,,,,,,10.00,0.00000,,,,,,,,,,,,,,4,1\r\n", "Timeout" => 45 }
) { |c| puts c }
puts 'Recieved response data[String] above'
# Verifone Error codes. There are 215 codes and they are [-1...-189] and [-999...-1014]. Just take the important ones :=(
# Example ERROR string '-31,1,10.00,0.00,,,,,,20130328190349,,,,,,,,SERVICE NOT ALLOWED'
#
error_codes = [
[ code: "-0", description: "Unspecified error", action: "Contact VeriFone" ],
[ code: "-31", description: "Invalid transaction type", action: " Use alternative method for transaction type" ],
]
res = printo.kind_of?(String) ? printo.strip.split(',') : printo.strip.split(',')
case res
when res.first == error_codes[:code]
puts "Error: #{error_codes[:code][:description]} \nAction: #{error_codes[:code][:action]}"
# On the VX680, success handshake closes port 25000 and sends a response on 25001
# response = Net::Telnet::new('Host' => '192.168.2.47', 'Port' => 25001)
#
# response example would be
# "0,1,10.00,0.00,0.00,************1234,0313,,0312,20130328185822,21249872,22736839,VISA DEBIT,,9027,789DE,,PIN VERIFIED"
when hand_shake.split(',')
puts 'error man'
end
printo.close
rescue Exception => e
puts "Class: #{e.class} => Message: #{e.message}"
end
@theCrab
Copy link
Author

theCrab commented Apr 3, 2013

@GeekOnCoffee How would you implement this considering am waiting on a Card terminal response?

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment