ugalic_moneta 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ .DS_Store
6
+ .rvmrc
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in moneta.gemspec
4
+ gemspec
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
data/lib/moneta.rb ADDED
@@ -0,0 +1,73 @@
1
+ module Moneta
2
+ class Eterminal
3
+
4
+ def initialize(*args)
5
+ return self if args.empty?
6
+ params_hash = args[0]
7
+ key_file = params_hash[:key_file]
8
+ key_pwd = params_hash[:key_pwd]
9
+ cert_file = params_hash[:cert_file]
10
+ ca_cert_file = params_hash[:ca_cert_file]
11
+ wsdl_path = params_hash[:wsdl_file]
12
+
13
+ HTTPI::Adapter.use = :net_http
14
+
15
+ @client = Savon::Client.new do
16
+ wsdl.document = wsdl_path
17
+ http.auth.ssl.verify_mode = :none
18
+ http.auth.ssl.cert_key_file = key_file
19
+ http.auth.ssl.cert_key_password = key_pwd
20
+ http.auth.ssl.cert_file = cert_file
21
+ http.auth.ssl.ca_cert_file = ca_cert_file
22
+ http.headers = {
23
+ "User-Agent" => "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13 (.NET CLR 3.5.30729)",
24
+ "Accept" => "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
25
+ "Accept-Language" => "sl,en-us;q=0.7,en;q=0.3",
26
+ "Accept-Encoding" => "gzip, deflate",
27
+ "Accept-Charset" => "ISO-8859-1,utf-8;q=0.7,*;q=0.7",
28
+ "Keep-Alive" => "115",
29
+ "Connection" => "Keep-Alive",
30
+ "iis6-feature" => "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec porta libero eu neque hendrerit vel volutpat sapien aliquam. Aenean suscipit porta leo, in iaculis est ornare id. Vivamus dignissim vulputate sapien, sed euismod tellus ultrices ut. Pellentesque quam odio, varius vel tempus at, gravida nec mauris. Vestibulum sodales scelerisque nunc sit amet vulputate. Praesent iaculis ipsum vel leo luctus sodales."
31
+ }
32
+ end
33
+ end
34
+
35
+ def login(pin=nil)
36
+ savon_call(:log_in, {:pin => pin}).to_hash
37
+ rescue Exception => ex
38
+ {error_code: -1, error_description: ex.message}
39
+ end
40
+
41
+ def token(amount, pin=nil)
42
+ soap_body = {:amount => amount}
43
+ soap_body[:pin] = pin unless pin.nil?
44
+ savon_call(:get_token, soap_body).to_hash #amount should be in format "x.xx CURRENCY"
45
+ rescue Exception => ex
46
+ { error_code: -1, error_description: ex.message }
47
+ end
48
+
49
+ def transaction_status(transaction_id, pin=nil)
50
+ soap_body = {:transaction_id => transaction_id}
51
+ soap_body[:pin] = pin unless pin.nil?
52
+ savon_call(:get_transaction_status, soap_body).to_hash
53
+ rescue Exception => ex
54
+ {error_code: -1, error_description: ex.message}
55
+ end
56
+
57
+ def transaction_list(date, pin=nil)
58
+ soap_body = {:date => date}
59
+ soap_body[:pin] = pin unless pin.nil?
60
+ savon_call(:get_transaction_list, soap_body).to_hash
61
+ rescue Exception => ex
62
+ {error_code: -1, error_description: ex.message}
63
+ end
64
+
65
+ private
66
+
67
+ def savon_call(method, body)
68
+ envelope = @client.request :soap, method, :xmlns => 'http://www.mpay.si/mgw/ekanali/public/2007/03/29' do
69
+ soap.body = body
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,3 @@
1
+ module Moneta
2
+ VERSION = "0.0.1"
3
+ end
data/moneta.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "moneta/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "ugalic_moneta"
7
+ s.version = Moneta::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Uros Galic"]
10
+ s.email = ["uros.galic@antiveb.com"]
11
+ s.homepage = ""
12
+ s.summary = %q{Mobilte Moneta eTreminal}
13
+ s.description = %q{Provides communication with Moneta Web Service}
14
+
15
+ s.rubyforge_project = "ugalic_moneta"
16
+ s.add_development_dependency "rspec"
17
+
18
+ s.files = `git ls-files`.split("\n")
19
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
20
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
21
+ s.require_paths = ["lib"]
22
+
23
+ s.add_runtime_dependency 'savon', "~> 0.8.3"
24
+ end
@@ -0,0 +1,130 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe 'Moneta' do
4
+
5
+ context 'get token' do
6
+
7
+ before(:each) do
8
+ @terminal = Moneta::Eterminal.new
9
+ @amount = '10.00 EUR'
10
+ end
11
+
12
+ it 'should call moneta service' do
13
+ @terminal.should_receive(:savon_call).with(:get_token, anything())
14
+ @terminal.token(@amount)
15
+ end
16
+
17
+ it 'should handle exceptions' do
18
+ @terminal.stub(:moneta_call) { raise "Errror" }
19
+ res = @terminal.token(@amount)
20
+ res[:error_code].should == -1
21
+ end
22
+
23
+ it 'should return correct status, token and transId on success' do
24
+ @terminal.stub(:savon_call) { {token: '123', transaction_id: '134', error_code: '0', error_description: '', valid_until: '30.12.2011'} }
25
+ res = @terminal.token(@amount)
26
+ res[:token].should == '123'
27
+ res[:transaction_id].should == '134'
28
+ res[:error_code] == "0"
29
+ res[:error_description].should == ''
30
+ res[:valid_until].should == '30.12.2011'
31
+ end
32
+
33
+ it 'should return error if amount is greather than 1000000 or amount is not of proper format' do
34
+
35
+ end
36
+
37
+ it 'should return status, code and msg on failure' do
38
+ Moneta::Eterminal.stub(:savon_call) { raise "Error" }
39
+ res = @terminal.token(@amount)
40
+ res[:error_code].should == -1
41
+ res[:error_description].should_not == ""
42
+ end
43
+
44
+ end
45
+
46
+ context 'get transaction status' do
47
+
48
+ before(:each) do
49
+ @terminal = Moneta::Eterminal.new
50
+ @transaction_id = 12345
51
+ end
52
+
53
+ it 'should call moneta service' do
54
+ @terminal.should_receive(:savon_call).with(:get_transaction_status, anything())
55
+ @terminal.transaction_status(@transaction_id)
56
+ end
57
+
58
+ it 'should handle exceptions' do
59
+ @terminal.stub(:savon_call) { raise "Error" }
60
+ res = @terminal.transaction_status(@transaction_id)
61
+ res[:error_code].should == -1
62
+ res[:error_description].should_not be_empty
63
+ end
64
+
65
+ it 'should return reference_id and status when transaction is completed' do
66
+ @terminal.stub(:savon_call) { {status: '3', reference_id: '1234'} }
67
+ response = @terminal.transaction_status(@transaction_id)
68
+ response[:reference_id].should == '1234'
69
+ response[:status].should == '3'
70
+ end
71
+
72
+ it 'should return status 13 with description when transaction was unproperly processed by processing center' do
73
+ @terminal.stub(:savon_call) { {status: '13', error_description: 'insufficient funds'} }
74
+ response = @terminal.transaction_status(@transaction_id)
75
+ response[:status].should == '13'
76
+ response[:error_description].should == 'insufficient funds'
77
+ end
78
+
79
+ it 'should return status for transaction in process' do
80
+ @terminal.stub(:savon_call) { {status: '2', error_code: '0', error_description: '0'} }
81
+ response = @terminal.transaction_status(@transaction_id)
82
+ response[:status].should == '2'
83
+ end
84
+
85
+ it 'should handle exception' do
86
+ @terminal.stub(:savon_call) { raise 'Exception' }
87
+ response = @terminal.transaction_status(@transaction_id)
88
+ response[:error_code].should == -1
89
+ response[:error_description].should_not be_empty
90
+ end
91
+ end
92
+
93
+ context 'login' do
94
+
95
+ before(:each) do
96
+ @terminal = Moneta::Eterminal.new
97
+ @pin = nil
98
+ end
99
+
100
+ it 'should call moneta service' do
101
+ @terminal.should_receive(:savon_call).with(:log_in, anything())
102
+ @terminal.login(@pin)
103
+ end
104
+
105
+ it 'should handle exceptions' do
106
+ @terminal.stub(:savon_call) { raise 'Error' }
107
+ res = @terminal.login(@pin)
108
+ res[:error_code].should == -1
109
+ res[:error_description].should == 'Error'
110
+ end
111
+
112
+ it 'should return customer informations if certificate and pin are correct' do
113
+ @terminal.stub(:savon_call) { {mid: '9011', pid: '527', error_code: "0", customer_name: 'lorem ipsum', name: 'lorem'} }
114
+ response = @terminal.login(@pin)
115
+ response[:name].should == 'lorem'
116
+ response[:error_code].should == "0"
117
+ response[:mid].should == '9011'
118
+ response[:pid].should == '527'
119
+ response[:customer_name].should == 'lorem ipsum'
120
+ end
121
+
122
+ it 'should return error code with error description if processing center is having difficulties' do
123
+ @terminal.stub(:savon_call) { {error_code: '33', error_description: 'processing center is having problems'}}
124
+ response = @terminal.login(@pin)
125
+ response[:error_code].should == '33'
126
+ response[:error_description].should == 'processing center is having problems'
127
+ end
128
+ end
129
+
130
+ end
@@ -0,0 +1,8 @@
1
+ require 'rubygems'
2
+ require 'moneta'
3
+
4
+ RSpec.configure do |config|
5
+
6
+ config.mock_with :rspec
7
+
8
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ugalic_moneta
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - Uros Galic
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-02-22 00:00:00 +01:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: rspec
18
+ prerelease: false
19
+ requirement: &id001 !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: "0"
25
+ type: :development
26
+ version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
28
+ name: savon
29
+ prerelease: false
30
+ requirement: &id002 !ruby/object:Gem::Requirement
31
+ none: false
32
+ requirements:
33
+ - - ~>
34
+ - !ruby/object:Gem::Version
35
+ version: 0.8.3
36
+ type: :runtime
37
+ version_requirements: *id002
38
+ description: Provides communication with Moneta Web Service
39
+ email:
40
+ - uros.galic@antiveb.com
41
+ executables: []
42
+
43
+ extensions: []
44
+
45
+ extra_rdoc_files: []
46
+
47
+ files:
48
+ - .gitignore
49
+ - Gemfile
50
+ - Rakefile
51
+ - lib/moneta.rb
52
+ - lib/moneta/version.rb
53
+ - moneta.gemspec
54
+ - spec/moneta_spec.rb
55
+ - spec/spec_helper.rb
56
+ has_rdoc: true
57
+ homepage: ""
58
+ licenses: []
59
+
60
+ post_install_message:
61
+ rdoc_options: []
62
+
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: "0"
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: "0"
77
+ requirements: []
78
+
79
+ rubyforge_project: ugalic_moneta
80
+ rubygems_version: 1.5.0
81
+ signing_key:
82
+ specification_version: 3
83
+ summary: Mobilte Moneta eTreminal
84
+ test_files:
85
+ - spec/moneta_spec.rb
86
+ - spec/spec_helper.rb