yandex_kassa 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +42 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/yandex_kassa/api.rb +25 -0
- data/lib/yandex_kassa/configuration.rb +5 -0
- data/lib/yandex_kassa/requests.rb +77 -0
- data/lib/yandex_kassa/signed_response_parser.rb +21 -0
- data/lib/yandex_kassa/version.rb +3 -0
- data/lib/yandex_kassa.rb +42 -0
- data/yandex_kassa.gemspec +27 -0
- metadata +115 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ec7934098a374532ddbe58b7fbdf7b9f308b91f9
|
4
|
+
data.tar.gz: 65eb771c1764b53cc37726a4c8134313a58958ce
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 862e467f720fc383b502d8a7f3064003a3a8f76dc099efd75af1633dd62fb1be890278653783762a13c5050127e40ceb185e9d8e90e39e4691ea87b2d943cea9
|
7
|
+
data.tar.gz: 5173acff1a844f74328469dbc65a64a0866a79d81cb4b72dab33c6702a91a1eeed0b44abcc3668c7fc4395a26f9c143a382e9aad82ce3071ce50476b766de2e9
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Evgeniy Burdaev
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
[![Code Climate](https://codeclimate.com/github/creepycheese/yandex-kassa-api/badges/gpa.svg)](https://codeclimate.com/github/creepycheese/yandex-kassa-api)
|
2
|
+
# YandexKassa
|
3
|
+
|
4
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/yandex_kassa`. To experiment with that code, run `bin/console` for an interactive prompt.
|
5
|
+
|
6
|
+
TODO: Delete this and the text above, and describe your gem
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem 'yandex_kassa'
|
14
|
+
```
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
$ gem install yandex_kassa
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
TODO: Write usage instructions here
|
27
|
+
|
28
|
+
## Development
|
29
|
+
|
30
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
31
|
+
|
32
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
33
|
+
|
34
|
+
## Contributing
|
35
|
+
|
36
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/yandex_kassa. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
37
|
+
|
38
|
+
|
39
|
+
## License
|
40
|
+
|
41
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
42
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "yandex_kassa"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
module YandexKassa
|
2
|
+
class Api
|
3
|
+
include Requests
|
4
|
+
|
5
|
+
def initialize(params = {})
|
6
|
+
@response_parser = params.fetch(:response_parser)
|
7
|
+
@url = params.fetch(:url)
|
8
|
+
@cert_file = params.fetch(:cert_file)
|
9
|
+
@key_file = params.fetch(:key_file)
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
attr_reader :cert_file, :key_file, :url, :response_parser
|
15
|
+
|
16
|
+
def client
|
17
|
+
@client ||= RestClient::Resource.new(
|
18
|
+
url,
|
19
|
+
ssl_client_cert: cert_file,
|
20
|
+
ssl_client_key: key_file,
|
21
|
+
verify_ssl: OpenSSL::SSL::VERIFY_NONE,
|
22
|
+
headers: { content_type: 'application/pkcs7-mime', content_lenght: '512' })
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
module YandexKassa
|
2
|
+
module Requests
|
3
|
+
def test_deposition(params = {}, &block)
|
4
|
+
test_deposition_request = Requests::TestDeposition.new(params, &block)
|
5
|
+
post_request(test_deposition_request)
|
6
|
+
end
|
7
|
+
|
8
|
+
def make_deposition(params = {}, &block)
|
9
|
+
make_deposition_request = Requests::MakeDeposition.new(params, &block)
|
10
|
+
post_request(make_deposition_request)
|
11
|
+
end
|
12
|
+
|
13
|
+
def post_request(xml_request)
|
14
|
+
response = client[xml_request.request_path].post(xml_request.xml_request_body)
|
15
|
+
response_parser.parse(response)
|
16
|
+
end
|
17
|
+
|
18
|
+
class Deposition
|
19
|
+
|
20
|
+
attr_accessor :agent_id, :client_order_id, :request_dt, :dst_account, :amount, :currency, :contract
|
21
|
+
|
22
|
+
def initialize(params = {}, &block)
|
23
|
+
params.each { |method, value| instance_variable_set("@#{method}", value) }
|
24
|
+
block.call(self) if block_given?
|
25
|
+
end
|
26
|
+
|
27
|
+
def request_name; end
|
28
|
+
|
29
|
+
def resource_path; end
|
30
|
+
|
31
|
+
def extra_params; end
|
32
|
+
|
33
|
+
def xml_request_body
|
34
|
+
<<XML
|
35
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
36
|
+
<#{request_name} agentId="#{agent_id}"
|
37
|
+
clientOrderId="#{client_order_id}"
|
38
|
+
requestDT="#{request_dt}"
|
39
|
+
dstAccount="#{dst_account}"
|
40
|
+
amount="#{amount}"
|
41
|
+
currency="#{currency}"
|
42
|
+
contract="#{contract}"/>#{extra_params}
|
43
|
+
</#{request_name}>
|
44
|
+
XML
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
class TestDeposition < Deposition
|
49
|
+
def request_name
|
50
|
+
'testDepositionRequest'
|
51
|
+
end
|
52
|
+
|
53
|
+
def request_path
|
54
|
+
'testDeposition'
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
class MakeDeposition < Deposition
|
59
|
+
def request_name
|
60
|
+
'makeDepositionRequest'
|
61
|
+
end
|
62
|
+
|
63
|
+
def request_path
|
64
|
+
'makeDeposition'
|
65
|
+
end
|
66
|
+
|
67
|
+
def extra_params
|
68
|
+
@payment_params
|
69
|
+
end
|
70
|
+
|
71
|
+
def set_payment_params(params={})
|
72
|
+
params = params.inject("") { |str, hash| str += "<#{hash[0]}>#{hash[1]}</#{hash[0]}>\n"}
|
73
|
+
@payment_params = "\n<paymentParams>\n#{params}</paymentParams>"
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module YandexKassa
|
2
|
+
class SignedResponseParser
|
3
|
+
def initialize(params = {})
|
4
|
+
cert_file = params.fetch(:cert_file)
|
5
|
+
@cert_store = OpenSSL::X509::Store.new
|
6
|
+
@cert_store.add_cert(cert_file)
|
7
|
+
|
8
|
+
@deposit_cert_file = params.fetch(:deposit_cert_file)
|
9
|
+
end
|
10
|
+
|
11
|
+
def parse(data)
|
12
|
+
signature = OpenSSL::PKCS7.new(data)
|
13
|
+
signature.verify([deposit_cert_file], cert_store, nil, OpenSSL::PKCS7::NOVERIFY)
|
14
|
+
signature.data
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
attr_reader :cert_store, :deposit_cert_file
|
20
|
+
end
|
21
|
+
end
|
data/lib/yandex_kassa.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
require "yandex_kassa/version"
|
2
|
+
require "yandex_kassa/configuration"
|
3
|
+
require "yandex_kassa/requests"
|
4
|
+
require "yandex_kassa/api"
|
5
|
+
require "yandex_kassa/signed_response_parser"
|
6
|
+
require "openssl"
|
7
|
+
require "rest-client"
|
8
|
+
|
9
|
+
module YandexKassa
|
10
|
+
class << self
|
11
|
+
|
12
|
+
def create
|
13
|
+
Api.new(url: configuration.url, cert_file: cert_file,
|
14
|
+
key_file: key_file, response_parser: pkcs7_response_parser)
|
15
|
+
end
|
16
|
+
|
17
|
+
def configure(&block)
|
18
|
+
block.call(configuration)
|
19
|
+
end
|
20
|
+
|
21
|
+
def pkcs7_response_parser
|
22
|
+
@pkcs7_response_parser ||= SignedResponseParser.new(deposit_cert_file: deposit_cert_file,
|
23
|
+
cert_file: cert_file)
|
24
|
+
end
|
25
|
+
|
26
|
+
def configuration
|
27
|
+
@configuration ||= Configuration.new
|
28
|
+
end
|
29
|
+
|
30
|
+
def cert_file
|
31
|
+
@cert_file ||= OpenSSL::X509::Certificate.new(File.read(configuration.cert))
|
32
|
+
end
|
33
|
+
|
34
|
+
def key_file
|
35
|
+
@key_file ||= OpenSSL::PKey::RSA.new(File.read(configuration.key), configuration.passphrase)
|
36
|
+
end
|
37
|
+
|
38
|
+
def deposit_cert_file
|
39
|
+
@depostit_cert_file ||= OpenSSL::X509::Certificate.new(File.read(configuration.deposit))
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'yandex_kassa/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "yandex_kassa"
|
8
|
+
spec.version = YandexKassa::VERSION
|
9
|
+
spec.authors = ["Evgeniy Burdaev"]
|
10
|
+
spec.email = ["inqify@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Interaction with Yandex Kassa for Mass depositions}
|
13
|
+
spec.description = %q{Yandex Kassa API}
|
14
|
+
spec.homepage = "https://www.github.com/creepycheese/yandex-kassa-api"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
spec.add_development_dependency "minitest"
|
25
|
+
|
26
|
+
spec.add_runtime_dependency "rest-client"
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: yandex_kassa
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Evgeniy Burdaev
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-03-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rest-client
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Yandex Kassa API
|
70
|
+
email:
|
71
|
+
- inqify@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- .gitignore
|
77
|
+
- .travis.yml
|
78
|
+
- Gemfile
|
79
|
+
- LICENSE.txt
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- bin/console
|
83
|
+
- bin/setup
|
84
|
+
- lib/yandex_kassa.rb
|
85
|
+
- lib/yandex_kassa/api.rb
|
86
|
+
- lib/yandex_kassa/configuration.rb
|
87
|
+
- lib/yandex_kassa/requests.rb
|
88
|
+
- lib/yandex_kassa/signed_response_parser.rb
|
89
|
+
- lib/yandex_kassa/version.rb
|
90
|
+
- yandex_kassa.gemspec
|
91
|
+
homepage: https://www.github.com/creepycheese/yandex-kassa-api
|
92
|
+
licenses:
|
93
|
+
- MIT
|
94
|
+
metadata: {}
|
95
|
+
post_install_message:
|
96
|
+
rdoc_options: []
|
97
|
+
require_paths:
|
98
|
+
- lib
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - '>='
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
requirements: []
|
110
|
+
rubyforge_project:
|
111
|
+
rubygems_version: 2.4.8
|
112
|
+
signing_key:
|
113
|
+
specification_version: 4
|
114
|
+
summary: Interaction with Yandex Kassa for Mass depositions
|
115
|
+
test_files: []
|