money_online 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +4 -0
- data/Gemfile +3 -0
- data/README.md +66 -0
- data/Rakefile +1 -0
- data/lib/money_online/config.rb +14 -0
- data/lib/money_online/request.rb +37 -0
- data/lib/money_online/response.rb +69 -0
- data/lib/money_online/version.rb +3 -0
- data/lib/money_online.rb +32 -0
- data/money_online.gemspec +22 -0
- metadata +67 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
# MoneyOnline
|
2
|
+
|
3
|
+
This gem implements a simple Ruby interface for the [MoneyOnline](http://dengionline.com/eng) service (aka DengiOnline, [Деньги Онлайн](http://dengionline.com)).
|
4
|
+
|
5
|
+
## Install
|
6
|
+
|
7
|
+
If you're on Rails, add the following line to a Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem "money_online"
|
11
|
+
```
|
12
|
+
|
13
|
+
## Using
|
14
|
+
|
15
|
+
MoneyOnline requires a config file, add the initializer to config/initializers folder:
|
16
|
+
|
17
|
+
```yaml
|
18
|
+
# config/money_online.yml
|
19
|
+
project: 1
|
20
|
+
secret: "password"
|
21
|
+
```
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
# config/initializers/money_online.rb
|
25
|
+
MoneyOnline.config_path = Rails.root.join("config", "money_online.yml")
|
26
|
+
```
|
27
|
+
|
28
|
+
List of payment systems you can find [here](http://www.onlinedengi.ru/dev/paymodes.php).
|
29
|
+
|
30
|
+
## Example
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
# app/controllers/orders_controller.rb
|
34
|
+
class OrdersController < ApplicationController
|
35
|
+
|
36
|
+
# POST /orders/1/purchase
|
37
|
+
def purchase
|
38
|
+
# params #=> amount: 7300, user_id: 107, system_id: 46, order_id: 8964
|
39
|
+
request = MoneyOnline::Request.new(params)
|
40
|
+
redirect_to request.url
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
# app/controllers/payments_controller.rb
|
46
|
+
class PaymentsController < ApplicationController
|
47
|
+
|
48
|
+
# POST /payments/1/confirm
|
49
|
+
def confirm
|
50
|
+
# params #=> amount: 7300, userid: 107, paymentid: 8831914, orderid: 8964, key: "d27f27b54c5c9b944685a111483e68b5"
|
51
|
+
response = MoneyOnline::Response.new(params)
|
52
|
+
if response.valid? && (Order.find(response.order_id).amount == response.amount)
|
53
|
+
payment.confirm!
|
54
|
+
end
|
55
|
+
render :xml => response
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
```
|
60
|
+
|
61
|
+
## TODO
|
62
|
+
|
63
|
+
* 10 000 000 $
|
64
|
+
|
65
|
+
|
66
|
+
### Copyright (c) 2011 [Dimko](mailto:deemox@gmail.com).
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module MoneyOnline
|
2
|
+
class Request
|
3
|
+
attr_reader :params
|
4
|
+
|
5
|
+
def initialize(params)
|
6
|
+
@params = {
|
7
|
+
:currency => "RUB"
|
8
|
+
}.merge(params)
|
9
|
+
|
10
|
+
raise ArgumentError, "MoneyOnline::Request requires amount, user_id, system_id, order_id and currency" unless params_valid?
|
11
|
+
end
|
12
|
+
|
13
|
+
def mapped_params
|
14
|
+
{
|
15
|
+
:project => MoneyOnline.config.project,
|
16
|
+
:amount => params[:amount],
|
17
|
+
:nickname => params[:user_id],
|
18
|
+
:nick_extra => params[:user_extra],
|
19
|
+
:mode_type => params[:system_id],
|
20
|
+
:order_id => params[:order_id],
|
21
|
+
:paymentCurrency => params[:currency]
|
22
|
+
}
|
23
|
+
end
|
24
|
+
|
25
|
+
def url
|
26
|
+
"http://www.onlinedengi.ru/wmpaycheck.php?#{MoneyOnline.build_query(mapped_params)}"
|
27
|
+
end
|
28
|
+
|
29
|
+
def params_valid?
|
30
|
+
[:amount, :user_id, :system_id, :order_id, :currency].inject(true) do |memo, attribute|
|
31
|
+
memo = false unless params[attribute]
|
32
|
+
memo
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
module MoneyOnline
|
2
|
+
class Response
|
3
|
+
attr_reader :params
|
4
|
+
|
5
|
+
def initialize(params)
|
6
|
+
@params = params
|
7
|
+
end
|
8
|
+
|
9
|
+
def amount
|
10
|
+
params[:amount].to_i
|
11
|
+
end
|
12
|
+
|
13
|
+
def user_id
|
14
|
+
params[:userid].to_i
|
15
|
+
end
|
16
|
+
|
17
|
+
def user_extra
|
18
|
+
params[:userid_extra]
|
19
|
+
end
|
20
|
+
|
21
|
+
def money_payment_id
|
22
|
+
params[:paymentid].to_i
|
23
|
+
end
|
24
|
+
|
25
|
+
def order_id
|
26
|
+
params[:orderid].to_i
|
27
|
+
end
|
28
|
+
|
29
|
+
def signature
|
30
|
+
params[:key]
|
31
|
+
end
|
32
|
+
|
33
|
+
def generate_signature_string
|
34
|
+
[amount, user_id, money_payment_id, MoneyOnline.config.secret].join
|
35
|
+
end
|
36
|
+
|
37
|
+
def generate_signature
|
38
|
+
Digest::MD5.hexdigest(generate_signature_string)
|
39
|
+
end
|
40
|
+
|
41
|
+
def valid?
|
42
|
+
generate_signature == signature
|
43
|
+
end
|
44
|
+
|
45
|
+
def invalid?
|
46
|
+
not valid?
|
47
|
+
end
|
48
|
+
|
49
|
+
def to_xml(*args)
|
50
|
+
<<-XML
|
51
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
52
|
+
<result>
|
53
|
+
<id>#{order_id}</id>
|
54
|
+
<code>#{code}</code>
|
55
|
+
<comment>#{error}</comment>
|
56
|
+
</result>
|
57
|
+
XML
|
58
|
+
end
|
59
|
+
|
60
|
+
def code
|
61
|
+
valid? ? "YES" : "NO"
|
62
|
+
end
|
63
|
+
|
64
|
+
def error
|
65
|
+
"Signature is not valid" if invalid?
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
end
|
data/lib/money_online.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require "uri"
|
2
|
+
require "yaml"
|
3
|
+
require "digest/md5"
|
4
|
+
require "money_online/config"
|
5
|
+
require "money_online/request"
|
6
|
+
require "money_online/response"
|
7
|
+
require "money_online/version"
|
8
|
+
|
9
|
+
module MoneyOnline
|
10
|
+
extend self
|
11
|
+
|
12
|
+
attr_accessor :config_path
|
13
|
+
|
14
|
+
def config
|
15
|
+
@config ||= MoneyOnline::Config.new(config_hash)
|
16
|
+
end
|
17
|
+
|
18
|
+
def build_query(params)
|
19
|
+
params.map do |key, value|
|
20
|
+
"#{escape(key)}=#{escape(value)}" if value
|
21
|
+
end.compact.join("&")
|
22
|
+
end
|
23
|
+
|
24
|
+
def escape(string)
|
25
|
+
URI.encode_www_form_component(string)
|
26
|
+
end
|
27
|
+
|
28
|
+
def config_hash
|
29
|
+
YAML.load_file(config_path)
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "money_online/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "money_online"
|
7
|
+
s.version = MoneyOnline::VERSION
|
8
|
+
s.authors = ["Dimko"]
|
9
|
+
s.email = ["deemox@gmail.com"]
|
10
|
+
s.homepage = "http://github.com/dimko/money_online"
|
11
|
+
s.summary = %q{Simple wrapper for a DengiOnline service}
|
12
|
+
s.description = %q{MoneyOnline (aka DengiOnline) is a payment system, that have a single interface for many payment providers}
|
13
|
+
|
14
|
+
s.rubyforge_project = "money_online"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
s.add_dependency "active_support", "~> 3.0"
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: money_online
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Dimko
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-09-14 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: active_support
|
16
|
+
requirement: &70345677064500 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '3.0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70345677064500
|
25
|
+
description: MoneyOnline (aka DengiOnline) is a payment system, that have a single
|
26
|
+
interface for many payment providers
|
27
|
+
email:
|
28
|
+
- deemox@gmail.com
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- .gitignore
|
34
|
+
- Gemfile
|
35
|
+
- README.md
|
36
|
+
- Rakefile
|
37
|
+
- lib/money_online.rb
|
38
|
+
- lib/money_online/config.rb
|
39
|
+
- lib/money_online/request.rb
|
40
|
+
- lib/money_online/response.rb
|
41
|
+
- lib/money_online/version.rb
|
42
|
+
- money_online.gemspec
|
43
|
+
homepage: http://github.com/dimko/money_online
|
44
|
+
licenses: []
|
45
|
+
post_install_message:
|
46
|
+
rdoc_options: []
|
47
|
+
require_paths:
|
48
|
+
- lib
|
49
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
57
|
+
requirements:
|
58
|
+
- - ! '>='
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
requirements: []
|
62
|
+
rubyforge_project: money_online
|
63
|
+
rubygems_version: 1.8.10
|
64
|
+
signing_key:
|
65
|
+
specification_version: 3
|
66
|
+
summary: Simple wrapper for a DengiOnline service
|
67
|
+
test_files: []
|