Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

X20 support #15

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ doc/*
lib/wmsigner.so
pkg/*
tmp/*

.idea
36 changes: 35 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ XML-interfaces: http://www.wmtransfer.com/eng/developers/interfaces/index.shtml

Gem have built-in native *wmsigner*.

Compatible with ruby: 1.8.7, 1.9.2
Compatible with ruby: 1.8.7, 1.9.2, 2.0.0
Reqirements: Nokogiri >= 1.4.1 built with libxml2 >= 2.7 (IMPORTANT!)

Author:: Alexander Oryol (mailto:eagle.alex@gmail.com)
License:: MIT License

Also supported by: Pavel Sorokin (mailto:pahan40@gmail.com)

# Request types

Completed:
Expand All @@ -25,6 +27,8 @@ Completed:
* i_trust - x15
* trust_me - x15
* check_user - x19
* req_payment - x20
* conf_payment - x20
* bussines_level
* login

Expand Down Expand Up @@ -205,4 +209,34 @@ res = @wm.request(:check_user,
)
```


## X20 create payment

```ruby
@response = @wm.request(
:req_payment,
:wmid => '210987654321',
:purse => "R123456789012",
:amount => 1,
:description => "Any payment you want",
:clientid => '123456789012',
:clientidtype => '1',
:smstype => '1',
:paymentid => '815195258'
)
```

## X20 Confirm payment

```ruby
@result = @wm.request(
:conf_payment,
:wmid => '210987654321',
:purse => Settings.purse,
:paymentcode => '1234',
:invoiceid => '815195258'
)

Also, see spec/* for examples.


236 changes: 236 additions & 0 deletions README.md~
Original file line number Diff line number Diff line change
@@ -0,0 +1,236 @@
# About Webmoney library

This library should help to make requests to WebMoney Transfer http://www.wmtransfer.com
XML-interfaces: http://www.wmtransfer.com/eng/developers/interfaces/index.shtml

Gem have built-in native *wmsigner*.

Compatible with ruby: 1.8.7, 1.9.2
Reqirements: Nokogiri >= 1.4.1 built with libxml2 >= 2.7 (IMPORTANT!)

Author:: Alexander Oryol (mailto:eagle.alex@gmail.com)
License:: MIT License

# Request types

Completed:

* create_invoice - x1
* create_transaction - x2
* outgoing_invoices - x4
* send_message - x6
* find_wm - x8
* balance - x9
* get_passport - x11
* i_trust - x15
* trust_me - x15
* check_user - x19
* bussines_level
* login

Incompleted (help need!):

* operation_history - x3
* finish_protect - x5
* check_sign - x7
* incoming_invoices - x10
* reject_protection - x13
* transaction_moneyback - x14
* trust_save - x15
* create_purse - x16
* create_contract - x17
* transaction_get - x18
* req_payment - x20
* conf_payment - x20

Please, see relative documentation and parameters on wiki:

http://wiki.wmtransfer.com/wiki/list/XML-Interfaces

http://wiki.webmoney.ru/wiki/list/XML-%D0%B8%D0%BD%D1%82%D0%B5%D1%80%D1%84%D0%B5%D0%B9%D1%81%D1%8B (in russian)

or official sites:

http://www.wmtransfer.com/eng/developers/interfaces/xml/index.shtml

http://www.webmoney.ru/rus/developers/interfaces/xml/index.shtml (in russian)

# Examples

## Setup

```ruby
class MyWM
include Webmoney
end
```

```ruby
@wm = MyWM.new(:wmid => '123456789012', :password => 'my_pass', :key => 'gQABAIR6...2cC8FZTyKyjBM=')

wmid = '111222333444'
```

## Light

The key convert instruction from P12 format to PEM see [here](http://wiki.webmoney.ru/projects/webmoney/wiki/konvertatsiya_klyuchey_wm_keeper_light_v_pem_format)

```ruby
mywm = MyWM.new(:wmid => '123456789012',
:cert => 'webmoney.pem', # ~/.wm/webmoney.pem
# :cert => '/home/user/webmoney.pem',
:key => 'webmoney.key', # ~/.wm/webmoney.key
# :key => '/home/user/webmoney.key',
:password => 'pa$$w0rt')
```
or

```ruby
cert = OpenSSL::X509::Certificate.new(File.read("webmoney.pem"))
key = OpenSSL::PKey::RSA.new(File.read("webmoney.key"), "password")
mywm = MyWM.new(:wmid => '123456789012', :cert => cert, :key => key)
```

## Passport (X11)

Get attestat data:

```ruby
passport = Webmoney::Passport.new(wmid, :mode => 1) # optionally :mode, :dict, :info
passport.attestat # { # hash
# :attestat => 110, # == FORMAL attestat, as example
# :created_at => Wed Feb 25 21:54:01 +0300 2004 # Time object
# :cid => "103453"
# and etc.
# }
passport.wmids # All wmids attached to the attestat
passport.userinfo[:country] # => 'Russia' # Userinfo fields in string context
passport.userinfo[:country].checked # => true # with checked/locked attribute
passport.directory # Base dictionary
```

## Bussines level

```ruby
bl = @wm.request(:bussines_level, :wmid => wmid) # => 15
```

## Sending message

... for one message:

```ruby
@wm.request(:send_message, :wmid => wmid, :subj => 'Subject', :text => 'Body of \<b>message\</b>')
```

... for many messages (with queue):

```ruby
@wm.send_message(:wmid => wmid, :subj => 'Subject', :text => 'Body of \<b>message\</b>') do |msg, result|
File.open("logfile", "w") do |file|
case result
when Hash
file.puts "Message #{msg.inspect} sended in:#{result[:date]} with id:#{result[:id]}"
else
file.puts "Error sent message #{msg.inspect}: #{result.message}"
end
end
end
```

## Purses and WMIDs

```ruby
@wm.wmid_exist?('123456789012') # => true

purse = Purse.new('Z123456789012')
purse.wmid # => '123456789012'
purse.belong_to?('123456789012') # => true
```

## Example: Create invoice and check it's state

```ruby
@wm = MyWM.new(:wmid => '123456789012', :password => 'my_pass', :key => 'gQABAIR6...2cC8FZTyKyjBM=')
```

### Create invoice

```ruby
@invoice = @wm.request(:create_invoice,
:orderid => 5,
:amount => 10,
:customerwmid => CUSTOMER_WMID,
:storepurse => STORE_PURSE,
:desc => "Test invoice",
:address => "Delivery Address"
)
```

### Check state

```ruby
res = @wm.request(:outgoing_invoices,
:purse => STORE_PURSE,
:wminvid => @invoice[:id],
:orderid => @invoice[:orderid],
:customerwmid => CUSTOMER_WMID,
:datestart => @invoice[:created_at],
:datefinish => @invoice[:created_at]
)
if res[:retval].should == 0 && !res[:invoices].empty?
invoice = res[:invoices].first
case invoice[:state]
when 0 then # Not Paid
when 1 then # Paid with protection
when 2 then # Payment complete
when 3 then # Rejected
end
end
```

## Check purse owner

```ruby
res = @wm.request(:check_user,
:operation => {
:type => 2,
:amount => 100,
:pursetype => "WMZ"
},
:userinfo => {
:wmid => "123445532523",
:iname => "Alexander",
:fname => "Ivanov"
}
)
```


## X20 create payment

```ruby
@response = @wm.request(
:req_payment,
:wmid => '210987654321',
:purse => "R123456789012",
:amount => 1,
:description => "Any payment you want",
:clientid => '123456789012',
:clientidtype => '1',
:smstype => '1',
:paymentid => '815195258'
)
##
## X20 Confirm payment
```ruby
@result = @wm.request(
:conf_payment,
:wmid => '210987654321',
:purse => Settings.purse,
:paymentcode => '1234',
:invoiceid => '815195258'
)
Also, see spec/* for examples.


4 changes: 4 additions & 0 deletions RUNNING_TESTS
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ first:
key: 'gQABAIR6... YOUR BASE64-KEY (see wmsigner readme) ...2cC8FZTyKyjBM='
password: _your_password_
wmz: Z123456789012
wmr: R123456789012
second:
wmtype: light
wmid: '012345678901'
Expand All @@ -24,4 +25,7 @@ second:
HOWTO convert Light-keys:
Russian: https://wiki.webmoney.ru/wiki/show/Konvertatsiya_klyuchey_WM_Keeper_Light_v_PEM_format

For X20 support, you need to attach your purse (wmz or wmr) to merchant service.
Russian: http://wiki.webmoney.ru/projects/webmoney/wiki/interfeys_x20

Then type (RSpec required): rake spec
4 changes: 4 additions & 0 deletions lib/interfaces.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ def interface_urls
: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
:req_payment => { :url => 'https://merchant.webmoney.ru/conf/xml/XMLTransRequest.asp'}, # x20
:conf_payment => { :url => 'https://merchant.webmoney.ru/conf/xml/XMLTransConfirm.asp'}, # x20
:set_trust => { :url => 'https://merchant.webmoney.ru/conf/xml/XMLTrustRequest.asp'}, # x21
:confirm_trust => { :url => 'https://merchant.webmoney.ru/conf/xml/XMLTrustConfirm.asp'}, # x21
}
end

Expand Down
Loading