Skip to content

Instantly share code, notes, and snippets.

@anwajler
Created May 8, 2011 11:50
Show Gist options
  • Save anwajler/961321 to your computer and use it in GitHub Desktop.
Save anwajler/961321 to your computer and use it in GitHub Desktop.
Smartpay.pl handling
require 'net/http'
require 'net/https'
MESSAGES = {
# OK
"1001" => "kod zostal znaleziony i jest aktywny",
# INACTIVE
"2001" => "szukany kod nie zostal znaleziony",
"2002" => "kod zostal znaleziony, ale nie jest juz aktywny",
# ERROR
"3001" => "brakuje ktoregos z parametrow (password, service lub code)",
"3004" => "podany identyfikator (parametr 'service') jest nieprawidlowy",
"3005" => "ktorys z parametrow ma nieprawidlowy format",
"3006" => "bledna kombinacja hasla uzytkownika i identyfikatora (subprefixu)",
"5001" => "blad wewnetrzny po stronie serwera Smartpay"
}
host = 'www.smartpay.pl'
code = ''
service = ''
password = ''
rate = ''
just_check = 'true'
http = Net::HTTP.new(host, 443)
http.use_ssl = true
path = "/check/?service=#{service}&password=#{password}&code=#{code}&just_check=#{just_check}&rate=#{rate}"
# GET request -> so the host can set his cookies
resp, data = http.get(path, nil)
status, message = data.split("\n")
msg_id = message.split(":")[0]
case status
when "OK"
puts MESSAGES[msg_id]
when "INACTIVE"
puts MESSAGES[msg_id]
when "ERROR"
puts MESSAGES[msg_id]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment