Module: Webmoney

Includes:
RequestResult, RequestRetval, RequestXML
Defined in:
lib/wmid.rb,
lib/purse.rb,
lib/passport.rb,
lib/webmoney.rb,
lib/messenger.rb

Overview

Module for Webmoney lib. Instance contain info for WMT-interfaces requests (wmid, key, etc). Implement general requests.

Defined Under Namespace

Modules: RequestResult, RequestRetval, RequestXML Classes: CaCertificateError, IncorrectPurseError, IncorrectWmidError, Messenger, NonExistentWmidError, Passport, Purse, RequestError, ResultError, WebmoneyError, Wmid

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from RequestResult

#result_bussines_level, #result_check_sign, #result_create_transaction, #result_find_wm, #result_get_passport, #result_send_message

Methods included from RequestRetval

#retval_common, #retval_find_wm, #retval_get_passport

Methods included from RequestXML

#xml_bussines_level, #xml_check_sign, #xml_create_transaction, #xml_find_wm, #xml_get_passport, #xml_send_message

Instance Attribute Details

#errorObject (readonly)

Returns the value of attribute error.



33
34
35
# File 'lib/webmoney.rb', line 33

def error
  @error
end

#errormsgObject (readonly)

Returns the value of attribute errormsg.



33
34
35
# File 'lib/webmoney.rb', line 33

def errormsg
  @errormsg
end

#interfacesObject (readonly)

Returns the value of attribute interfaces.



33
34
35
# File 'lib/webmoney.rb', line 33

def interfaces
  @interfaces
end

#last_requestObject (readonly)

Returns the value of attribute last_request.



33
34
35
# File 'lib/webmoney.rb', line 33

def last_request
  @last_request
end

#last_responseObject (readonly)

Returns the value of attribute last_response.



33
34
35
# File 'lib/webmoney.rb', line 33

def last_response
  @last_response
end

#messengerObject

Returns the value of attribute messenger.



34
35
36
# File 'lib/webmoney.rb', line 34

def messenger
  @messenger
end

#wmidObject (readonly)

Returns the value of attribute wmid.



33
34
35
# File 'lib/webmoney.rb', line 33

def wmid
  @wmid
end

Instance Method Details

#classic?Boolean

Webmoney instance is classic type?

Returns:

  • (Boolean)


122
123
124
# File 'lib/webmoney.rb', line 122

def classic?
  !! @signer
end

#initialize(opt = {}) ⇒ Object

Required options:

  • :wmid - WMID

  • :password - on Classic key or Light X509 certificate & key

  • :key - Base64 string for Classic key

OR #TODO

  • :key - OpenSSL::PKey::RSA or OpenSSL::PKey::DSA object

  • :cert - OpenSSL::X509::Certificate object

Optional:

  • :ca_cert - file CA certificate or path to directory with certs (in PEM format)



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/webmoney.rb', line 84

def initialize(opt = {})

  unless check_libxml_version
    $stderr.puts "WARNING: webmoney lib will not work correctly with nokogori compiled with libxml2 version < 2.7.0"
  end

  @wmid = Wmid.new(opt[:wmid])

  # classic or light
  case opt[:key]
    when String
      @signer = Signer.new(@wmid, opt[:password], opt[:key])
    when OpenSSL::PKey::RSA, OpenSSL::PKey::DSA
      @key = opt[:key]
      @cert = opt[:cert]
      @password = opt[:password]
  end

  # ca_cert or default
  @ca_cert =
    if opt[:ca_cert].nil?
       File.dirname(__FILE__) + '/../lib/certs/'
    else
      opt[:ca_cert]
    end

  # Iconv.new(to, from)
  @ic_in = Iconv.new('UTF-8', 'CP1251')
  @ic_out = Iconv.new('CP1251', 'UTF-8')

  prepare_interface_urls

  # initialize workers by self
  Purse.worker = self
  Passport.worker = self
end

#interface_urlsObject

Presets for interfaces



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/webmoney.rb', line 43

def interface_urls
  {
    :create_invoice      => w3s_url + 'XMLInvoice.asp',       # x1
    :create_transaction  => w3s_url + 'XMLTrans.asp',         # x2
    :operation_history   => w3s_url + 'XMLOperations.asp',    # x3
    :outgoing_invoices   => w3s_url + 'XMLOutInvoices.asp',   # x4
    :finish_protect      => w3s_url + 'XMLFinishProtect.asp', # x5
    :send_message        => w3s_url + 'XMLSendMsg.asp',       # x6
    :check_sign          => w3s_url + 'XMLClassicAuth.asp',   # x7
    :find_wm             => w3s_url + 'XMLFindWMPurse.asp',   # x8
    :balance             => w3s_url + 'XMLPurses.asp',        # x9
    :incoming_invoices   => w3s_url + 'XMLInInvoices.asp',    # x10
    :get_passport        => 'https://passport.webmoney.ru/asp/XMLGetWMPassport.asp', # x11
    :reject_protection   => w3s_url + 'XMLRejectProtect.asp', # x13
    :transaction_moneyback => w3s_url + 'XMLTransMoneyback.asp', # x14
    :i_trust             => w3s_url + 'XMLTrustList.asp',     # x15
    :trust_me            => w3s_url + 'XMLTrustList2.asp',    # x15
    :trust_save          => w3s_url + 'XMLTrustSave2.asp',    # x15
    :create_purse        => w3s_url + 'XMLCreatePurse.asp',   # x16
    :create_contract => 'https://arbitrage.webmoney.ru/xml/X17_CreateContract.aspx', # x17
    :transaction_get => 'https://merchant.webmoney.ru/conf/xml/XMLTransGet.asp', # x18
    :bussines_level  => 'https://stats.wmtransfer.com/levels/XMLWMIDLevel.aspx'
  }
end

#request(iface, opt = {}) ⇒ Object

Generic function for request to WMT-interfaces

Raises:

  • (ArgumentError)


144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/webmoney.rb', line 144

def request(iface, opt ={})
  raise ArgumentError, "should be hash" unless opt.kind_of?(Hash)

  # Use self wmid when not defined
  opt[:wmid] ||= @wmid

  # Do request
  res = https_request(iface, make_xml(iface, opt))

  # Parse response
  doc = Nokogiri::XML(res)
  parse_retval(iface, doc)
  make_result(iface, doc)
end

#send_message(params) ⇒ Object

Send message through Queue and Thread

Params: { :wmid, :subj, :text }



130
131
132
133
# File 'lib/webmoney.rb', line 130

def send_message(params)
  @messenger = Messenger.new(self){} if @messenger.nil?
  @messenger.push(params)
end

#sign(str) ⇒ Object

Signing string by instance wmid’s, return signed string



162
163
164
# File 'lib/webmoney.rb', line 162

def sign(str)
  @signer.sign(str) unless str.nil? || str.empty?
end

#w3s_urlObject

Preset for W3S



38
39
40
# File 'lib/webmoney.rb', line 38

def w3s_url
  'https://w3s.wmtransfer.com/asp/'
end

#wmid_exist?(wmid) ⇒ Boolean

Check existent WMID or not

Params: wmid

Returns:

  • (Boolean)


138
139
140
# File 'lib/webmoney.rb', line 138

def wmid_exist?(wmid)
  request(:find_wm, :wmid => Wmid.new(wmid))[:retval] == 1
end