yandex-kassa 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 54f965c93b9897c9f6d4ce9b82541396285f55d8
4
+ data.tar.gz: f67e69187ac3e219d2920a56a1058ecadb2c3c89
5
+ SHA512:
6
+ metadata.gz: e06cfb9c269703815a6729571dc8554ffc66f2a0b1df597597dec71cca04d5a948402937f4e735288e3992a8d3f2cdb706e24ce5d4f3862f36c658520e6507a0
7
+ data.tar.gz: bd495526dcc4f9044bf8603beb47211040f209b50893d01557792bba3376aa0bfaa9dbb05168677289ae86ad54e2b5db31b83e2fafaf133a2375d16ccb0a632e
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /.idea/
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in yandex-kassa.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Sergey Odintsov
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.
@@ -0,0 +1,43 @@
1
+ # YandexKassa
2
+
3
+ ## Installation
4
+
5
+ Add this line to your application's Gemfile:
6
+
7
+ ```ruby
8
+ gem 'yandex-kassa'
9
+ ```
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install yandex-kassa
18
+
19
+ ## Usage
20
+
21
+ require 'yandex_kassa'
22
+
23
+ # Initialize
24
+ yandex_kassa = YandexKassa::Deposition.new('demo.yamoney.ru:9094', "my.cer", "private.key", "deposit.cer")
25
+
26
+ request_params = {
27
+ dstAccount: '410039303350',
28
+ clientOrderId: 123,
29
+ amount: amount,
30
+ currency: 10643,
31
+ agentId: 234,
32
+ contract: 'payment_event'
33
+ }
34
+
35
+ # Test request
36
+ response = yandex_kassa.test_deposition(request_params)
37
+
38
+ # Make deposition
39
+ response = yandex_kassa.make_deposition(request_params)
40
+
41
+ # Requests with paymentParams
42
+ response = yandex_kassa.make_deposition(request_params, {pof_offerAccepted: 1, smsPhoneNumber: 79653457676})
43
+
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,150 @@
1
+ require 'yandex_kassa/version'
2
+
3
+ # Yandex.Kassa deposition sdk
4
+ module YandexKassa
5
+ class Deposition
6
+ include OpenSSL
7
+
8
+ attr_accessor :agent_id
9
+
10
+ # Create a new instance
11
+ #
12
+ #=== Parameters
13
+ # * +host+ - string Only Host and Port
14
+ # * +cert+ - string
15
+ # * +private_key+ - string
16
+ # * +deposit_cert+ - string
17
+ #
18
+ # yandex_kassa = YandexKassa.new('host:port', 'adp.cer', 'private.key', 'deposit.cer')
19
+ #
20
+ def initialize(host, cert, private_key, deposit_cert)
21
+ @prefix = "https://#{host}/webservice/deposition/api/"
22
+ @cert = X509::Certificate.new(File.read(cert))
23
+ @private_key = PKey::RSA.new(File.read(private_key))
24
+ @deposit_cert = X509::Certificate.new(File.read(deposit_cert))
25
+ end
26
+
27
+ # Test Deposition
28
+ # @link https://tech.yandex.ru/money/doc/payment-solution/payout/payments-docpage/
29
+ # response = yandex_kassa.test_deposition({
30
+ # dstAccount: '123455',
31
+ # clientOrderId: 123,
32
+ # amount: 100.0,
33
+ # currency: 10643,
34
+ # agentId: 234,
35
+ # contract: 'test'
36
+ # })
37
+ def test_deposition(params, payment_params = {})
38
+ request('testDeposition', params, payment_params)
39
+ end
40
+
41
+ # Make Deposition
42
+ # @link https://tech.yandex.ru/money/doc/payment-solution/payout/payments-docpage/
43
+ # response = yandex_kassa.make_deposition({
44
+ # dstAccount: '123455',
45
+ # clientOrderId: 123,
46
+ # amount: 100.0,
47
+ # currency: 10643,
48
+ # agentId: 234,
49
+ # contract: 'test'
50
+ # })
51
+ def make_deposition(params, payment_params = {})
52
+ request('makeDeposition', params, payment_params)
53
+ end
54
+
55
+ # Get account balance
56
+ # @link https://tech.yandex.ru/money/doc/payment-solution/payout/balance-request-docpage/
57
+ # response = yandex_kassa.balance({
58
+ # clientOrderId: 123,
59
+ # agentId: 234,
60
+ # })
61
+ def balance(params)
62
+ request('balance', params)
63
+ end
64
+
65
+ private
66
+
67
+ # Request with params
68
+ #
69
+ # response = yandex_kassa.request('testDeposition', {
70
+ # dstAccount: '123455',
71
+ # clientOrderId: 123,
72
+ # amount: 100.0,
73
+ # currency: 10643,
74
+ # agentId: 234,
75
+ # contract: 'test'
76
+ # })
77
+ def request(method, params, payment_params = {})
78
+
79
+ # Add params
80
+ default_params = {
81
+ requestDT: Time.now.iso8601,
82
+ agentId: agent_id,
83
+ }
84
+ params = params.reverse_merge(default_params)
85
+
86
+ #Setup http request
87
+ uri = URI.parse(@prefix + method)
88
+ http = Net::HTTP.new(uri.host, uri.port)
89
+ http.open_timeout = 4
90
+ http.read_timeout = 5
91
+ http.use_ssl = true
92
+ http.cert = @cert
93
+ http.key = @private_key
94
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
95
+
96
+ # Request initialize
97
+ request = Net::HTTP::Post.new(uri.path)
98
+ request.body = sign_data(xml_header(method, params, payment_params))
99
+ request.content_type = 'application/pkcs7-mime'
100
+
101
+ # Make request
102
+ response = http.request(request)
103
+
104
+ # Parsing
105
+ parse_response(method, response.body)
106
+ end
107
+
108
+ # Sign +data+ with certificate
109
+ #
110
+ #=== Parameters
111
+ # * +data+ - string
112
+ #
113
+ # signed_data = yandex_kassa.sign_data('xml string')
114
+ #
115
+ def sign_data(data)
116
+ OpenSSL::PKCS7::sign(@cert, @private_key, data, [], PKCS7::NOCERTS).to_pem
117
+ end
118
+
119
+ def xml_header(method, params, payment_params = {})
120
+ xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><#{method}Request "
121
+ xml += (params.map {|m| "#{m[0]}=\"#{m[1]}\""}.join(' '))
122
+ if payment_params.present?
123
+ xml += '>'
124
+ xml += payment_params.to_xml(root: 'paymentParams', skip_instruct: true, skip_types: true, dasherize: false)
125
+ xml += "</#{method}Request>"
126
+ else
127
+ xml += '/>'
128
+ end
129
+ xml
130
+ end
131
+
132
+ # Response parsing
133
+ def parse_response(method, data)
134
+
135
+ # Initialize store cert
136
+ cert_store = OpenSSL::X509::Store.new
137
+ cert_store.add_cert(@cert)
138
+
139
+ # Parse response
140
+ signature = OpenSSL::PKCS7.new(data)
141
+
142
+ # Decrypt data
143
+ signature.verify([@deposit_cert], cert_store, nil, OpenSSL::PKCS7::NOVERIFY)
144
+
145
+ # Parse xml
146
+ hash = Hash.from_xml(signature.data)
147
+ hash["#{method}Response"]
148
+ end
149
+ end
150
+ end
@@ -0,0 +1,3 @@
1
+ module YandexKassa
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,24 @@
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 = ["Sergey Odintsov"]
10
+ spec.email = ["nixx.dj@gmail.com"]
11
+
12
+ spec.summary = %q{Yandex.Kassa Rails}
13
+ spec.description = %q{Реализация протокола автоматизации массовых выплат}
14
+ spec.homepage = "https://github.com/PNixx/yandex-kassa"
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.9"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yandex-kassa
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Sergey Odintsov
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-12-03 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.9'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.9'
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
+ description: "Реализация протокола автоматизации массовых выплат"
42
+ email:
43
+ - nixx.dj@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - ".travis.yml"
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - lib/yandex_kassa.rb
55
+ - lib/yandex_kassa/version.rb
56
+ - yandex-kassa.gemspec
57
+ homepage: https://github.com/PNixx/yandex-kassa
58
+ licenses:
59
+ - MIT
60
+ metadata: {}
61
+ post_install_message:
62
+ rdoc_options: []
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ requirements: []
76
+ rubyforge_project:
77
+ rubygems_version: 2.4.5
78
+ signing_key:
79
+ specification_version: 4
80
+ summary: Yandex.Kassa Rails
81
+ test_files: []
82
+ has_rdoc: