Module: Webmoney
- Includes:
- RequestResult, RequestRetval, RequestXML
- Defined in:
- lib/wmid.rb,
lib/purse.rb,
lib/passport.rb,
lib/webmoney.rb,
lib/messenger.rb,
lib/interfaces.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
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#errormsg ⇒ Object
readonly
Returns the value of attribute errormsg.
-
#interfaces ⇒ Object
readonly
Returns the value of attribute interfaces.
-
#last_request ⇒ Object
readonly
Returns the value of attribute last_request.
-
#last_response ⇒ Object
readonly
Returns the value of attribute last_response.
-
#messenger ⇒ Object
Returns the value of attribute messenger.
-
#rid ⇒ Object
readonly
Returns the value of attribute rid.
-
#wmid ⇒ Object
readonly
Returns the value of attribute wmid.
Instance Method Summary collapse
-
#classic? ⇒ Boolean
Webmoney instance is classic type?.
- #filter_str(str) ⇒ Object
-
#initialize(opt = {}) ⇒ Object
Required options:.
-
#interface_urls ⇒ Object
Presets for interfaces.
-
#request(iface, opt = {}) ⇒ Object
Generic function for request to WMT-interfaces.
-
#send_message(params) ⇒ Object
Send message through Queue and Thread.
-
#sign(str) ⇒ Object
Signing string by instance wmid’s, return signed string.
-
#w3s_url ⇒ Object
Preset for W3S.
-
#wmid_exist?(wmid) ⇒ Boolean
Check existent WMID or not.
Methods included from RequestResult
#result_balance, #result_bussines_level, #result_check_sign, #result_check_user, #result_create_invoice, #result_create_transaction, #result_find_wm, #result_get_passport, #result_login, #result_outgoing_invoices, #result_send_message, #result_trust_me
Methods included from RequestRetval
#retval_balance, #retval_check_user, #retval_common, #retval_create_invoice, #retval_find_wm, #retval_get_passport, #retval_login, #retval_outgoing_invoices
Methods included from RequestXML
#xml_balance, #xml_bussines_level, #xml_check_sign, #xml_check_user, #xml_create_invoice, #xml_create_transaction, #xml_find_wm, #xml_get_passport, #xml_i_trust, #xml_login, #xml_outgoing_invoices, #xml_send_message, #xml_trust_me
Instance Attribute Details
#error ⇒ Object (readonly)
Returns the value of attribute error.
33 34 35 |
# File 'lib/webmoney.rb', line 33 def error @error end |
#errormsg ⇒ Object (readonly)
Returns the value of attribute errormsg.
33 34 35 |
# File 'lib/webmoney.rb', line 33 def errormsg @errormsg end |
#interfaces ⇒ Object (readonly)
Returns the value of attribute interfaces.
33 34 35 |
# File 'lib/webmoney.rb', line 33 def interfaces @interfaces end |
#last_request ⇒ Object (readonly)
Returns the value of attribute last_request.
33 34 35 |
# File 'lib/webmoney.rb', line 33 def last_request @last_request end |
#last_response ⇒ Object (readonly)
Returns the value of attribute last_response.
33 34 35 |
# File 'lib/webmoney.rb', line 33 def last_response @last_response end |
#messenger ⇒ Object
Returns the value of attribute messenger.
34 35 36 |
# File 'lib/webmoney.rb', line 34 def messenger @messenger end |
#rid ⇒ Object (readonly)
Returns the value of attribute rid.
33 34 35 |
# File 'lib/webmoney.rb', line 33 def rid @rid end |
#wmid ⇒ Object (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?
135 136 137 |
# File 'lib/webmoney.rb', line 135 def classic? !! @signer end |
#filter_str(str) ⇒ Object
118 119 120 121 122 123 124 125 |
# File 'lib/webmoney.rb', line 118 def filter_str(str) if @force_encoding str_out = utf8_to_cp1251(str) [cp1251_to_utf8(str_out), str_out] else [str, utf8_to_cp1251(str)] end end |
#initialize(opt = {}) ⇒ Object
Required options:
-
:wmid - WMID
Optional:
-
:password - on Classic key or Light X509 certificate & key
-
:key - Base64 string for Classic key
OR
-
:key - OpenSSL::PKey::RSA or OpenSSL::PKey::DSA object
-
:cert - OpenSSL::X509::Certificate object
-
:ca_cert - file CA certificate or path to directory with certs (in PEM format)
56 57 58 59 60 61 62 63 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 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 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/webmoney.rb', line 56 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__) + '/../ssl-certs/ca_bundle.crt' else opt[:ca_cert] end @rid = opt[:rid] # encode will raise exception, # when uncovertable character in input sequence. It is default behavior. # With option :force_encoding uncovertable characters will be cutted. @force_encoding = opt[:force_encoding] # for backward compatibility with ruby 1.8 if String.new.respond_to?(:encode) # was: @ic_out def utf8_to_cp1251(str) return str if str.nil? || str.length < 1 @force_encoding ? str.encode('CP1251', 'UTF-8', :undef => :replace, :replace => '') : str.encode('CP1251', 'UTF-8') end # was: @ic_in def cp1251_to_utf8(str) return str if str.empty? str.encode('UTF-8', 'CP1251') end else require 'iconv' # was: @ic_out def utf8_to_cp1251(str) @force_encoding ? Iconv.iconv('CP1251//IGNORE', 'UTF-8', str)[0] : Iconv.iconv('CP1251', 'UTF-8', str)[0] end # was: @ic_in def cp1251_to_utf8(str) Iconv.iconv('UTF-8', 'CP1251', str)[0] end end def filter_str(str) if @force_encoding str_out = utf8_to_cp1251(str) [cp1251_to_utf8(str_out), str_out] else [str, utf8_to_cp1251(str)] end end prepare_interface_urls # initialize workers by self Purse.worker = self Passport.worker = self end |
#interface_urls ⇒ Object
Presets for interfaces
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/interfaces.rb', line 4 def interface_urls { :create_invoice => { :url => 'XMLInvoice.asp' }, # x1 :create_transaction => { :url => 'XMLTrans.asp' }, # x2 :operation_history => { :url => 'XMLOperations.asp' }, # x3 :outgoing_invoices => { :url => 'XMLOutInvoices.asp' }, # x4 :finish_protect => { :url => 'XMLFinishProtect.asp' }, # x5 :send_message => { :url => 'XMLSendMsg.asp' }, # x6 :check_sign => { :url => 'XMLClassicAuth.asp' }, # x7 :find_wm => { :url => 'XMLFindWMPurse.asp' }, # x8 :balance => { :url => 'XMLPurses.asp' }, # x9 :incoming_invoices => { :url => 'XMLInInvoices.asp' }, # x10 :get_passport => { :url => 'https://passport.webmoney.ru/asp/XMLGetWMPassport.asp' , # x11 :x509 => lambda {|url| url.sub(/\.asp$/, 'Cert.asp')} }, :reject_protection => { :url => 'XMLRejectProtect.asp' }, # x13 :transaction_moneyback => { :url => 'XMLTransMoneyback.asp' }, # x14 :i_trust => { :url => 'XMLTrustList.asp' }, # x15 :trust_me => { :url => 'XMLTrustList2.asp' }, # x15 :trust_save => { :url => 'XMLTrustSave2.asp' }, # x15 :create_purse => { :url => 'XMLCreatePurse.asp' }, # x16 :create_contract => { :url => 'https://arbitrage.webmoney.ru/xml/X17_CreateContract.aspx', }, # x17 :get_contract_info => { :url => 'https://arbitrage.webmoney.ru/xml/X17_GetContractInfo.aspx' }, # x17 :transaction_get => { :url => 'https://merchant.webmoney.ru/conf/xml/XMLTransGet.asp' }, # x18 :check_user => { :url => 'https://apipassport.webmoney.ru/XMLCheckUser.aspx', # x19 :x509 => lambda {|url| url.sub(/\.aspx$/, 'Cert.aspx')} }, :bussines_level => { :url => 'https://stats.wmtransfer.com/levels/XMLWMIDLevel.aspx' }, :login => { :url => 'https://login.wmtransfer.com/ws/authorize.xiface' }, # login } end |
#request(iface, opt = {}) ⇒ Object
Generic function for request to WMT-interfaces
157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/webmoney.rb', line 157 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 }
143 144 145 146 |
# File 'lib/webmoney.rb', line 143 def (params) @messenger = Messenger.new(self){} if @messenger.nil? @messenger.push(params) end |
#sign(str) ⇒ Object
Signing string by instance wmid’s, return signed string
175 176 177 |
# File 'lib/webmoney.rb', line 175 def sign(str) @signer.sign(str) unless str.nil? || str.empty? end |
#w3s_url ⇒ Object
Preset for W3S
38 39 40 |
# File 'lib/webmoney.rb', line 38 def w3s_url 'https://w3s.wmtransfer.com/asp/' end |