webmoney 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +7 -1
- data/README +34 -0
- data/VERSION +1 -1
- data/lib/passport.rb +2 -1
- data/lib/purse.rb +1 -1
- data/lib/request_result.rb +40 -1
- data/lib/request_retval.rb +12 -1
- data/lib/request_xml.rb +50 -1
- data/lib/webmoney.rb +1 -1
- data/spec/spec_helper.rb +52 -5
- data/spec/unit/passport_spec.rb +6 -0
- data/spec/unit/purse_spec.rb +10 -5
- data/spec/unit/signer_spec.rb +3 -3
- data/spec/unit/webmoney_spec.rb +44 -1
- data/webmoney.gemspec +2 -2
- metadata +4 -4
data/ChangeLog
CHANGED
@@ -1,12 +1,18 @@
|
|
1
1
|
ChangeLog
|
2
2
|
|
3
|
+
Mon Sep 20 2010 14:31:00 +0300
|
4
|
+
----------------------------
|
5
|
+
V 0.0.9
|
6
|
+
* Add light-keys support
|
7
|
+
* Fix Purse bug
|
8
|
+
* Add Passport#wmids method
|
9
|
+
|
3
10
|
Mon Aug 24 2010 12:00:00 +0300
|
4
11
|
----------------------------
|
5
12
|
V 0.0.8
|
6
13
|
* Compatible with ruby 1.9.2
|
7
14
|
* Added Gemfile
|
8
15
|
|
9
|
-
|
10
16
|
Mon Jun 07 2010 19:01:30 +0400
|
11
17
|
----------------------------
|
12
18
|
V 0.0.7
|
data/README
CHANGED
@@ -113,4 +113,38 @@ purse.wmid # => '123456789012'
|
|
113
113
|
purse.belong_to?('123456789012') # => true
|
114
114
|
|
115
115
|
|
116
|
+
== Example: Create invoice and check it's state
|
117
|
+
|
118
|
+
@wm = MyWM.new(:wmid => '123456789012', :password => 'my_pass', :key => 'gQABAIR6...2cC8FZTyKyjBM=')
|
119
|
+
|
120
|
+
# Create invoice
|
121
|
+
@invoice = @wm.request(:create_invoice,
|
122
|
+
:orderid => 5,
|
123
|
+
:amount => 10,
|
124
|
+
:customerwmid => CUSTOMER_WMID,
|
125
|
+
:storepurse => STORE_PURSE,
|
126
|
+
:desc => "Test invoice",
|
127
|
+
:address => "Delivery Address"
|
128
|
+
)
|
129
|
+
|
130
|
+
# Check state
|
131
|
+
res = @wm.request(:outgoing_invoices,
|
132
|
+
:purse => STORE_PURSE,
|
133
|
+
:wminvid => @invoice[:id],
|
134
|
+
:orderid => @invoice[:orderid],
|
135
|
+
:customerwmid => CUSTOMER_WMID,
|
136
|
+
:datestart => @invoice[:created_at],
|
137
|
+
:datefinish => @invoice[:created_at]
|
138
|
+
)
|
139
|
+
if res[:retval].should == 0 && !res[:invoices].empty?
|
140
|
+
invoice = res[:invoices].first
|
141
|
+
case invoice[:state]
|
142
|
+
when 0 then # Not Paid
|
143
|
+
when 1 then # Paid with protection
|
144
|
+
when 2 then # Payment complete
|
145
|
+
when 3 then # Rejected
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
|
116
150
|
Also, see spec/* for examples.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.9
|
data/lib/passport.rb
CHANGED
@@ -35,6 +35,7 @@ module Webmoney
|
|
35
35
|
def directory; @directory ||= getinfo[:directory] end
|
36
36
|
def full_access; @full_access = getinfo[:full_access] end
|
37
37
|
def userinfo; @userinfo ||= getinfo[:userinfo] end
|
38
|
+
def wmids; @userinfo ||= getinfo[:wmids] end
|
38
39
|
|
39
40
|
protected
|
40
41
|
|
@@ -100,4 +101,4 @@ module Webmoney
|
|
100
101
|
end
|
101
102
|
|
102
103
|
end
|
103
|
-
end
|
104
|
+
end
|
data/lib/purse.rb
CHANGED
data/lib/request_result.rb
CHANGED
@@ -28,6 +28,21 @@ module Webmoney::RequestResult # :nodoc:all
|
|
28
28
|
}
|
29
29
|
end
|
30
30
|
|
31
|
+
def result_create_invoice(doc)
|
32
|
+
res = {
|
33
|
+
:retval => doc.at('//retval').inner_html.to_i,
|
34
|
+
:retdesc => (doc.at('//testwmpurse/retdesc').inner_html rescue nil),
|
35
|
+
:orderid => (doc.at('//invoice/orderid').inner_html.to_i),
|
36
|
+
}
|
37
|
+
if res[:retval] == 0
|
38
|
+
res[:id] = (doc.at('//invoice').attributes['id'].value.to_i)
|
39
|
+
res[:ts] = (doc.at('//invoice').attributes['ts'].value.to_i)
|
40
|
+
res[:state] = (doc.at('//invoice/state').inner_html.to_i)
|
41
|
+
res[:created_at] = (DateTime.strptime(doc.at('//invoice/datecrt').inner_html, "%Y%m%d %H:%M:%S"))
|
42
|
+
end
|
43
|
+
res
|
44
|
+
end
|
45
|
+
|
31
46
|
def result_create_transaction(doc)
|
32
47
|
op = doc.at('//operation')
|
33
48
|
{
|
@@ -38,4 +53,28 @@ module Webmoney::RequestResult # :nodoc:all
|
|
38
53
|
end )
|
39
54
|
end
|
40
55
|
|
41
|
-
|
56
|
+
def result_outgoing_invoices(doc)
|
57
|
+
res = {
|
58
|
+
:retval => doc.at('//retval').inner_html.to_i,
|
59
|
+
:retdesc => (doc.at('//testwmpurse/retdesc').inner_html rescue nil),
|
60
|
+
}
|
61
|
+
if res[:retval] == 0
|
62
|
+
res[:invoices] = doc.at('//outinvoices').elements.collect do |invoice|
|
63
|
+
r = {
|
64
|
+
:id => invoice.attributes['id'].value.to_i,
|
65
|
+
:ts => invoice.attributes['ts'].value.to_i,
|
66
|
+
}
|
67
|
+
invoice.elements.each do |tag|
|
68
|
+
name = tag.name.to_sym
|
69
|
+
value = tag.inner_html
|
70
|
+
value = value.to_i if [:orderid, :tranid, :period, :expiration, :wmtranid, :state].include?(name)
|
71
|
+
value = value.to_f if [:rest, :amount, :comiss].include?(name)
|
72
|
+
value = DateTime.strptime(value, "%Y%m%d %H:%M:%S") if [:datecrt, :dateupd].include?(name)
|
73
|
+
r[name] = value
|
74
|
+
end
|
75
|
+
r
|
76
|
+
end
|
77
|
+
end
|
78
|
+
res
|
79
|
+
end
|
80
|
+
end
|
data/lib/request_retval.rb
CHANGED
@@ -21,4 +21,15 @@ module Webmoney::RequestRetval # :nodoc:all
|
|
21
21
|
# retval = { 1 - found; 0 - not found }
|
22
22
|
end
|
23
23
|
|
24
|
-
|
24
|
+
def retval_create_invoice(doc)
|
25
|
+
@error = doc.at('//retval').inner_html.to_i
|
26
|
+
@errormsg = doc.at('//retdesc').inner_html
|
27
|
+
raise Webmoney::ResultError, [@error, @errormsg].join(' ') unless @error == 0
|
28
|
+
end
|
29
|
+
|
30
|
+
def retval_outgoing_invoices(doc)
|
31
|
+
@error = doc.at('//retval').inner_html.to_i
|
32
|
+
@errormsg = doc.at('//retdesc').inner_html
|
33
|
+
raise Webmoney::ResultError, [@error, @errormsg].join(' ') unless @error == 0
|
34
|
+
end
|
35
|
+
end
|
data/lib/request_xml.rb
CHANGED
@@ -83,7 +83,35 @@ module Webmoney::RequestXML # :nodoc:all
|
|
83
83
|
}
|
84
84
|
end
|
85
85
|
|
86
|
-
|
86
|
+
def xml_create_invoice(opt)
|
87
|
+
req = reqn()
|
88
|
+
desc = @ic_out.iconv(opt[:desc])
|
89
|
+
address = @ic_out.iconv(opt[:address])[0...255].strip
|
90
|
+
amount = opt[:amount].to_f.to_s.gsub(/\.?0+$/, '')
|
91
|
+
Nokogiri::XML::Builder.new( :encoding => 'windows-1251' ) { |x|
|
92
|
+
x.send('w3s.request') {
|
93
|
+
x.wmid @wmid
|
94
|
+
x.reqn req
|
95
|
+
x.invoice do
|
96
|
+
x.orderid opt[:orderid]
|
97
|
+
x.customerwmid opt[:customerwmid]
|
98
|
+
x.storepurse opt[:storepurse]
|
99
|
+
x.amount amount
|
100
|
+
x.desc desc
|
101
|
+
x.address address
|
102
|
+
x.period opt[:period].to_i
|
103
|
+
x.expiration opt[:expiration].to_i
|
104
|
+
end
|
105
|
+
if classic?
|
106
|
+
@plan = "#{opt[:orderid]}#{opt[:customerwmid]}#{opt[:storepurse]}" + amount
|
107
|
+
@plan+= desc + address + "#{opt[:period].to_i}#{opt[:expiration].to_i}" + req
|
108
|
+
x.sign sign(@plan)
|
109
|
+
end
|
110
|
+
}
|
111
|
+
}
|
112
|
+
end
|
113
|
+
|
114
|
+
def xml_create_transaction(opt)
|
87
115
|
req = reqn()
|
88
116
|
desc = @ic_out.iconv(opt[:desc]) # description
|
89
117
|
Nokogiri::XML::Builder.new( :encoding => 'windows-1251' ) { |x|
|
@@ -105,4 +133,25 @@ module Webmoney::RequestXML # :nodoc:all
|
|
105
133
|
}
|
106
134
|
end
|
107
135
|
|
136
|
+
def xml_outgoing_invoices(opt)
|
137
|
+
req = reqn()
|
138
|
+
Nokogiri::XML::Builder.new( :encoding => 'windows-1251' ) { |x|
|
139
|
+
x.send('w3s.request') {
|
140
|
+
x.wmid @wmid
|
141
|
+
x.reqn req
|
142
|
+
x.getoutinvoices do
|
143
|
+
x.purse opt[:purse]
|
144
|
+
x.wminvid opt[:wminvid]
|
145
|
+
x.orderid opt[:orderid]
|
146
|
+
x.datestart opt[:datestart].strftime("%Y%m%d %H:%M:%S")
|
147
|
+
x.datefinish opt[:datefinish].strftime("%Y%m%d %H:%M:%S")
|
148
|
+
end
|
149
|
+
if classic?
|
150
|
+
# TODO
|
151
|
+
@plan = opt[:purse] + req
|
152
|
+
x.sign sign(@plan)
|
153
|
+
end
|
154
|
+
}
|
155
|
+
}
|
156
|
+
end
|
108
157
|
end
|
data/lib/webmoney.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -1,4 +1,25 @@
|
|
1
1
|
#encoding: utf-8
|
2
|
+
#
|
3
|
+
# ~/.wm/config.yml example:
|
4
|
+
#
|
5
|
+
# ca_cert:
|
6
|
+
#
|
7
|
+
# first:
|
8
|
+
# wmtype: classic
|
9
|
+
# wmid:
|
10
|
+
# password:
|
11
|
+
# key:
|
12
|
+
# wmz:
|
13
|
+
#
|
14
|
+
# second:
|
15
|
+
# wmtype: light
|
16
|
+
# wmid:
|
17
|
+
# password:
|
18
|
+
# cert: webmoney.cert
|
19
|
+
# key: webmoney.key
|
20
|
+
# wmz:
|
21
|
+
#
|
22
|
+
|
2
23
|
require 'rubygems'
|
3
24
|
require 'test/unit'
|
4
25
|
require 'spec'
|
@@ -8,23 +29,49 @@ require 'time'
|
|
8
29
|
require File.dirname(__FILE__) + '/../lib/webmoney'
|
9
30
|
|
10
31
|
# Variables may be access, for example WmConfig.wmid
|
11
|
-
config =
|
32
|
+
config = YAML.load_file("#{ENV['HOME']}/.wm/config.yml")
|
12
33
|
if ENV['WM_ENV']
|
13
34
|
env_config = config.send(ENV['WM_ENV'])
|
14
35
|
config.common.update(env_config) unless env_config.nil?
|
15
36
|
end
|
16
|
-
::WmConfig = OpenStruct.new(config
|
37
|
+
::WmConfig = OpenStruct.new(config)
|
38
|
+
raise "First user wmtype must be classic!" if WmConfig.first['wmtype'] != 'classic'
|
17
39
|
|
18
40
|
class TestWM
|
19
41
|
include Webmoney
|
20
42
|
|
21
43
|
def initialize(opt = {})
|
22
|
-
defaults = {:wmid => WmConfig.wmid,
|
23
|
-
:password => WmConfig.password,
|
24
|
-
:key => WmConfig.key,
|
44
|
+
defaults = {:wmid => WmConfig.first['wmid'],
|
45
|
+
:password => WmConfig.first['password'],
|
46
|
+
:key => WmConfig.first['key'],
|
25
47
|
:ca_cert => WmConfig.ca_cert}
|
26
48
|
defaults.merge!(opt)
|
27
49
|
super(defaults)
|
28
50
|
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def getwm(config)
|
54
|
+
if config.wmtype == "light"
|
55
|
+
# light
|
56
|
+
cert = OpenSSL::X509::Certificate.new(File.read(config.cert))
|
57
|
+
key = OpenSSL::PKey::RSA.new(File.read(config.key), config.password)
|
58
|
+
TestWM.new :wmid => config.wmid,
|
59
|
+
:key => key,
|
60
|
+
:cert => cert,
|
61
|
+
:ca_cert => WmConfig.ca_cert
|
62
|
+
else
|
63
|
+
# classic
|
64
|
+
TestWM.new :wmid => config.wmid,
|
65
|
+
:password => config.password,
|
66
|
+
:key => config.key,
|
67
|
+
:ca_cert => config.ca_cert
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def webmoney
|
72
|
+
getwm(OpenStruct.new(WmConfig.first))
|
73
|
+
end
|
29
74
|
|
75
|
+
def contragent
|
76
|
+
getwm(OpenStruct.new(WmConfig.second))
|
30
77
|
end
|
data/spec/unit/passport_spec.rb
CHANGED
@@ -123,4 +123,10 @@ describe Webmoney::Passport, "class" do
|
|
123
123
|
lambda {@wm.request(:get_passport, :wmid => '012345678901')}.should raise_error(Webmoney::NonExistentWmidError)
|
124
124
|
end
|
125
125
|
|
126
|
+
it "should have wmids" do
|
127
|
+
passport = Webmoney::Passport.new(@wm.wmid)
|
128
|
+
passport.wmids.should be_instance_of(Hash)
|
129
|
+
passport.wmids.has_key?(@wm.wmid).should be_true
|
130
|
+
passport.wmids[@wm.wmid].should be_instance_of(Hash)
|
131
|
+
end
|
126
132
|
end
|
data/spec/unit/purse_spec.rb
CHANGED
@@ -12,6 +12,11 @@ describe Webmoney::Purse, "class" do
|
|
12
12
|
@t = Webmoney::Purse.new('Z136894439563')
|
13
13
|
end
|
14
14
|
|
15
|
+
it "should return 111111111111 wmid for Z111111111111 purse" do
|
16
|
+
t = Webmoney::Purse.new("Z111111111111")
|
17
|
+
t.wmid.should == '111111111111'
|
18
|
+
end
|
19
|
+
|
15
20
|
it "should be kind of Wmid" do
|
16
21
|
@t.should be_kind_of(Webmoney::Purse)
|
17
22
|
end
|
@@ -26,16 +31,16 @@ describe Webmoney::Purse, "class" do
|
|
26
31
|
end
|
27
32
|
|
28
33
|
it "should return wmid" do
|
29
|
-
@t.wmid.should == '
|
34
|
+
@t.wmid.should == '128984249415'
|
30
35
|
end
|
31
36
|
|
32
37
|
it "should return true" do
|
33
|
-
@wm.should_receive(:request).with(:find_wm, :purse => @t).and_return(:retval=>1, :wmid => '
|
34
|
-
@t.belong_to?('
|
38
|
+
@wm.should_receive(:request).with(:find_wm, :purse => @t, :wmid => '').and_return(:retval=>1, :wmid => '128984249415')
|
39
|
+
@t.belong_to?('128984249415').should be_true
|
35
40
|
end
|
36
41
|
|
37
42
|
it "should return false" do
|
38
|
-
@wm.should_receive(:request).with(:find_wm, :purse => @t).and_return(:retval=>0)
|
43
|
+
@wm.should_receive(:request).with(:find_wm, :purse => @t, :wmid => '').and_return(:retval=>0, :wmid => '128984249415')
|
39
44
|
@t.belong_to?('123456789012').should be_false
|
40
45
|
end
|
41
46
|
|
@@ -45,7 +50,7 @@ describe Webmoney::Purse, "class" do
|
|
45
50
|
|
46
51
|
it "it" do
|
47
52
|
@wm.should_not_receive(:request).with(:find_wm, :purse => @t)
|
48
|
-
@t.belong_to?('
|
53
|
+
@t.belong_to?('128984249415').should be_true
|
49
54
|
end
|
50
55
|
|
51
56
|
end
|
data/spec/unit/signer_spec.rb
CHANGED
@@ -3,8 +3,8 @@ require 'spec_helper'
|
|
3
3
|
|
4
4
|
describe Signer, "class" do
|
5
5
|
|
6
|
-
before(:
|
7
|
-
@s = Signer.new( WmConfig.wmid, WmConfig.password, WmConfig.key)
|
6
|
+
before(:all) do
|
7
|
+
@s = Signer.new( WmConfig.first['wmid'].to_s, WmConfig.first['password'], WmConfig.first['key'])
|
8
8
|
end
|
9
9
|
|
10
10
|
it "should be Signer class" do
|
@@ -33,4 +33,4 @@ describe Signer, "class" do
|
|
33
33
|
lambda{Signer.new('405424574082', 'test', '')}.should raise_error(ArgumentError)
|
34
34
|
end
|
35
35
|
|
36
|
-
end
|
36
|
+
end
|
data/spec/unit/webmoney_spec.rb
CHANGED
@@ -20,7 +20,7 @@ describe Webmoney, "class" do
|
|
20
20
|
end
|
21
21
|
|
22
22
|
it "should correct prepare interfaces urls" do
|
23
|
-
wm = TestWM.new :wmid => WmConfig.wmid
|
23
|
+
wm = TestWM.new :wmid => WmConfig.first['wmid'], :key => nil
|
24
24
|
wm.should_not be_classic
|
25
25
|
wm.interfaces[:balance].class.should == URI::HTTPS
|
26
26
|
# converted to light-auth version
|
@@ -111,6 +111,10 @@ describe Webmoney, "class" do
|
|
111
111
|
lambda {@wm.request(:get_passport, :wmid => '012345678901')}.should raise_error(Webmoney::NonExistentWmidError)
|
112
112
|
end
|
113
113
|
|
114
|
+
it "should create transaction" do
|
115
|
+
# TODO @wm.request( :create_transaction, ...)
|
116
|
+
end
|
117
|
+
|
114
118
|
it "should return correct BL" do
|
115
119
|
wmid = '370860915669'
|
116
120
|
@wm.request(:bussines_level, :wmid => wmid).should == 0
|
@@ -163,4 +167,43 @@ describe Webmoney, "class" do
|
|
163
167
|
lambda { @wm.request(:unexistent_interface) }.should raise_error(::NoMethodError)
|
164
168
|
end
|
165
169
|
|
170
|
+
describe "invoice" do
|
171
|
+
before(:each) do
|
172
|
+
@wm = webmoney()
|
173
|
+
@ca = contragent()
|
174
|
+
# create invoice
|
175
|
+
@invoice = @ca.request(:create_invoice,
|
176
|
+
:orderid => 1,
|
177
|
+
:amount => 1,
|
178
|
+
:customerwmid => @wm.wmid,
|
179
|
+
:storepurse => WmConfig.second['wmz'],
|
180
|
+
:desc => "Test invoice",
|
181
|
+
:address => "Address"
|
182
|
+
)
|
183
|
+
end
|
184
|
+
|
185
|
+
it "should be created" do
|
186
|
+
@invoice[:retval].should == 0
|
187
|
+
@invoice[:state].should == 0
|
188
|
+
@invoice[:orderid].should == 1
|
189
|
+
@invoice[:ts].should > 0
|
190
|
+
@invoice[:id].should > 0
|
191
|
+
end
|
192
|
+
|
193
|
+
it "should be in state 0 (not paid)" do
|
194
|
+
res = @ca.request(:outgoing_invoices,
|
195
|
+
:purse => WmConfig.second['wmz'],
|
196
|
+
:wminvid => @invoice[:id],
|
197
|
+
:orderid => @invoice[:orderid],
|
198
|
+
:customerwmid => @wm.wmid,
|
199
|
+
:datestart => @invoice[:created_at],
|
200
|
+
:datefinish => @invoice[:created_at]
|
201
|
+
)
|
202
|
+
res[:retval].should == 0
|
203
|
+
res[:invoices].length.should == 1
|
204
|
+
res[:invoices][0][:state].should == 0
|
205
|
+
res[:invoices][0][:amount].should == 1
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
166
209
|
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.9"
|
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-09-20}
|
13
13
|
s.email = %q{eagle.alex@gmail.com}
|
14
14
|
s.extensions = ["ext/wmsigner/extconf.rb"]
|
15
15
|
s.extra_rdoc_files = [
|
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: 13
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 9
|
10
|
+
version: 0.0.9
|
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-09-20 00:00:00 +04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|