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?.
-
#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_bussines_level, #result_check_sign, #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_common, #retval_create_invoice, #retval_find_wm, #retval_get_passport, #retval_login, #retval_outgoing_invoices
Methods included from RequestXML
#xml_bussines_level, #xml_check_sign, #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.
34 35 36 |
# File 'lib/webmoney.rb', line 34 def error @error end |
#errormsg ⇒ Object (readonly)
Returns the value of attribute errormsg.
34 35 36 |
# File 'lib/webmoney.rb', line 34 def errormsg @errormsg end |
#interfaces ⇒ Object (readonly)
Returns the value of attribute interfaces.
34 35 36 |
# File 'lib/webmoney.rb', line 34 def interfaces @interfaces end |
#last_request ⇒ Object (readonly)
Returns the value of attribute last_request.
34 35 36 |
# File 'lib/webmoney.rb', line 34 def last_request @last_request end |
#last_response ⇒ Object (readonly)
Returns the value of attribute last_response.
34 35 36 |
# File 'lib/webmoney.rb', line 34 def last_response @last_response end |
#messenger ⇒ Object
Returns the value of attribute messenger.
35 36 37 |
# File 'lib/webmoney.rb', line 35 def messenger @messenger end |
#rid ⇒ Object (readonly)
Returns the value of attribute rid.
34 35 36 |
# File 'lib/webmoney.rb', line 34 def rid @rid end |
#wmid ⇒ Object (readonly)
Returns the value of attribute wmid.
34 35 36 |
# File 'lib/webmoney.rb', line 34 def wmid @wmid end |
Instance Method Details
#classic? ⇒ Boolean
Webmoney instance is classic type?
116 117 118 |
# File 'lib/webmoney.rb', line 116 def classic? !! @signer 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)
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 |
# File 'lib/webmoney.rb', line 57 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 @rid = opt[:rid] # Iconv will raise exception Iconv::IllegalSequence, # when uncovertable character in input sequence. It is default behavior. # With option :force_encoding Iconv initialized with //IGNORE option, and # uncovertable characters will be cutted. @ic_in = Iconv.new('UTF-8', 'CP1251') if opt[:force_encoding] #Iconv.new(to, from) @ic_out = Iconv.new('CP1251//IGNORE', 'UTF-8') instance_eval do def filter_str(str) str_out = @ic_out.iconv(str) return @ic_in.iconv(str_out), str_out end end else @ic_out = Iconv.new('CP1251', 'UTF-8') instance_eval do def filter_str(str) return str, @ic_out.iconv(str) end end end prepare_interface_urls # initialize workers by self Purse.worker = self Passport.worker = self end |
#interface_urls ⇒ Object
Presets for interfaces
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/interfaces.rb', line 3 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', :login => 'https://login.wmtransfer.com/ws/authorize.xiface' # login } end |
#request(iface, opt = {}) ⇒ Object
Generic function for request to WMT-interfaces
138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/webmoney.rb', line 138 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 }
124 125 126 127 |
# File 'lib/webmoney.rb', line 124 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
156 157 158 |
# File 'lib/webmoney.rb', line 156 def sign(str) @signer.sign(str) unless str.nil? || str.empty? end |
#w3s_url ⇒ Object
Preset for W3S
39 40 41 |
# File 'lib/webmoney.rb', line 39 def w3s_url 'https://w3s.wmtransfer.com/asp/' end |