Module: Webmoney::RequestXML

Included in:
Webmoney
Defined in:
lib/request_xml.rb

Overview

:nodoc:all

Instance Method Summary collapse

Instance Method Details

#xml_balance(opt) ⇒ Object



196
197
198
199
200
201
202
203
204
205
206
207
208
# File 'lib/request_xml.rb', line 196

def xml_balance(opt)
  req = reqn()
  Nokogiri::XML::Builder.new { |x|
    x.send('w3s.request') {
      x.reqn req
      x.wmid @wmid
      x.sign sign("#{opt[:wmid]}#{req}") if classic?
      x.getpurses do
        x.wmid opt[:wmid]
      end
    }
  }
end

#xml_bussines_level(opt) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/request_xml.rb', line 20

def xml_bussines_level(opt)
  Nokogiri::XML::Builder.new { |x|
    x.send('WMIDLevel.request') {
      x.signerwmid @wmid
      x.wmid opt[:wmid]
    }
  }
end

#xml_check_sign(opt) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/request_xml.rb', line 29

def xml_check_sign(opt)
  plan_in, plan_out = filter_str(opt[:plan])
  Nokogiri::XML::Builder.new( :encoding => 'windows-1251' ) { |x|
    x.send('w3s.request') {
      x.wmid @wmid
      x.testsign {
        x.wmid opt[:wmid]
        x.plan { x.cdata plan_in }
        x.sign opt[:sign]
      }
      x.sign sign("#{@wmid}#{opt[:wmid]}#{plan_out}#{opt[:sign]}") if classic?
    }
  }
end

#xml_check_user(opt) ⇒ Object



174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
# File 'lib/request_xml.rb', line 174

def xml_check_user(opt)
  req = reqn()
  Nokogiri::XML::Builder.new { |x|
    x.send('passport.request') {
      x.reqn req
      x.signerwmid @wmid
      x.sign sign("#{req}#{opt[:operation][:type]}#{opt[:userinfo][:wmid]}") if classic?
      x.operation do
        opt[:operation].each do |operation_key, operation_value|
          operation_key = "#{operation_key}_" if operation_key.to_sym == :type
          x.send(operation_key, operation_value)
        end
      end
      x.userinfo do
        opt[:userinfo].each do |userinfo_key, userinfo_value|
          x.send(userinfo_key, userinfo_value)
        end
      end
    }
  }
end

#xml_create_invoice(opt) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/request_xml.rb', line 77

def xml_create_invoice(opt)
  req = reqn()
  desc_in, desc_out = filter_str(opt[:desc])
  address_in, address_out = filter_str(opt[:address])
  amount = opt[:amount].to_f.to_s.gsub(/\.?0+$/, '')
  Nokogiri::XML::Builder.new( :encoding => 'windows-1251' ) { |x|
    x.send('w3s.request') {
      x.reqn req
      x.wmid @wmid
      x.sign sign("#{opt[:orderid]}#{opt[:customerwmid]}#{opt[:storepurse]}#{amount}#{desc_out}#{address_out}#{opt[:period]||0}#{opt[:expiration]||0}#{req}") if classic?
      x.invoice do
        x.orderid opt[:orderid]
        x.customerwmid opt[:customerwmid]
        x.storepurse opt[:storepurse]
        x.amount amount
        x.desc desc_in
        x.address address_in
        x.period opt[:period].to_i
        x.expiration opt[:expiration].to_i
      end
    }
  }
end

#xml_create_transaction(opt) ⇒ Object



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/request_xml.rb', line 101

def xml_create_transaction(opt)
  req = reqn()
  desc_in, desc_out = filter_str(opt[:desc])                  # description
  pcode = opt[:pcode].strip if opt[:period] > 0 && opt[:pcode]
  Nokogiri::XML::Builder.new( :encoding => 'windows-1251' ) { |x|
    x.send('w3s.request') {
      x.reqn req
      x.wmid(@wmid)
      x.sign sign("#{req}#{opt[:transid]}#{opt[:pursesrc]}#{opt[:pursedest]}#{opt[:amount]}#{opt[:period]||0}#{pcode}#{desc_out}#{opt[:wminvid]||0}") if classic?
      x.trans {
        x.tranid opt[:transid]                      # transaction id - unique
        x.pursesrc opt[:pursesrc]                   # sender purse
        x.pursedest opt[:pursedest]                 # recipient purse
        x.amount opt[:amount]
        x.period( opt[:period] || 0 )                # protection period (0 - no protection)
        x.pcode( pcode ) if pcode  # protection code
        x.desc desc_in
        x.wminvid( opt[:wminvid] || 0 )              # invoice number (0 - without invoice)
      }
    }
  }
end

#xml_find_wm(opt) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/request_xml.rb', line 62

def xml_find_wm(opt)
  req = reqn()
  Nokogiri::XML::Builder.new { |x|
    x.send('w3s.request') {
      x.wmid @wmid
      x.reqn req
      x.testwmpurse do
        x.wmid( opt[:wmid] || '' )
        x.purse( opt[:purse] || '' )
      end
      x.sign sign("#{opt[:wmid]}#{opt[:purse]}") if classic?
    }
  }
end

#xml_get_passport(opt) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/request_xml.rb', line 4

def xml_get_passport(opt)
  Nokogiri::XML::Builder.new { |x|
    x.request {
      x.wmid @wmid if classic?
      x.passportwmid opt[:wmid]
      x.params {
        x.dict opt[:dict] || 0
        x.info opt[:info] || 1
        x.mode opt[:mode] || 0
      }
      # unless mode == 1, signed data need'nt, but elem <sign/> required
      x.sign( opt[:mode]==1 ? sign(@wmid+opt[:wmid]) : nil ) if classic?
    }
  }
end

#xml_i_trust(opt) ⇒ Object



155
156
157
158
# File 'lib/request_xml.rb', line 155

def xml_i_trust(opt)
  opt[:wmid] = @wmid
  xml_trust_me(opt)
end

#xml_login(opt) ⇒ Object



142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/request_xml.rb', line 142

def (opt)
  Nokogiri::XML::Builder.new { |x|
    x.send('request') {
      x.siteHolder opt[:siteHolder] || @wmid
      x.user opt[:WmLogin_WMID]
      x.ticket opt[:WmLogin_Ticket]
      x.urlId  opt[:WmLogin_UrlID]
      x.authType opt[:WmLogin_AuthType]
      x.userAddress opt[:remote_ip]
    }
  }
end

#xml_outgoing_invoices(opt) ⇒ Object



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/request_xml.rb', line 124

def xml_outgoing_invoices(opt)
  req = reqn()
  Nokogiri::XML::Builder.new( :encoding => 'windows-1251' ) { |x|
    x.send('w3s.request') {
      x.reqn req
      x.wmid @wmid
      x.sign sign("#{opt[:purse]}#{req}") if classic?
      x.getoutinvoices do
        x.purse opt[:purse]
        x.wminvid opt[:wminvid]
        x.orderid opt[:orderid]
        x.datestart opt[:datestart].strftime("%Y%m%d %H:%M:%S")
        x.datefinish opt[:datefinish].strftime("%Y%m%d %H:%M:%S")
      end
    }
  }
end

#xml_send_message(opt) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/request_xml.rb', line 44

def xml_send_message(opt)
  req = reqn()
  subj_in, subj_out = filter_str(opt[:subj])
  text_in, text_out = filter_str(opt[:text])
  Nokogiri::XML::Builder.new( :encoding => 'windows-1251' ) { |x|
    x.send('w3s.request') {
      x.wmid @wmid
      x.reqn req
      x.message do
        x.receiverwmid opt[:wmid]
        x.msgsubj { x.cdata subj_in }
        x.msgtext { x.cdata text_in }
      end
      x.sign sign("#{opt[:wmid]}#{req}#{text_out}#{subj_out}") if classic?
    }
  }
end

#xml_trust_me(opt) ⇒ Object



160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/request_xml.rb', line 160

def xml_trust_me(opt)
  req = reqn()
  Nokogiri::XML::Builder.new { |x|
    x.send('w3s.request') {
      x.reqn req
      x.wmid @wmid
      x.sign sign("#{opt[:wmid]}#{req}") if classic?
      x.gettrustlist do
        x.wmid opt[:wmid]
      end
    }
  }
end