webmoney 0.0.13 → 0.0.14

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -20,6 +20,7 @@ Completed:
20
20
  * outgoing_invoices - x4
21
21
  * send_message - x6
22
22
  * find_wm - x8
23
+ * balance - x9
23
24
  * get_passport - x11
24
25
  * i_trust - x15
25
26
  * trust_me - x15
@@ -32,7 +33,6 @@ Incompleted (help need!):
32
33
  * operation_history - x3
33
34
  * finish_protect - x5
34
35
  * check_sign - x7
35
- * balance - x9
36
36
  * incoming_invoices - x10
37
37
  * reject_protection - x13
38
38
  * transaction_moneyback - x14
@@ -83,7 +83,7 @@ mywm = MyWM.new(:wmid => '123456789012', :cert => cert, :key => key)
83
83
  Get attestat data:
84
84
 
85
85
  ```ruby
86
- passport = Webmoney::Passport.new(wmid)
86
+ passport = Webmoney::Passport.new(wmid, :mode => 1) # optionally :mode, :dict, :info
87
87
  passport.attestat # { # hash
88
88
  # :attestat => 110, # == FORMAL attestat, as example
89
89
  # :created_at => Wed Feb 25 21:54:01 +0300 2004 # Time object
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.13
1
+ 0.0.14
@@ -45,7 +45,7 @@ extern "C" VALUE signer_new(VALUE self, VALUE szWMID, VALUE szPwd, VALUE szKeyDa
45
45
  {
46
46
  Signer *pSign;
47
47
 
48
- if(NIL_P(szWMID)) rb_raise(rb_eArgError, "nil wmid");
48
+ if(NIL_P(szWMID)) rb_raise(rb_eArgError, "nil wmid");
49
49
 
50
50
  // check WMID
51
51
  if (! IsWmid(RSTRING_PTR(szWMID))) rb_raise(rb_eArgError, "Incorrect WMID");
@@ -56,7 +56,7 @@ extern "C" VALUE signer_new(VALUE self, VALUE szWMID, VALUE szPwd, VALUE szKeyDa
56
56
 
57
57
  // check base64 data
58
58
  if ( RSTRING_LEN(szKeyData64) != 220 ) rb_raise(rb_eArgError, "Illegal size for base64 keydata");
59
-
59
+
60
60
  char KeyBuffer[ASCII_SIZE];
61
61
  int bytes = code64( ENCODE, KeyBuffer, ASCII_SIZE, RSTRING_PTR(szKeyData64), BUF_64_SIZE );
62
62
 
@@ -68,7 +68,7 @@ extern "C" VALUE signer_new(VALUE self, VALUE szWMID, VALUE szPwd, VALUE szKeyDa
68
68
 
69
69
  pSign->isIgnoreKeyFile = TRUE;
70
70
  pSign->Key64Flag = TRUE;
71
-
71
+
72
72
  if (pSign) pSign->SetKeyFromCL( TRUE, KeyBuffer );
73
73
 
74
74
  return tdata;
@@ -86,12 +86,12 @@ extern "C" VALUE signer_sign(VALUE self, VALUE szIn)
86
86
 
87
87
  Signer *pSign;
88
88
 
89
- Data_Get_Struct(self, Signer, pSign);
90
-
89
+ Data_Get_Struct(self, Signer, pSign);
90
+
91
91
  if(NIL_P(szIn)) rb_raise(rb_eArgError, "nil for sign");
92
92
 
93
93
  if (pSign)
94
- {
94
+ {
95
95
  szptr szSign;
96
96
  if (pSign->Sign(RSTRING_PTR(szIn), szSign))
97
97
  {
@@ -101,16 +101,14 @@ extern "C" VALUE signer_sign(VALUE self, VALUE szIn)
101
101
 
102
102
  int err_no = pSign->ErrorCode();
103
103
  if (err_no){
104
- char err[20];
105
- sprintf(err, "Signer error: %d", err_no);
106
- rb_raise(rb_eStandardError, err);
104
+ rb_raise(rb_eStandardError, "Signer error: %d", err_no);
107
105
  }
108
106
 
109
107
  return ret;
110
108
  }
111
109
 
112
110
  // The initialization method for this module
113
- extern "C" void Init_wmsigner()
111
+ extern "C" void Init_wmsigner()
114
112
  {
115
113
  cSigner = rb_define_class("Signer", rb_cObject);
116
114
  rb_define_singleton_method(cSigner, "new", (ruby_method*) &signer_new, 3);
@@ -13,7 +13,8 @@ module Webmoney
13
13
  :find_wm => { :url => 'XMLFindWMPurse.asp' }, # x8
14
14
  :balance => { :url => 'XMLPurses.asp' }, # x9
15
15
  :incoming_invoices => { :url => 'XMLInInvoices.asp' }, # x10
16
- :get_passport => { :url => 'https://passport.webmoney.ru/asp/XMLGetWMPassport.asp' }, # x11
16
+ :get_passport => { :url => 'https://passport.webmoney.ru/asp/XMLGetWMPassport.asp' , # x11
17
+ :x509 => lambda {|url| url.sub(/\.asp$/, 'Cert.asp')} },
17
18
  :reject_protection => { :url => 'XMLRejectProtect.asp' }, # x13
18
19
  :transaction_moneyback => { :url => 'XMLTransMoneyback.asp' }, # x14
19
20
  :i_trust => { :url => 'XMLTrustList.asp' }, # x15
@@ -37,16 +38,16 @@ module Webmoney
37
38
  # default transform to x509 version for w3s urls
38
39
  default_lambda = lambda {|url| url.sub(/\.asp$/, 'Cert.asp') }
39
40
 
40
- @interfaces = interface_urls.inject({}) do |m,k|
41
- url = k[1][:url]
41
+ @interfaces = interface_urls.inject({}) do |m,(k,v)|
42
+ url = v[:url]
42
43
  unless url.match %r{^https://}
43
44
  url = w3s_url + url
44
45
  url = default_lambda.call(url) if !classic?
45
46
  else
46
- transform = k[1][:x509]
47
+ transform = v[:x509]
47
48
  url = transform.call(url) if !classic? && transform && transform.respond_to?(:call)
48
49
  end
49
- m.merge!(k[0] => URI.parse(url))
50
+ m.merge!(k => URI.parse(url))
50
51
  end
51
52
 
52
53
  end
@@ -30,6 +30,12 @@ module Webmoney
30
30
  @@worker
31
31
  end
32
32
 
33
+ # extra permit :dict, :info, :dict params
34
+ def initialize(str, extra = {})
35
+ super(str)
36
+ @extra = extra
37
+ end
38
+
33
39
  # memoize data
34
40
  def attestat; @attestat ||= getinfo[:attestat] end
35
41
  def directory; @directory ||= getinfo[:directory] end
@@ -40,12 +46,7 @@ module Webmoney
40
46
  protected
41
47
 
42
48
  def getinfo
43
- info = @@worker.request(:get_passport, :wmid => self)
44
- @attestat = info[:attestat]
45
- @full_access = info[:full_access]
46
- @userinfo = info[:userinfo]
47
- @directory = info[:directory]
48
- info
49
+ @info ||= @@worker.request(:get_passport, @extra.merge(:wmid => self))
49
50
  end
50
51
 
51
52
  def self.parse_result(doc)
@@ -104,4 +104,19 @@ module Webmoney::RequestResult # :nodoc:all
104
104
  }
105
105
  end
106
106
 
107
+ def result_balance(doc)
108
+ purses = []
109
+ doc.at('//purses').children.each do |purse|
110
+ purses_hash = {}
111
+ purse.children.each do |child|
112
+ purses_hash[child.name.to_sym] = child.content
113
+ end
114
+ purses << purses_hash unless purses_hash.empty?
115
+ end
116
+ {
117
+ :purses => purses,
118
+ :retval => doc.at('//retval').inner_html.to_i
119
+ }
120
+ end
121
+
107
122
  end
@@ -52,4 +52,11 @@ module Webmoney::RequestRetval # :nodoc:all
52
52
  raise Webmoney::ResultError, [@error, @errormsg].join(' ') unless not_exception_result_errors.include?(@error)
53
53
  end
54
54
 
55
+ def retval_balance(doc)
56
+ retval_element = doc.at('//retval')
57
+ @error = retval_element.inner_html.to_i
58
+ @errormsg = doc.at('//retdesc') ? doc.at('//retdesc').inner_html : ''
59
+ raise Webmoney::ResultError, [@error, @errormsg].join(' ') unless @error == 0
60
+ end
61
+
55
62
  end
@@ -4,15 +4,15 @@ module Webmoney::RequestXML # :nodoc:all
4
4
  def xml_get_passport(opt)
5
5
  Nokogiri::XML::Builder.new { |x|
6
6
  x.request {
7
- x.wmid @wmid
7
+ x.wmid @wmid if classic?
8
8
  x.passportwmid opt[:wmid]
9
9
  x.params {
10
10
  x.dict opt[:dict] || 0
11
11
  x.info opt[:info] || 1
12
12
  x.mode opt[:mode] || 0
13
13
  }
14
- # unless mode == 1, signed data need'nt
15
- x.sign( (classic? && opt[:mode]) ? sign("#{@wmid}#{opt[:wmid]}") : nil )
14
+ # unless mode == 1, signed data need'nt, but elem <sign/> required
15
+ x.sign( opt[:mode]==1 ? sign(@wmid+opt[:wmid]) : nil ) if classic?
16
16
  }
17
17
  }
18
18
  end
@@ -163,7 +163,7 @@ module Webmoney::RequestXML # :nodoc:all
163
163
  x.send('w3s.request') {
164
164
  x.reqn req
165
165
  x.wmid @wmid
166
- x.sign sign("#{opt[:wmid]}#{req}")
166
+ x.sign sign("#{opt[:wmid]}#{req}") if classic?
167
167
  x.gettrustlist do
168
168
  x.wmid opt[:wmid]
169
169
  end
@@ -193,4 +193,18 @@ module Webmoney::RequestXML # :nodoc:all
193
193
  }
194
194
  end
195
195
 
196
+ def xml_balance(opt)
197
+ req = reqn()
198
+ Nokogiri::XML::Builder.new { |x|
199
+ x.send('w3s.request') {
200
+ x.reqn req
201
+ x.wmid @wmid
202
+ x.sign sign("#{opt[:wmid]}#{req}") if classic?
203
+ x.getpurses do
204
+ x.wmid opt[:wmid]
205
+ end
206
+ }
207
+ }
208
+ end
209
+
196
210
  end
@@ -10,8 +10,8 @@ module Webmoney
10
10
  raise IncorrectWmidError, str unless str =~ /^\d{12}$/
11
11
  super(str)
12
12
  end
13
-
13
+
14
14
  def wmid; self end
15
-
15
+
16
16
  end
17
17
  end
@@ -0,0 +1,21 @@
1
+ #encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe "balance (x9) interface" do
5
+
6
+ before(:each) do
7
+ @wm = webmoney()
8
+ end
9
+
10
+ it "result should have purse list" do
11
+ result = @wm.request(:balance)
12
+ result[:purses].should_not be_empty
13
+ end
14
+
15
+ it "retval should be zero" do
16
+ result = @wm.request(:balance)
17
+ result[:retval].should == 0
18
+ end
19
+
20
+
21
+ end
@@ -28,7 +28,7 @@ describe "interfaces url" do
28
28
  wml.interfaces[:balance].to_s.should == 'https://w3s.wmtransfer.com/asp/XMLPursesCert.asp'
29
29
  wml.interfaces[:check_user].to_s.should == 'https://apipassport.webmoney.ru/XMLCheckUserCert.aspx'
30
30
  # non-converted
31
- wml.interfaces[:get_passport].to_s.should == 'https://passport.webmoney.ru/asp/XMLGetWMPassport.asp'
31
+ wml.interfaces[:transaction_get].to_s.should == 'https://merchant.webmoney.ru/conf/xml/XMLTransGet.asp'
32
32
  end
33
33
 
34
34
  end
@@ -5,7 +5,7 @@ require 'date'
5
5
  describe Webmoney::Passport, "class" do
6
6
 
7
7
  before(:each) do
8
- @wm = TestWM.new
8
+ @wm = webmoney()
9
9
  end
10
10
 
11
11
  it "should return Passport instance" do
@@ -78,7 +78,7 @@ describe Webmoney::Passport, "class" do
78
78
  end
79
79
 
80
80
  it "should have wmids" do
81
- passport = Webmoney::Passport.new(@wm.wmid)
81
+ passport = Webmoney::Passport.new(@wm.wmid, :mode => 1)
82
82
  passport.wmids.should be_instance_of(Hash)
83
83
  passport.wmids.has_key?(@wm.wmid).should be_true
84
84
  passport.wmids[@wm.wmid].should be_instance_of(Hash)
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "webmoney"
8
- s.version = "0.0.13"
8
+ s.version = "0.0.14"
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 = "2012-04-11"
12
+ s.date = "2012-10-25"
13
13
  s.email = "eagle.alex@gmail.com"
14
14
  s.extensions = ["ext/wmsigner/extconf.rb"]
15
15
  s.extra_rdoc_files = [
@@ -49,6 +49,7 @@ Gem::Specification.new do |s|
49
49
  "lib/wmid.rb",
50
50
  "rakefile",
51
51
  "spec/spec_helper.rb",
52
+ "spec/unit/balance_spec.rb",
52
53
  "spec/unit/check_user.rb",
53
54
  "spec/unit/iconv_spec.rb",
54
55
  "spec/unit/interfaces_spec.rb",
@@ -68,9 +69,9 @@ Gem::Specification.new do |s|
68
69
  ]
69
70
  s.require_paths = ["lib"]
70
71
  s.rubyforge_project = "webmoney"
71
- s.rubygems_version = "1.8.17"
72
+ s.rubygems_version = "1.8.24"
72
73
  s.summary = "Webmoney interfaces and native wmsigner"
73
- s.test_files = ["Gemfile", "spec/spec_helper.rb", "spec/unit/interfaces_spec.rb", "spec/unit/check_user.rb", "spec/unit/purse_spec.rb", "spec/unit/messenger_spec.rb", "spec/unit/iconv_spec.rb", "spec/unit/webmoney_spec.rb", "spec/unit/signer_spec.rb", "spec/unit/time_spec.rb", "spec/unit/wmid_spec.rb", "spec/unit/trust_spec.rb", "spec/unit/login_spec.rb", "spec/unit/passport_spec.rb"]
74
+ s.test_files = ["Gemfile", "spec/spec_helper.rb", "spec/unit/balance_spec.rb", "spec/unit/purse_spec.rb", "spec/unit/time_spec.rb", "spec/unit/check_user.rb", "spec/unit/interfaces_spec.rb", "spec/unit/messenger_spec.rb", "spec/unit/signer_spec.rb", "spec/unit/passport_spec.rb", "spec/unit/trust_spec.rb", "spec/unit/wmid_spec.rb", "spec/unit/login_spec.rb", "spec/unit/webmoney_spec.rb", "spec/unit/iconv_spec.rb"]
74
75
 
75
76
  if s.respond_to? :specification_version then
76
77
  s.specification_version = 3
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webmoney
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.13
4
+ version: 0.0.14
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-11 00:00:00.000000000 Z
12
+ date: 2012-10-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
16
- requirement: &84373370 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *84373370
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: rspec
27
- requirement: &84373070 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ! '>='
@@ -32,10 +37,15 @@ dependencies:
32
37
  version: '0'
33
38
  type: :development
34
39
  prerelease: false
35
- version_requirements: *84373070
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: bundler
38
- requirement: &84372740 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
51
  - - ! '>='
@@ -43,10 +53,15 @@ dependencies:
43
53
  version: '0'
44
54
  type: :development
45
55
  prerelease: false
46
- version_requirements: *84372740
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
47
62
  - !ruby/object:Gem::Dependency
48
63
  name: jeweler
49
- requirement: &84372410 !ruby/object:Gem::Requirement
64
+ requirement: !ruby/object:Gem::Requirement
50
65
  none: false
51
66
  requirements:
52
67
  - - ! '>='
@@ -54,10 +69,15 @@ dependencies:
54
69
  version: '0'
55
70
  type: :development
56
71
  prerelease: false
57
- version_requirements: *84372410
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
58
78
  - !ruby/object:Gem::Dependency
59
79
  name: rake-compiler
60
- requirement: &84372120 !ruby/object:Gem::Requirement
80
+ requirement: !ruby/object:Gem::Requirement
61
81
  none: false
62
82
  requirements:
63
83
  - - ! '>='
@@ -65,7 +85,12 @@ dependencies:
65
85
  version: '0'
66
86
  type: :development
67
87
  prerelease: false
68
- version_requirements: *84372120
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
69
94
  description:
70
95
  email: eagle.alex@gmail.com
71
96
  executables: []
@@ -107,6 +132,7 @@ files:
107
132
  - lib/wmid.rb
108
133
  - rakefile
109
134
  - spec/spec_helper.rb
135
+ - spec/unit/balance_spec.rb
110
136
  - spec/unit/check_user.rb
111
137
  - spec/unit/iconv_spec.rb
112
138
  - spec/unit/interfaces_spec.rb
@@ -135,6 +161,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
135
161
  - - ! '>='
136
162
  - !ruby/object:Gem::Version
137
163
  version: '0'
164
+ segments:
165
+ - 0
166
+ hash: 1774018962906030977
138
167
  required_rubygems_version: !ruby/object:Gem::Requirement
139
168
  none: false
140
169
  requirements:
@@ -143,22 +172,23 @@ required_rubygems_version: !ruby/object:Gem::Requirement
143
172
  version: '0'
144
173
  requirements: []
145
174
  rubyforge_project: webmoney
146
- rubygems_version: 1.8.17
175
+ rubygems_version: 1.8.24
147
176
  signing_key:
148
177
  specification_version: 3
149
178
  summary: Webmoney interfaces and native wmsigner
150
179
  test_files:
151
180
  - Gemfile
152
181
  - spec/spec_helper.rb
153
- - spec/unit/interfaces_spec.rb
154
- - spec/unit/check_user.rb
182
+ - spec/unit/balance_spec.rb
155
183
  - spec/unit/purse_spec.rb
184
+ - spec/unit/time_spec.rb
185
+ - spec/unit/check_user.rb
186
+ - spec/unit/interfaces_spec.rb
156
187
  - spec/unit/messenger_spec.rb
157
- - spec/unit/iconv_spec.rb
158
- - spec/unit/webmoney_spec.rb
159
188
  - spec/unit/signer_spec.rb
160
- - spec/unit/time_spec.rb
161
- - spec/unit/wmid_spec.rb
189
+ - spec/unit/passport_spec.rb
162
190
  - spec/unit/trust_spec.rb
191
+ - spec/unit/wmid_spec.rb
163
192
  - spec/unit/login_spec.rb
164
- - spec/unit/passport_spec.rb
193
+ - spec/unit/webmoney_spec.rb
194
+ - spec/unit/iconv_spec.rb