rubykassa 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +26 -0
- data/.travis.yml +6 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +139 -0
- data/Guardfile +5 -0
- data/MIT-LICENSE +20 -0
- data/README.md +26 -0
- data/Rakefile +7 -0
- data/app/controllers/.gitkeep +0 -0
- data/app/controllers/robokassa_controller.rb +30 -0
- data/config/routes.rb +8 -0
- data/lib/rubykassa/action_view_extension.rb +10 -0
- data/lib/rubykassa/client.rb +21 -0
- data/lib/rubykassa/configuration.rb +15 -0
- data/lib/rubykassa/engine.rb +10 -0
- data/lib/rubykassa/notification.rb +26 -0
- data/lib/rubykassa/payment_interface.rb +50 -0
- data/lib/rubykassa/signature_generator.rb +21 -0
- data/lib/rubykassa/version.rb +4 -0
- data/lib/rubykassa/xml_interface.rb +57 -0
- data/lib/rubykassa.rb +28 -0
- data/rubykassa.gemspec +27 -0
- data/script/rails +8 -0
- data/spec/dummy/README.rdoc +261 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/controllers/application_controller.rb +4 -0
- data/spec/dummy/app/controllers/welcome_controller.rb +5 -0
- data/spec/dummy/app/views/layouts/application.html.erb +12 -0
- data/spec/dummy/app/views/welcome/index.html.erb +24 -0
- data/spec/dummy/config/application.rb +60 -0
- data/spec/dummy/config/boot.rb +11 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +6 -0
- data/spec/dummy/config/environments/development.rb +38 -0
- data/spec/dummy/config/environments/production.rb +68 -0
- data/spec/dummy/config/environments/test.rb +38 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +8 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +6 -0
- data/spec/dummy/config/initializers/rubykassa.rb +8 -0
- data/spec/dummy/config/initializers/secret_token.rb +8 -0
- data/spec/dummy/config/initializers/session_store.rb +9 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +15 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +6 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/lib/assets/.gitkeep +0 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +25 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/rubykassa/client_configuration_spec.rb +60 -0
- data/spec/rubykassa/notification_spec.rb +31 -0
- data/spec/rubykassa/payment_interface_spec.rb +41 -0
- data/spec/rubykassa/xml_interface_spec.rb +27 -0
- data/spec/spec_helper.rb +12 -0
- metadata +205 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: fb7b7735b191f748207076ea975421b7fa513025
|
4
|
+
data.tar.gz: ae694c27916cd5dbe1365f047cd9e8324c8c58a0
|
5
|
+
!binary "U0hBNTEy":
|
6
|
+
metadata.gz: 5861395cf63acbd75ac9d1a0b798f26d548a084a40ec6555c9fe5809b75fcbf59bf0a0f742216ca4d2316a7e6df334d8aa4dc852c49e57b3d6971d68b893043c
|
7
|
+
data.tar.gz: 1d8565a5151e30169e5ae1c3ac33e06069d6be4b0e6e3f1faf0628240ca43ba46da1e78a113e51986dc39fc6362706f53c13c07a8460cf37a0e4de4608442c11
|
data/.gitignore
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
.bundle/
|
2
|
+
log/*.log
|
3
|
+
pkg/
|
4
|
+
spec/dummy/log
|
5
|
+
spec/dummy/db/*.sqlite3
|
6
|
+
spec/dummy/tmp/
|
7
|
+
spec/dummy/.sass-cache
|
8
|
+
*.gem
|
9
|
+
*.rbc
|
10
|
+
.config
|
11
|
+
coverage
|
12
|
+
InstalledFiles
|
13
|
+
lib/bundler/man
|
14
|
+
rdoc
|
15
|
+
spec/reports
|
16
|
+
spec/tmp
|
17
|
+
spec/version_tmp
|
18
|
+
tmp
|
19
|
+
.DS_Store
|
20
|
+
passenger.3000.log
|
21
|
+
passenger.3000.pid.lock
|
22
|
+
|
23
|
+
# YARD artifacts
|
24
|
+
.yardoc
|
25
|
+
_yardoc
|
26
|
+
doc/
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,139 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
rubykassa (0.0.1)
|
5
|
+
multi_xml
|
6
|
+
rails (~> 3.2.13)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: http://rubygems.org/
|
10
|
+
specs:
|
11
|
+
actionmailer (3.2.13)
|
12
|
+
actionpack (= 3.2.13)
|
13
|
+
mail (~> 2.5.3)
|
14
|
+
actionpack (3.2.13)
|
15
|
+
activemodel (= 3.2.13)
|
16
|
+
activesupport (= 3.2.13)
|
17
|
+
builder (~> 3.0.0)
|
18
|
+
erubis (~> 2.7.0)
|
19
|
+
journey (~> 1.0.4)
|
20
|
+
rack (~> 1.4.5)
|
21
|
+
rack-cache (~> 1.2)
|
22
|
+
rack-test (~> 0.6.1)
|
23
|
+
sprockets (~> 2.2.1)
|
24
|
+
activemodel (3.2.13)
|
25
|
+
activesupport (= 3.2.13)
|
26
|
+
builder (~> 3.0.0)
|
27
|
+
activerecord (3.2.13)
|
28
|
+
activemodel (= 3.2.13)
|
29
|
+
activesupport (= 3.2.13)
|
30
|
+
arel (~> 3.0.2)
|
31
|
+
tzinfo (~> 0.3.29)
|
32
|
+
activeresource (3.2.13)
|
33
|
+
activemodel (= 3.2.13)
|
34
|
+
activesupport (= 3.2.13)
|
35
|
+
activesupport (3.2.13)
|
36
|
+
i18n (= 0.6.1)
|
37
|
+
multi_json (~> 1.0)
|
38
|
+
arel (3.0.2)
|
39
|
+
builder (3.0.4)
|
40
|
+
coderay (1.0.9)
|
41
|
+
diff-lcs (1.2.4)
|
42
|
+
erubis (2.7.0)
|
43
|
+
ffi (1.8.1)
|
44
|
+
formatador (0.2.4)
|
45
|
+
growl (1.0.3)
|
46
|
+
guard (1.8.0)
|
47
|
+
formatador (>= 0.2.4)
|
48
|
+
listen (>= 1.0.0)
|
49
|
+
lumberjack (>= 1.0.2)
|
50
|
+
pry (>= 0.9.10)
|
51
|
+
thor (>= 0.14.6)
|
52
|
+
guard-rspec (1.2.1)
|
53
|
+
guard (>= 1.1)
|
54
|
+
hike (1.2.2)
|
55
|
+
i18n (0.6.1)
|
56
|
+
journey (1.0.4)
|
57
|
+
json (1.8.0)
|
58
|
+
listen (1.1.4)
|
59
|
+
rb-fsevent (>= 0.9.3)
|
60
|
+
rb-inotify (>= 0.9)
|
61
|
+
rb-kqueue (>= 0.2)
|
62
|
+
lumberjack (1.0.3)
|
63
|
+
mail (2.5.4)
|
64
|
+
mime-types (~> 1.16)
|
65
|
+
treetop (~> 1.4.8)
|
66
|
+
method_source (0.8.1)
|
67
|
+
mime-types (1.23)
|
68
|
+
multi_json (1.7.4)
|
69
|
+
multi_xml (0.5.3)
|
70
|
+
polyglot (0.3.3)
|
71
|
+
pry (0.9.12.2)
|
72
|
+
coderay (~> 1.0.5)
|
73
|
+
method_source (~> 0.8)
|
74
|
+
slop (~> 3.4)
|
75
|
+
rack (1.4.5)
|
76
|
+
rack-cache (1.2)
|
77
|
+
rack (>= 0.4)
|
78
|
+
rack-ssl (1.3.3)
|
79
|
+
rack
|
80
|
+
rack-test (0.6.2)
|
81
|
+
rack (>= 1.0)
|
82
|
+
rails (3.2.13)
|
83
|
+
actionmailer (= 3.2.13)
|
84
|
+
actionpack (= 3.2.13)
|
85
|
+
activerecord (= 3.2.13)
|
86
|
+
activeresource (= 3.2.13)
|
87
|
+
activesupport (= 3.2.13)
|
88
|
+
bundler (~> 1.0)
|
89
|
+
railties (= 3.2.13)
|
90
|
+
railties (3.2.13)
|
91
|
+
actionpack (= 3.2.13)
|
92
|
+
activesupport (= 3.2.13)
|
93
|
+
rack-ssl (~> 1.3.2)
|
94
|
+
rake (>= 0.8.7)
|
95
|
+
rdoc (~> 3.4)
|
96
|
+
thor (>= 0.14.6, < 2.0)
|
97
|
+
rake (10.0.4)
|
98
|
+
rb-fsevent (0.9.3)
|
99
|
+
rb-inotify (0.9.0)
|
100
|
+
ffi (>= 0.5.0)
|
101
|
+
rb-kqueue (0.2.0)
|
102
|
+
ffi (>= 0.5.0)
|
103
|
+
rdoc (3.12.2)
|
104
|
+
json (~> 1.4)
|
105
|
+
rspec-core (2.13.1)
|
106
|
+
rspec-expectations (2.13.0)
|
107
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
108
|
+
rspec-mocks (2.13.1)
|
109
|
+
rspec-rails (2.13.2)
|
110
|
+
actionpack (>= 3.0)
|
111
|
+
activesupport (>= 3.0)
|
112
|
+
railties (>= 3.0)
|
113
|
+
rspec-core (~> 2.13.0)
|
114
|
+
rspec-expectations (~> 2.13.0)
|
115
|
+
rspec-mocks (~> 2.13.0)
|
116
|
+
slop (3.4.5)
|
117
|
+
sprockets (2.2.2)
|
118
|
+
hike (~> 1.2)
|
119
|
+
multi_json (~> 1.0)
|
120
|
+
rack (~> 1.0)
|
121
|
+
tilt (~> 1.1, != 1.3.0)
|
122
|
+
sqlite3 (1.3.7)
|
123
|
+
thor (0.18.1)
|
124
|
+
tilt (1.4.1)
|
125
|
+
treetop (1.4.12)
|
126
|
+
polyglot
|
127
|
+
polyglot (>= 0.3.1)
|
128
|
+
tzinfo (0.3.37)
|
129
|
+
|
130
|
+
PLATFORMS
|
131
|
+
ruby
|
132
|
+
|
133
|
+
DEPENDENCIES
|
134
|
+
growl
|
135
|
+
guard
|
136
|
+
guard-rspec
|
137
|
+
rspec-rails
|
138
|
+
rubykassa!
|
139
|
+
sqlite3
|
data/Guardfile
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2013 YOURNAME
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
## The Rubykassa gem
|
2
|
+
|
3
|
+
[![Build Status](https://secure.travis-ci.org/ZeroOneStudio/rubykassa.png)](http://travis-ci.org/ZeroOneStudio/rubykassa)
|
4
|
+
|
5
|
+
by [Zero One][]
|
6
|
+
|
7
|
+
[Zero One]: http://zeroone.st
|
8
|
+
|
9
|
+
Yet another Ruby wrapper for Robokassa API. Took the best from [robokassa gem][] and [Active Merchant Robokassa integration] but easier to use and setup.
|
10
|
+
|
11
|
+
[robokassa gem]: https://github.com/shaggyone/robokassa
|
12
|
+
[Active Merchant Robokassa integration]: https://github.com/Shopify/active_merchant/tree/master/lib/active_merchant/billing/integrations/robokassa
|
13
|
+
|
14
|
+
## Installation
|
15
|
+
|
16
|
+
gem install rubykassa
|
17
|
+
|
18
|
+
Or put to your `Gemfile`
|
19
|
+
|
20
|
+
gem "rubykassa"
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
## License
|
25
|
+
|
26
|
+
This project rocks and uses MIT-LICENSE.
|
data/Rakefile
ADDED
File without changes
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
class RobokassaController < ApplicationController
|
3
|
+
before_filter :create_notification, except: :fail
|
4
|
+
|
5
|
+
def paid
|
6
|
+
if @notification.valid_response_signature?
|
7
|
+
render text: @notification.success
|
8
|
+
else
|
9
|
+
render text: "fail"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def success
|
14
|
+
if @notification.valid_success_signature?
|
15
|
+
render text: "success"
|
16
|
+
else
|
17
|
+
render text: "fail"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def fail
|
22
|
+
render text: "fail"
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def create_notification
|
28
|
+
@notification = Rubykassa::Notification.new params
|
29
|
+
end
|
30
|
+
end
|
data/config/routes.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
module Rubykassa
|
3
|
+
module ActionViewExtension
|
4
|
+
def link_to_pay phrase, invoice_id, total, options = {}
|
5
|
+
phrase ||= "Pay"
|
6
|
+
total, invoice_id = total.to_s, invoice_id.to_s
|
7
|
+
link_to phrase, Rubykassa.pay_url(invoice_id, total, params, options)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'rubykassa/configuration'
|
3
|
+
|
4
|
+
module Rubykassa
|
5
|
+
class ConfigurationError < StandardError; end
|
6
|
+
|
7
|
+
class Client
|
8
|
+
class << self
|
9
|
+
attr_accessor :configuration
|
10
|
+
|
11
|
+
def configure
|
12
|
+
self.configuration = Rubykassa::Configuration.new
|
13
|
+
yield self.configuration
|
14
|
+
|
15
|
+
raise ConfigurationError, "Alailable modes are :test or :production" unless [:test, :production].include? self.configuration.mode
|
16
|
+
raise ConfigurationError, "Alailable http methods are :get or :post" unless [:get, :post].include? self.configuration.http_method
|
17
|
+
raise ConfigurationError, "Alailable xml http methods are :get or :post" unless [:get, :post].include? self.configuration.xml_http_method
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
module Rubykassa
|
3
|
+
class Configuration
|
4
|
+
attr_accessor :login, :first_password, :second_password, :mode, :http_method, :xml_http_method
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
self.login = "your_login"
|
8
|
+
self.first_password = "first_password"
|
9
|
+
self.second_password = "second_password"
|
10
|
+
self.mode = :test
|
11
|
+
self.http_method = :get
|
12
|
+
self.xml_http_method = :get
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'rubykassa/signature_generator'
|
3
|
+
|
4
|
+
module Rubykassa
|
5
|
+
class Notification
|
6
|
+
include SignatureGenerator
|
7
|
+
|
8
|
+
attr_accessor :params
|
9
|
+
|
10
|
+
def initialize params
|
11
|
+
@params = params
|
12
|
+
@invoice_id = params["InvId"]
|
13
|
+
@total = params["OutSum"]
|
14
|
+
end
|
15
|
+
|
16
|
+
%w(result success).map do |kind|
|
17
|
+
define_method "valid_#{kind}_signature?" do
|
18
|
+
@params["SignatureValue"] == generate_signature_for(kind.to_sym)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def success
|
23
|
+
"OK#{@invoice_id}"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'rubykassa/signature_generator'
|
3
|
+
|
4
|
+
module Rubykassa
|
5
|
+
class PaymentInterface
|
6
|
+
include SignatureGenerator
|
7
|
+
|
8
|
+
PARAMS_CONFORMITY = {
|
9
|
+
login: "MrchLogin",
|
10
|
+
total: "OutSum",
|
11
|
+
invoice_id: "InvId",
|
12
|
+
signature: "SignatureValue",
|
13
|
+
email: "Email",
|
14
|
+
currency: "IncCurrLabel",
|
15
|
+
description: "InvDesc",
|
16
|
+
culture: "Culture"
|
17
|
+
}
|
18
|
+
|
19
|
+
attr_accessor :invoice_id, :total, :params
|
20
|
+
|
21
|
+
def initialize &block
|
22
|
+
instance_eval &block if block_given?
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_mode?
|
26
|
+
Rubykassa.mode == :test
|
27
|
+
end
|
28
|
+
|
29
|
+
def base_url
|
30
|
+
test_mode? ? "http://test.robokassa.ru/Index.aspx" : "https://merchant.roboxchange.com/Index.aspx"
|
31
|
+
end
|
32
|
+
|
33
|
+
def pay_url(options = {})
|
34
|
+
options = options.slice(:currency, :description, :email, :culture)
|
35
|
+
|
36
|
+
"#{base_url}?" + initial_options.merge(options).map do |key, value|
|
37
|
+
"#{PARAMS_CONFORMITY[key.to_sym]}=#{value}" unless key =~ /^shp/
|
38
|
+
end.compact!.join("&")
|
39
|
+
end
|
40
|
+
|
41
|
+
def initial_options
|
42
|
+
{
|
43
|
+
login: Rubykassa.login,
|
44
|
+
total: @total,
|
45
|
+
invoice_id: @invoice_id,
|
46
|
+
signature: generate_signature_for(:payment)
|
47
|
+
}.merge(Hash[@params.sort.map {|param_name| ["shp#{param_name[0]}".to_sym, param_name[1]]}])
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
module Rubykassa
|
3
|
+
module SignatureGenerator
|
4
|
+
def generate_signature_for kind
|
5
|
+
raise ArgumentError, "Available kinds are only :payment, :result or :success" if ![:success, :payment, :result].include? kind
|
6
|
+
custom_param_keys = @params.keys.select {|key| key =~ /^shp/ }.sort
|
7
|
+
custom_params = custom_param_keys.map {|key| "#{key}=#{params[key]}"}
|
8
|
+
custom_params_string = custom_params.present? ? ":#{custom_params}" : ""
|
9
|
+
|
10
|
+
if kind == :payment
|
11
|
+
string = [Rubykassa.login, @total, @invoice_id, Rubykassa.first_password].join(":") + custom_params_string
|
12
|
+
elsif kind == :result
|
13
|
+
string = [@total, @invoice_id, Rubykassa.second_password].join(":") + custom_params_string
|
14
|
+
elsif kind == :success
|
15
|
+
string = [@total, @invoice_id, Rubykassa.first_password].join(":") + custom_params_string
|
16
|
+
end
|
17
|
+
|
18
|
+
signature = Digest::MD5.hexdigest(string)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'net/http'
|
3
|
+
require 'multi_xml'
|
4
|
+
require 'uri'
|
5
|
+
|
6
|
+
module Rubykassa
|
7
|
+
class InvalidResponseError < StandardError; end
|
8
|
+
|
9
|
+
class XmlInterface
|
10
|
+
attr_accessor :invoice_id, :total, :language
|
11
|
+
|
12
|
+
def initialize &block
|
13
|
+
instance_eval &block if block_given?
|
14
|
+
end
|
15
|
+
|
16
|
+
def get_currencies
|
17
|
+
request(base_url + transform_method_name(__method__), Hash["MerchantLogin", Rubykassa.login, "Language", @language])
|
18
|
+
end
|
19
|
+
|
20
|
+
def get_payment_methods
|
21
|
+
request(base_url + transform_method_name(__method__), Hash["MerchantLogin", Rubykassa.login, "Language", @language])
|
22
|
+
end
|
23
|
+
|
24
|
+
def get_rates
|
25
|
+
request(base_url + transform_method_name(__method__), Hash["MerchantLogin", Rubykassa.login, "IncCurrLabel", "", "OutSum", @total.to_s, "Language", @language])
|
26
|
+
end
|
27
|
+
|
28
|
+
def op_state
|
29
|
+
request(base_url + transform_method_name(__method__), Hash["MerchantLogin", Rubykassa.login, "InvoiceID", @invoice_id.to_s, "Signature", generate_signature])
|
30
|
+
end
|
31
|
+
|
32
|
+
def base_url
|
33
|
+
"https://merchant.roboxchange.com/WebService/Service.asmx/"
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def generate_signature
|
39
|
+
Digest::MD5.hexdigest("#{Rubykassa.login}:#{@invoice_id}:#{Rubykassa.second_password}")
|
40
|
+
end
|
41
|
+
|
42
|
+
def transform_method_name meth
|
43
|
+
meth.to_s.split('_').map(&:capitalize).join(' ').gsub(/\s/, "")
|
44
|
+
end
|
45
|
+
|
46
|
+
def request url, params
|
47
|
+
if Rubykassa.xml_http_method == :get
|
48
|
+
converted_params = "?" + params.map {|key, value| "#{key}=#{value}" }.join("&")
|
49
|
+
response = Net::HTTP.get_response(URI(url) + converted_params)
|
50
|
+
else
|
51
|
+
response = Net::HTTP.post_form(URI(url), params)
|
52
|
+
end
|
53
|
+
raise InvalidResponseError, "Invalid response from the service" unless response.code == "200"
|
54
|
+
MultiXml.parse(response.body)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
data/lib/rubykassa.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require "rubykassa/engine"
|
3
|
+
require 'rubykassa/client'
|
4
|
+
require 'rubykassa/payment_interface'
|
5
|
+
require 'rubykassa/xml_interface'
|
6
|
+
require 'rubykassa/notification'
|
7
|
+
|
8
|
+
module Rubykassa
|
9
|
+
extend self
|
10
|
+
|
11
|
+
def configure &block
|
12
|
+
Rubykassa::Client.configure &block
|
13
|
+
end
|
14
|
+
|
15
|
+
%w(login first_password second_password mode http_method xml_http_method).map do |name|
|
16
|
+
define_method name do
|
17
|
+
Rubykassa::Client.configuration.send(name)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def pay_url invoice_id, total, params, options = {}
|
22
|
+
Rubykassa::PaymentInterface.new do
|
23
|
+
self.total = total
|
24
|
+
self.invoice_id = invoice_id
|
25
|
+
self.params = params
|
26
|
+
end.pay_url(options)
|
27
|
+
end
|
28
|
+
end
|
data/rubykassa.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
$:.push File.expand_path("../lib", __FILE__)
|
2
|
+
|
3
|
+
# Maintain your gem's version:
|
4
|
+
require "rubykassa/version"
|
5
|
+
|
6
|
+
# Describe your gem and declare its dependencies:
|
7
|
+
Gem::Specification.new do |s|
|
8
|
+
s.name = "rubykassa"
|
9
|
+
s.version = Rubykassa::VERSION
|
10
|
+
s.authors = ["Sergey Kishenin"]
|
11
|
+
s.email = ["sergey.kishenin@gmail.com"]
|
12
|
+
s.homepage = "http://github.com/ZeroOneStudio/rubykassa"
|
13
|
+
s.summary = "Yet another Ruby wrapper for Robokassa API"
|
14
|
+
s.description = "Yet another Ruby wrapper for Robokassa API aimed to make Robokassa integration even more easier"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- spec/rubykassa/*`.split("\n")
|
18
|
+
|
19
|
+
s.add_dependency "rails", "~> 3.2.13"
|
20
|
+
s.add_dependency "multi_xml"
|
21
|
+
|
22
|
+
s.add_development_dependency "sqlite3"
|
23
|
+
s.add_development_dependency "rspec-rails"
|
24
|
+
s.add_development_dependency "growl"
|
25
|
+
s.add_development_dependency "guard"
|
26
|
+
s.add_development_dependency "guard-rspec"
|
27
|
+
end
|
data/script/rails
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
|
3
|
+
|
4
|
+
ENGINE_ROOT = File.expand_path('../..', __FILE__)
|
5
|
+
ENGINE_PATH = File.expand_path('../../lib/rubykassa/engine', __FILE__)
|
6
|
+
|
7
|
+
require 'rails/all'
|
8
|
+
require 'rails/engine/commands'
|