webmoney 0.0.7 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +1 -0
- data/ChangeLog +7 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +41 -0
- data/README +7 -0
- data/VERSION +1 -1
- data/ext/wmsigner/extconf.rb +1 -0
- data/ext/wmsigner/wmsigner.cpp +5 -5
- data/lib/messenger.rb +1 -0
- data/lib/passport.rb +1 -0
- data/lib/purse.rb +1 -0
- data/lib/request_result.rb +1 -0
- data/lib/request_retval.rb +1 -0
- data/lib/request_xml.rb +1 -0
- data/lib/webmoney.rb +6 -1
- data/lib/wmid.rb +1 -0
- data/spec/spec_helper.rb +11 -7
- data/spec/unit/messenger_spec.rb +33 -36
- data/spec/unit/passport_spec.rb +107 -121
- data/spec/unit/purse_spec.rb +36 -39
- data/spec/unit/signer_spec.rb +2 -1
- data/spec/unit/time_spec.rb +2 -1
- data/spec/unit/webmoney_spec.rb +144 -122
- data/spec/unit/wmid_spec.rb +18 -21
- data/webmoney.gemspec +4 -2
- metadata +6 -4
data/.gitignore
CHANGED
data/ChangeLog
CHANGED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
---
|
2
|
+
dependencies:
|
3
|
+
rspec:
|
4
|
+
group:
|
5
|
+
- :default
|
6
|
+
version: ">= 0"
|
7
|
+
rake-compiler:
|
8
|
+
group:
|
9
|
+
- :default
|
10
|
+
version: ">= 0"
|
11
|
+
jeweler:
|
12
|
+
group:
|
13
|
+
- :default
|
14
|
+
version: ">= 0"
|
15
|
+
nokogiri:
|
16
|
+
group:
|
17
|
+
- :default
|
18
|
+
version: ">= 0"
|
19
|
+
specs:
|
20
|
+
- rake:
|
21
|
+
version: 0.8.7
|
22
|
+
- gemcutter:
|
23
|
+
version: 0.6.1
|
24
|
+
- git:
|
25
|
+
version: 1.2.5
|
26
|
+
- json_pure:
|
27
|
+
version: 1.4.6
|
28
|
+
- rubyforge:
|
29
|
+
version: 2.0.4
|
30
|
+
- jeweler:
|
31
|
+
version: 1.4.0
|
32
|
+
- nokogiri:
|
33
|
+
version: 1.4.3.1
|
34
|
+
- rake-compiler:
|
35
|
+
version: 0.7.1
|
36
|
+
- rspec:
|
37
|
+
version: 1.3.0
|
38
|
+
hash: 46b2419c1fae88ace745852a84f3ee395ef8a70e
|
39
|
+
sources:
|
40
|
+
- Rubygems:
|
41
|
+
uri: http://rubygems.org
|
data/README
CHANGED
@@ -5,6 +5,7 @@ XML-interfaces: http://www.wmtransfer.com/eng/developers/interfaces/index.shtml
|
|
5
5
|
|
6
6
|
Gem have built-in native *wmsigner*.
|
7
7
|
|
8
|
+
Compatible with ruby: 1.8.7, 1.9.2
|
8
9
|
Reqirements: Nokogiri >= 1.4.1 built with libxml2 >= 2.7 (IMPORTANT!)
|
9
10
|
|
10
11
|
Author:: Alexander Oryol (mailto:eagle.alex@gmail.com)
|
@@ -61,6 +62,12 @@ end
|
|
61
62
|
|
62
63
|
wmid = '111222333444'
|
63
64
|
|
65
|
+
= Light
|
66
|
+
|
67
|
+
cert = OpenSSL::X509::Certificate.new(File.read("webmoney.cert"))
|
68
|
+
key = OpenSSL::PKey::RSA.new(File.read("webmoney.key"), "password")
|
69
|
+
mywm = MyWM.new(:wmid => '123456789012', :cert => cert, :key => key)
|
70
|
+
|
64
71
|
= Passport (X11)
|
65
72
|
|
66
73
|
Get attestat data:
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.8
|
data/ext/wmsigner/extconf.rb
CHANGED
data/ext/wmsigner/wmsigner.cpp
CHANGED
@@ -48,22 +48,22 @@ extern "C" VALUE signer_new(VALUE self, VALUE szWMID, VALUE szPwd, VALUE szKeyDa
|
|
48
48
|
if(NIL_P(szWMID)) rb_raise(rb_eArgError, "nil wmid");
|
49
49
|
|
50
50
|
// check WMID
|
51
|
-
if (! IsWmid(
|
51
|
+
if (! IsWmid(RSTRING_PTR(szWMID))) rb_raise(rb_eArgError, "Incorrect WMID");
|
52
52
|
|
53
53
|
if(NIL_P(szPwd)) rb_raise(rb_eArgError, "nil password");
|
54
54
|
|
55
55
|
if(NIL_P(szKeyData64)) rb_raise(rb_eArgError, "nil key");
|
56
56
|
|
57
57
|
// check base64 data
|
58
|
-
if (
|
58
|
+
if ( RSTRING_LEN(szKeyData64) != 220 ) rb_raise(rb_eArgError, "Illegal size for base64 keydata");
|
59
59
|
|
60
60
|
char KeyBuffer[ASCII_SIZE];
|
61
|
-
int bytes = code64( ENCODE, KeyBuffer, ASCII_SIZE,
|
61
|
+
int bytes = code64( ENCODE, KeyBuffer, ASCII_SIZE, RSTRING_PTR(szKeyData64), BUF_64_SIZE );
|
62
62
|
|
63
63
|
// check encoded key
|
64
64
|
if ( bytes != 164) rb_raise(rb_eArgError, "Illegal size for keydata");
|
65
65
|
|
66
|
-
pSign = new Signer(
|
66
|
+
pSign = new Signer(RSTRING_PTR(szWMID), RSTRING_PTR(szPwd), "");
|
67
67
|
VALUE tdata = Data_Wrap_Struct(self, 0, signer_free, pSign);
|
68
68
|
|
69
69
|
pSign->isIgnoreKeyFile = TRUE;
|
@@ -93,7 +93,7 @@ extern "C" VALUE signer_sign(VALUE self, VALUE szIn)
|
|
93
93
|
if (pSign)
|
94
94
|
{
|
95
95
|
szptr szSign;
|
96
|
-
if (pSign->Sign(
|
96
|
+
if (pSign->Sign(RSTRING_PTR(szIn), szSign))
|
97
97
|
{
|
98
98
|
ret = rb_str_new2((char *)(const char *)szSign);
|
99
99
|
}
|
data/lib/messenger.rb
CHANGED
data/lib/passport.rb
CHANGED
data/lib/purse.rb
CHANGED
data/lib/request_result.rb
CHANGED
data/lib/request_retval.rb
CHANGED
data/lib/request_xml.rb
CHANGED
data/lib/webmoney.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
#encoding: utf-8
|
1
2
|
# :title:Webmoney library Documentation
|
2
3
|
# :main:lib/webmoney.rb
|
3
4
|
# :include:README
|
@@ -96,7 +97,7 @@ module Webmoney
|
|
96
97
|
when OpenSSL::PKey::RSA, OpenSSL::PKey::DSA
|
97
98
|
@key = opt[:key]
|
98
99
|
@cert = opt[:cert]
|
99
|
-
|
100
|
+
#@password = opt[:password]
|
100
101
|
end
|
101
102
|
|
102
103
|
# ca_cert or default
|
@@ -193,6 +194,10 @@ module Webmoney
|
|
193
194
|
else
|
194
195
|
raise CaCertificateError, @ca_cert
|
195
196
|
end
|
197
|
+
unless classic?
|
198
|
+
http.cert = @cert
|
199
|
+
http.key = @key
|
200
|
+
end
|
196
201
|
http.use_ssl = true
|
197
202
|
@last_request = xml
|
198
203
|
@last_response = result = http.post( url.path, xml, "Content-Type" => "text/xml" )
|
data/lib/wmid.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
#encoding: utf-8
|
1
2
|
require 'rubygems'
|
2
3
|
require 'test/unit'
|
3
4
|
require 'spec'
|
@@ -16,11 +17,14 @@ end
|
|
16
17
|
|
17
18
|
class TestWM
|
18
19
|
include Webmoney
|
19
|
-
end
|
20
20
|
|
21
|
-
def
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
21
|
+
def initialize(opt = {})
|
22
|
+
defaults = {:wmid => WmConfig.wmid,
|
23
|
+
:password => WmConfig.password,
|
24
|
+
:key => WmConfig.key,
|
25
|
+
:ca_cert => WmConfig.ca_cert}
|
26
|
+
defaults.merge!(opt)
|
27
|
+
super(defaults)
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
data/spec/unit/messenger_spec.rb
CHANGED
@@ -1,46 +1,43 @@
|
|
1
|
-
|
1
|
+
#encoding: utf-8
|
2
|
+
require 'spec_helper'
|
2
3
|
|
3
|
-
|
4
|
+
describe Webmoney::Messenger, "class" do
|
4
5
|
|
5
|
-
|
6
|
+
before(:each) do
|
7
|
+
@wm = TestWM.new
|
8
|
+
@params = { :wmid => @wm.wmid, :subj => 'FIRST', :text => 'BODY' }
|
9
|
+
end
|
6
10
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
it "should create instance" do
|
13
|
-
@wm.messenger.should be_nil
|
14
|
-
@wm.send_message(@params)
|
15
|
-
@wm.messenger.should be_instance_of(Messenger)
|
16
|
-
end
|
11
|
+
it "should create instance" do
|
12
|
+
@wm.messenger.should be_nil
|
13
|
+
@wm.send_message(@params)
|
14
|
+
@wm.messenger.should be_instance_of(Webmoney::Messenger)
|
15
|
+
end
|
17
16
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
end
|
17
|
+
it "should send with logger call" do
|
18
|
+
self.should_receive(:log_it).once()
|
19
|
+
logger = Proc.new do |msg, result|
|
20
|
+
case result
|
21
|
+
when Hash
|
22
|
+
log_it "Message #{msg.inspect} sended in:#{result[:date]} with id:#{result[:id]}"
|
23
|
+
else
|
24
|
+
log_it "Error sent message #{msg.inspect}: #{result.message}"
|
27
25
|
end
|
28
|
-
@wm.messenger = Messenger.new(@wm, &logger)
|
29
|
-
@wm.send_message(@params)
|
30
|
-
sleep(2)
|
31
|
-
end
|
32
|
-
|
33
|
-
it "should call request(:send_message) twice" do
|
34
|
-
# if spec failed here, increase sleep time
|
35
|
-
@wm.should_receive(:request).
|
36
|
-
with(:send_message, @params).twice().and_return({:test => 'test'})
|
37
|
-
2.times {@wm.send_message(@params)}
|
38
|
-
# Don't take:
|
39
|
-
# @wm.messenger.thread.join
|
40
|
-
# this will create deadlock
|
41
|
-
sleep(2)
|
42
26
|
end
|
27
|
+
@wm.messenger = Webmoney::Messenger.new(@wm, &logger)
|
28
|
+
@wm.send_message(@params)
|
29
|
+
sleep(2)
|
30
|
+
end
|
43
31
|
|
32
|
+
it "should call request(:send_message) twice" do
|
33
|
+
# if spec failed here, increase sleep time
|
34
|
+
@wm.should_receive(:request).
|
35
|
+
with(:send_message, @params).twice().and_return({:test => 'test'})
|
36
|
+
2.times {@wm.send_message(@params)}
|
37
|
+
# Don't take:
|
38
|
+
# @wm.messenger.thread.join
|
39
|
+
# this will create deadlock
|
40
|
+
sleep(2)
|
44
41
|
end
|
45
42
|
|
46
43
|
end
|
data/spec/unit/passport_spec.rb
CHANGED
@@ -1,140 +1,126 @@
|
|
1
|
-
|
1
|
+
#encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
require 'date'
|
2
4
|
|
3
|
-
|
5
|
+
describe Webmoney::Passport, "class" do
|
4
6
|
|
5
|
-
|
7
|
+
before(:each) do
|
8
|
+
@wm = TestWM.new
|
9
|
+
end
|
6
10
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
it "should return Passport instance" do
|
12
|
-
Passport.new(@wm.wmid).should be_instance_of(Passport)
|
13
|
-
end
|
11
|
+
it "should return Passport instance" do
|
12
|
+
Webmoney::Passport.new(@wm.wmid).should be_instance_of(Webmoney::Passport)
|
13
|
+
end
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
res[:attestat].should
|
24
|
-
|
25
|
-
:locked=>"1",
|
26
|
-
:recalled=>"0",
|
27
|
-
:cid=>"103453",
|
28
|
-
:admlocked=>"0",
|
29
|
-
:created_at=>created_at,
|
30
|
-
:datecrt=>"2004-02-25T21:54:01.370",
|
31
|
-
:regnickname=>"WM Passport Service /Центр аттестации/",
|
32
|
-
:regwmid=>"464889785562",
|
33
|
-
:attestat=>150,
|
34
|
-
:tid=>"150",
|
35
|
-
:datediff=>(Date.today - created_at.send(:to_date)).to_s
|
36
|
-
}
|
15
|
+
it "request result get_passport should be hash with data" do
|
16
|
+
wmid = '000000000007'
|
17
|
+
res = @wm.request(:get_passport, :wmid => wmid, :dict => 1)
|
18
|
+
res[:full_access].should be_false
|
19
|
+
res[:wmids][wmid][:created_at].should be_a(Time)
|
20
|
+
res[:attestat][:created_at].should be_a(Time)
|
21
|
+
[:regcid, :locked, :recalled, :cid, :admlocked, :created_at, :datecrt, :regnickname,
|
22
|
+
:regwmid, :attestat, :tid, :datediff].each do |key|
|
23
|
+
res[:attestat].should have_key(key)
|
24
|
+
end
|
37
25
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
26
|
+
u_info = {
|
27
|
+
:locked=>"0",
|
28
|
+
:ctype=>"1",
|
29
|
+
:citid=>"12918",
|
30
|
+
:cap_owner=>"0",
|
31
|
+
:region=>"Москва",
|
32
|
+
:countryid=>"195",
|
33
|
+
:city=>"Москва",
|
34
|
+
:pasdoc=>"0",
|
35
|
+
:nickname=>"Арбитр",
|
36
|
+
:country=>"Россия",
|
37
|
+
:inndoc=>"0",
|
38
|
+
:sex=>"0",
|
39
|
+
:email=>"", :pdateMMDDYYYY => "", :pday => "", :pmonth => "", :pyear => "",
|
40
|
+
:iname=>"", :inn=>"", :okonx=>"", :bik=>"", :pbywhom=>"", :phonemobile=>"", :rcountry=>"",
|
41
|
+
:bmonth=>"", :jadres=>"", :okpo=>"", :bday=>"", :pnomer=>"", :bankname=>"", :pcountry=>"", :pcountryid=>"",
|
42
|
+
:jcountryid=>"", :ks=>"", :infoopen=>"", :icq=>"", :byear=>"", :oname=>"", :osnovainfo=>"", :dirfio=>"",
|
43
|
+
:pdate=>"", :bplace=>"", :rs=>"", :rcity=>"", :adres=>"", :phone=>"", :buhfio=>"", :radres=>"", :fname=>"",
|
44
|
+
:phonehome=>"", :jcity=>"", :name=>"", :pcity=>"", :jstatus=>"", :fax=>"", :zipcode=>"", :rcountryid=>"",
|
45
|
+
:web=>"", :jzipcode=>"", :jcountry=>"", :jabberid=>""
|
46
|
+
}
|
59
47
|
|
60
48
|
# a1 = res[:userinfo].keys.map(&:to_s).sort
|
61
49
|
# a2 = u_info.keys.map(&:to_s).sort
|
62
50
|
# puts ((a1|a2) - (a1 & a2)).inspect
|
63
51
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
}
|
52
|
+
res[:userinfo].should == u_info
|
53
|
+
|
54
|
+
res[:directory].should == {
|
55
|
+
:ctype=>{
|
56
|
+
1=>"Частное лицо",
|
57
|
+
2=>"Юридическое лицо"
|
58
|
+
},
|
59
|
+
:jstatus=>{
|
60
|
+
20=>"Директор юридического лица",
|
61
|
+
21=>"Бухгалтер юридического лица",
|
62
|
+
22=>"Представитель юридического лица",
|
63
|
+
23=>"ИП"
|
64
|
+
},
|
65
|
+
:types=>{
|
66
|
+
100=>"Аттестат псевдонима",
|
67
|
+
110=>"Формальный аттестат",
|
68
|
+
120=>"Начальный аттестат",
|
69
|
+
130=>"Персональный аттестат",
|
70
|
+
135=>"Аттестат продавца",
|
71
|
+
136=>"Аттестат Capitaller",
|
72
|
+
140=>"Аттестат разработчика",
|
73
|
+
150=>"Аттестат регистратора",
|
74
|
+
170=>"Аттестат Гаранта",
|
75
|
+
190=>"Аттестат сервиса WMT",
|
76
|
+
200=>"Аттестат сервиса WMT",
|
77
|
+
300=>"Аттестат Оператора"
|
91
78
|
}
|
92
|
-
|
93
|
-
|
94
|
-
it "should return userinfo attributes with checked/locked" do
|
95
|
-
wmid = '000000000007'
|
96
|
-
p = Passport.new(wmid)
|
97
|
-
p.userinfo[:adres].should be_empty
|
98
|
-
p.userinfo[:adres].checked.should be_true
|
99
|
-
p.userinfo[:adres].locked.should be_true
|
100
|
-
p.userinfo[:inn].should be_empty
|
101
|
-
p.userinfo[:inn].checked.should be_false
|
102
|
-
p.userinfo[:inn].locked.should be_true
|
103
|
-
end
|
79
|
+
}
|
80
|
+
end
|
104
81
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
p.wmid.should == wmid
|
116
|
-
p.attestat[:attestat].should == Webmoney::Passport::ALIAS
|
117
|
-
p.attestat[:created_at].strftime('%Y-%m-%d %H:%M:%S').should == '2006-04-19 10:16:30'
|
118
|
-
|
119
|
-
wmid = '210971342927'
|
120
|
-
p = Passport.new(wmid)
|
121
|
-
p.attestat.should_not be_nil
|
122
|
-
end
|
82
|
+
it "should return userinfo attributes with checked/locked" do
|
83
|
+
wmid = '000000000007'
|
84
|
+
p = Webmoney::Passport.new(wmid)
|
85
|
+
p.userinfo[:adres].should be_empty
|
86
|
+
p.userinfo[:adres].checked.should be_true
|
87
|
+
p.userinfo[:adres].locked.should be_true
|
88
|
+
p.userinfo[:inn].should be_empty
|
89
|
+
p.userinfo[:inn].checked.should be_false
|
90
|
+
p.userinfo[:inn].locked.should be_true
|
91
|
+
end
|
123
92
|
|
124
|
-
|
125
|
-
|
126
|
-
|
93
|
+
it "should return correct fields" do
|
94
|
+
wmid = '000000000007'
|
95
|
+
p = Webmoney::Passport.new(wmid)
|
96
|
+
p.wmid.should == wmid
|
97
|
+
p.attestat[:attestat].should == Webmoney::Passport::REGISTRATOR
|
98
|
+
p.attestat[:created_at].strftime('%Y-%m-%d %H:%M:%S').should == '2004-02-25 21:54:01'
|
99
|
+
p.full_access.should be_false
|
100
|
+
|
101
|
+
wmid = '370860915669'
|
102
|
+
p = Webmoney::Passport.new(wmid)
|
103
|
+
p.wmid.should == wmid
|
104
|
+
p.attestat[:attestat].should == Webmoney::Passport::ALIAS
|
105
|
+
p.attestat[:created_at].strftime('%Y-%m-%d %H:%M:%S').should == '2006-04-19 10:16:30'
|
106
|
+
|
107
|
+
wmid = '210971342927'
|
108
|
+
p = Webmoney::Passport.new(wmid)
|
109
|
+
p.attestat.should_not be_nil
|
110
|
+
end
|
127
111
|
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
end
|
112
|
+
it "should raise exception on bad WMID" do
|
113
|
+
lambda {@wm.request(:get_passport, :wmid => '111')}.should raise_error(Webmoney::ResultError)
|
114
|
+
end
|
132
115
|
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
116
|
+
it "should raise exception on non existent WMID" do
|
117
|
+
@wm.stub!(:http_request).and_return("<?xml version='1.0' encoding='windows-1251'?><response retval='0'><fullaccess>0</fullaccess><certinfo wmid='012345678901'/><retdesc>WMID not found</retdesc></response>")
|
118
|
+
lambda {@wm.request(:get_passport, :wmid => '012345678901')}.should raise_error(Webmoney::NonExistentWmidError)
|
119
|
+
end
|
137
120
|
|
121
|
+
it "should raise exception on blank response" do
|
122
|
+
@wm.stub!(:http_request).and_return(nil)
|
123
|
+
lambda {@wm.request(:get_passport, :wmid => '012345678901')}.should raise_error(Webmoney::NonExistentWmidError)
|
138
124
|
end
|
139
125
|
|
140
126
|
end
|
data/spec/unit/purse_spec.rb
CHANGED
@@ -1,54 +1,51 @@
|
|
1
|
-
|
1
|
+
#encoding: utf-8
|
2
|
+
require 'spec_helper'
|
2
3
|
|
3
|
-
|
4
|
+
describe Webmoney::Purse, "class" do
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
@wm = webmoney
|
10
|
-
end
|
11
|
-
|
12
|
-
before(:each) do
|
13
|
-
@t = Purse.new('Z136894439563')
|
14
|
-
end
|
6
|
+
before(:all) do
|
7
|
+
# initialize worker
|
8
|
+
@wm = TestWM.new
|
9
|
+
end
|
15
10
|
|
16
|
-
|
17
|
-
|
18
|
-
|
11
|
+
before(:each) do
|
12
|
+
@t = Webmoney::Purse.new('Z136894439563')
|
13
|
+
end
|
19
14
|
|
20
|
-
|
21
|
-
|
22
|
-
|
15
|
+
it "should be kind of Wmid" do
|
16
|
+
@t.should be_kind_of(Webmoney::Purse)
|
17
|
+
end
|
23
18
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
end
|
19
|
+
it "should be string" do
|
20
|
+
@t.should == 'Z136894439563'
|
21
|
+
end
|
28
22
|
|
29
|
-
|
30
|
-
|
31
|
-
|
23
|
+
it "should raise error on incorrect" do
|
24
|
+
lambda{ Webmoney::Purse.new('X123456789012') }.
|
25
|
+
should raise_error(Webmoney::IncorrectPurseError)
|
26
|
+
end
|
32
27
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
end
|
28
|
+
it "should return wmid" do
|
29
|
+
@t.wmid.should == '405424574082'
|
30
|
+
end
|
37
31
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
32
|
+
it "should return true" do
|
33
|
+
@wm.should_receive(:request).with(:find_wm, :purse => @t).and_return(:retval=>1, :wmid => '405424574082')
|
34
|
+
@t.belong_to?('405424574082').should be_true
|
35
|
+
end
|
42
36
|
|
43
|
-
|
37
|
+
it "should return false" do
|
38
|
+
@wm.should_receive(:request).with(:find_wm, :purse => @t).and_return(:retval=>0)
|
39
|
+
@t.belong_to?('123456789012').should be_false
|
40
|
+
end
|
44
41
|
|
45
|
-
|
42
|
+
context "memoize" do
|
46
43
|
|
47
|
-
|
48
|
-
@wm.should_not_receive(:request).with(:find_wm, :purse => @t)
|
49
|
-
@t.belong_to?('405424574082').should be_true
|
50
|
-
end
|
44
|
+
before(:each) { @t.wmid }
|
51
45
|
|
46
|
+
it "it" do
|
47
|
+
@wm.should_not_receive(:request).with(:find_wm, :purse => @t)
|
48
|
+
@t.belong_to?('405424574082').should be_true
|
52
49
|
end
|
53
50
|
|
54
51
|
end
|
data/spec/unit/signer_spec.rb
CHANGED
data/spec/unit/time_spec.rb
CHANGED
data/spec/unit/webmoney_spec.rb
CHANGED
@@ -1,144 +1,166 @@
|
|
1
|
-
|
1
|
+
#encoding: utf-8
|
2
|
+
require 'spec_helper'
|
2
3
|
|
3
|
-
|
4
|
+
describe Webmoney, "class" do
|
4
5
|
|
5
|
-
|
6
|
+
before(:each) do
|
7
|
+
@wm = TestWM.new
|
8
|
+
end
|
6
9
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
+
it "should be classic" do
|
11
|
+
@wm.should be_classic # @wm.classic? == true
|
12
|
+
end
|
10
13
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
t2 = @wm.send(:reqn)
|
19
|
-
t1.should match(/^\d{16}$/)
|
20
|
-
(t2 > t1).should be_true
|
21
|
-
end
|
14
|
+
it "should return reqn" do
|
15
|
+
t1 = @wm.send(:reqn)
|
16
|
+
sleep(0.1)
|
17
|
+
t2 = @wm.send(:reqn)
|
18
|
+
t1.should match(/^\d{16}$/)
|
19
|
+
(t2 > t1).should be_true
|
20
|
+
end
|
22
21
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
22
|
+
it "should correct prepare interfaces urls" do
|
23
|
+
wm = TestWM.new :wmid => WmConfig.wmid , :key => nil
|
24
|
+
wm.should_not be_classic
|
25
|
+
wm.interfaces[:balance].class.should == URI::HTTPS
|
26
|
+
# converted to light-auth version
|
27
|
+
wm.interfaces[:balance].to_s.should == 'https://w3s.wmtransfer.com/asp/XMLPursesCert.asp'
|
28
|
+
# non-converted to light-auth version
|
29
|
+
wm.interfaces[:get_passport].to_s.should == 'https://passport.webmoney.ru/asp/XMLGetWMPassport.asp'
|
30
|
+
end
|
32
31
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
32
|
+
it "should correct reqn" do
|
33
|
+
Time.stub!(:now).and_return(Time.at(1244704683.69677))
|
34
|
+
@wm.send(:reqn).should == '2009061111180369'
|
35
|
+
end
|
37
36
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
37
|
+
it "should correct reqn with zero microsec" do
|
38
|
+
Time.stub!(:now).and_return(Time.at(1244704683))
|
39
|
+
@wm.send(:reqn).should == '2009061111180300'
|
40
|
+
end
|
42
41
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
it "should send request" do
|
49
|
-
doc = Nokogiri.XML(@wm.send(:https_request, :check_sign, '<w3s.request/>'))
|
50
|
-
doc.root.should_not be_nil
|
51
|
-
end
|
42
|
+
it "should raise error on incorrect arg" do
|
43
|
+
lambda { @wm.send(:request, :check_sign, 1) }.
|
44
|
+
should raise_error(ArgumentError)
|
45
|
+
end
|
52
46
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
@wm.error.should == '404'
|
58
|
-
@wm.errormsg.should match(/^<!DOCTYPE HTML PUBLIC/)
|
59
|
-
end
|
47
|
+
it "should send request" do
|
48
|
+
doc = Nokogiri.XML(@wm.send(:https_request, :check_sign, '<w3s.request/>'))
|
49
|
+
doc.root.should_not be_nil
|
50
|
+
end
|
60
51
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
52
|
+
it"should raise error on bad response" do
|
53
|
+
lambda { @wm.send(:https_request,
|
54
|
+
'https://w3s.wmtransfer.com/asp/XMLUnexistantIface.asp', '<w3s.request/>')}.
|
55
|
+
should raise_error(Webmoney::RequestError)
|
56
|
+
@wm.error.should == '404'
|
57
|
+
@wm.errormsg.should match(/^<!DOCTYPE HTML PUBLIC/)
|
58
|
+
end
|
66
59
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
@wm.send(:sign, '').should be_nil
|
73
|
-
end
|
74
|
-
|
75
|
-
it "should check_sign" do
|
76
|
-
plan = 'test123'
|
77
|
-
@wm.request(:check_sign,
|
78
|
-
:wmid => @wm.wmid, :plan => plan, :sign => @wm.send(:sign, plan)).
|
79
|
-
should be_true
|
80
|
-
end
|
60
|
+
it "should parse retval and raise error" do
|
61
|
+
lambda { @wm.request(:send_message, :wmid => '')}.should raise_error(Webmoney::ResultError)
|
62
|
+
@wm.error.should == -2
|
63
|
+
@wm.errormsg.should match(%r{value of w3s.request/message/receiverwmid is incorrect})
|
64
|
+
end
|
81
65
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
:wmid => @wm.wmid, :plan => plan, :sign => 'abcd').
|
86
|
-
should be_false
|
87
|
-
end
|
88
|
-
|
89
|
-
it "should check_sign with specials" do
|
90
|
-
plan = '<test>текст</test>'
|
91
|
-
real_plan = Iconv.conv('CP1251', 'UTF-8', plan)
|
92
|
-
begin
|
93
|
-
@wm.request(:check_sign,
|
94
|
-
:wmid => @wm.wmid,
|
95
|
-
:plan => plan,
|
96
|
-
:sign => @wm.send(:sign, real_plan )
|
97
|
-
).should be_true
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
it "should parse retval and raise error on broken get_passport" do
|
102
|
-
lambda { @wm.request(:get_passport, :wmid => '') }.should raise_error(ResultError)
|
103
|
-
@wm.error.should == 2
|
104
|
-
@wm.errormsg.should match(%r{неверно указан проверяемый WMID})
|
105
|
-
end
|
66
|
+
it "should sign string" do
|
67
|
+
@wm.send(:sign, 'Test123').should match(/^[0-9a-f]{132}$/)
|
68
|
+
end
|
106
69
|
|
107
|
-
|
108
|
-
|
109
|
-
|
70
|
+
it "should return nil on sign empty string" do
|
71
|
+
@wm.send(:sign, '').should be_nil
|
72
|
+
end
|
110
73
|
|
111
|
-
|
112
|
-
|
113
|
-
|
74
|
+
it "should check_sign" do
|
75
|
+
plan = 'test123'
|
76
|
+
@wm.request(:check_sign,
|
77
|
+
:wmid => @wm.wmid, :plan => plan, :sign => @wm.send(:sign, plan)).
|
78
|
+
should be_true
|
79
|
+
end
|
114
80
|
|
115
|
-
|
116
|
-
|
117
|
-
|
81
|
+
it "should check_sign broken" do
|
82
|
+
plan = 'test123'
|
83
|
+
@wm.request(:check_sign,
|
84
|
+
:wmid => @wm.wmid, :plan => plan, :sign => 'abcd').
|
85
|
+
should be_false
|
86
|
+
end
|
118
87
|
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
:text => 'Тело <b>сообщения</b>')
|
129
|
-
result.should be_kind_of(Hash)
|
130
|
-
result[:id].should match(/^\d*$/)
|
131
|
-
((result[:date] + 60) > Time.now).should be_true
|
88
|
+
it "should check_sign with specials" do
|
89
|
+
plan = '<test>текст</test>'
|
90
|
+
real_plan = Iconv.conv('CP1251', 'UTF-8', plan)
|
91
|
+
begin
|
92
|
+
@wm.request(:check_sign,
|
93
|
+
:wmid => @wm.wmid,
|
94
|
+
:plan => plan,
|
95
|
+
:sign => @wm.send(:sign, real_plan )
|
96
|
+
).should be_true
|
132
97
|
end
|
98
|
+
end
|
133
99
|
|
134
|
-
|
135
|
-
|
136
|
-
|
100
|
+
it "should parse retval and raise error on broken get_passport" do
|
101
|
+
lambda { @wm.request(:get_passport, :wmid => '') }.should raise_error(Webmoney::ResultError)
|
102
|
+
@wm.error.should == 2
|
103
|
+
@wm.errormsg.should match(%r{неверно указан проверяемый WMID})
|
104
|
+
end
|
137
105
|
|
138
|
-
|
139
|
-
|
140
|
-
|
106
|
+
it "should raise exception on bad WMID" do
|
107
|
+
lambda {@wm.request(:get_passport, :wmid => '111')}.should raise_error(Webmoney::ResultError)
|
108
|
+
end
|
109
|
+
|
110
|
+
it "should raise exception on non existent WMID" do
|
111
|
+
lambda {@wm.request(:get_passport, :wmid => '012345678901')}.should raise_error(Webmoney::NonExistentWmidError)
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should return correct BL" do
|
115
|
+
wmid = '370860915669'
|
116
|
+
@wm.request(:bussines_level, :wmid => wmid).should == 0
|
117
|
+
|
118
|
+
wmid = Webmoney::Wmid.new '000000000007'
|
119
|
+
bl = @wm.request(:bussines_level, :wmid => wmid)
|
120
|
+
(bl > 1000).should be_true
|
121
|
+
end
|
122
|
+
|
123
|
+
it "should send message" do
|
124
|
+
result = @wm.request( :send_message,
|
125
|
+
:wmid => @wm.wmid,
|
126
|
+
:subj => 'Текст',
|
127
|
+
:text => 'Тело <b>сообщения</b>')
|
128
|
+
result.should be_kind_of(Hash)
|
129
|
+
result[:id].should match(/^\d*$/)
|
130
|
+
((result[:date] + 60) > Time.now).should be_true
|
131
|
+
end
|
132
|
+
|
133
|
+
it "should create invoice" do
|
134
|
+
# TODO
|
135
|
+
#@wm.request(
|
136
|
+
# :create_invoice,
|
137
|
+
# :orderid => 3,
|
138
|
+
# :amount => 10.0,
|
139
|
+
# :customerwmid => "TEST_WMID",
|
140
|
+
# :storepurse => "Z161888783954",
|
141
|
+
# :desc => "Test invoice",
|
142
|
+
# :address => "Address"
|
143
|
+
#)
|
144
|
+
end
|
145
|
+
|
146
|
+
it "should return operation history" do
|
147
|
+
# TODO
|
148
|
+
#@mywm.request(:operation_history,
|
149
|
+
# :purse => "Z161888783954",
|
150
|
+
# :tranid => 148696631,
|
151
|
+
# :wminvid => 148613215,
|
152
|
+
# :orderid => 1,
|
153
|
+
# :datestart => Date.today() - 1,
|
154
|
+
# :datefinish => Date.today() + 1
|
155
|
+
#)
|
156
|
+
end
|
157
|
+
|
158
|
+
it "should create transaction" do
|
159
|
+
# TODO @wm.request( :create_transaction, ...)
|
160
|
+
end
|
141
161
|
|
162
|
+
it "should raise error on undefined xml func" do
|
163
|
+
lambda { @wm.request(:unexistent_interface) }.should raise_error(::NoMethodError)
|
142
164
|
end
|
143
165
|
|
144
|
-
end
|
166
|
+
end
|
data/spec/unit/wmid_spec.rb
CHANGED
@@ -1,30 +1,27 @@
|
|
1
|
-
|
1
|
+
#encoding: utf-8
|
2
|
+
require 'spec_helper'
|
2
3
|
|
3
|
-
|
4
|
+
describe Webmoney::Wmid, "class" do
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
@t = Wmid.new('123456789012')
|
9
|
-
end
|
10
|
-
|
11
|
-
it "should be kind of Wmid" do
|
12
|
-
@t.should be_kind_of(Wmid)
|
13
|
-
end
|
6
|
+
before(:each) do
|
7
|
+
@t = Webmoney::Wmid.new('123456789012')
|
8
|
+
end
|
14
9
|
|
15
|
-
|
16
|
-
|
17
|
-
|
10
|
+
it "should be kind of Wmid" do
|
11
|
+
@t.should be_kind_of(Webmoney::Wmid)
|
12
|
+
end
|
18
13
|
|
19
|
-
|
20
|
-
|
21
|
-
|
14
|
+
it "should be string" do
|
15
|
+
@t.should == '123456789012'
|
16
|
+
end
|
22
17
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
end
|
18
|
+
it "should permit initialize by integer" do
|
19
|
+
Webmoney::Wmid.new(123456789012).should == '123456789012'
|
20
|
+
end
|
27
21
|
|
22
|
+
it "should raise error on incorrect wmid" do
|
23
|
+
lambda{Webmoney::Wmid.new('abc')}.
|
24
|
+
should raise_error(Webmoney::IncorrectWmidError)
|
28
25
|
end
|
29
26
|
|
30
27
|
end
|
data/webmoney.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{webmoney}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.8"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Alexander Oryol"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-08-24}
|
13
13
|
s.email = %q{eagle.alex@gmail.com}
|
14
14
|
s.extensions = ["ext/wmsigner/extconf.rb"]
|
15
15
|
s.extra_rdoc_files = [
|
@@ -19,6 +19,8 @@ Gem::Specification.new do |s|
|
|
19
19
|
s.files = [
|
20
20
|
".gitignore",
|
21
21
|
"ChangeLog",
|
22
|
+
"Gemfile",
|
23
|
+
"Gemfile.lock",
|
22
24
|
"README",
|
23
25
|
"RUNNING_TESTS",
|
24
26
|
"VERSION",
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: webmoney
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 15
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 8
|
10
|
+
version: 0.0.8
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Alexander Oryol
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-08-24 00:00:00 +04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -44,6 +44,8 @@ extra_rdoc_files:
|
|
44
44
|
files:
|
45
45
|
- .gitignore
|
46
46
|
- ChangeLog
|
47
|
+
- Gemfile
|
48
|
+
- Gemfile.lock
|
47
49
|
- README
|
48
50
|
- RUNNING_TESTS
|
49
51
|
- VERSION
|