tinkoff 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7747a86f38e397679c217ba2636d8618ff425ba8
4
+ data.tar.gz: d3b2bfb1ce43efb4488584b23599c0b9dfd4148e
5
+ SHA512:
6
+ metadata.gz: f768be623f7e5efbbf3c83e65d0928dd53d60e39155777588864c618b6480f1b84e111a09b97866d8c9414bed29ad203d775171ddba79fa785d4dc98e5578cfc
7
+ data.tar.gz: 34a5da792044f3bf47b4be7c9bf11b8a9b89bf2a832e0ddc19b916f2cd23cb50a1ba1e8c42415dd3322740b92d492ceeb6bd1720dabfc1a587f1a217c841fc73
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ *.gem
12
+ .byebug_history
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.12.5
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at itsdanya@gmail.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in tinkoff.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Dan Kim
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,66 @@
1
+ # Tinkoff
2
+
3
+ This is a Ruby wrapper for Tinkoff Acquiring API. The API of this gem is not final and may change significantly before the 1.0 release.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'tinkoff'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install tinkoff
20
+
21
+ ## Usage
22
+
23
+ Configure the gem with the credentials provided by the bank. If you are using Ruby on Rails, you should do that in an initializer.
24
+
25
+ ```ruby
26
+ # config/initializers/tinkoff.rb
27
+ Tinkoff.configure do |config|
28
+ config.terminal_key = 'TerminalKey'
29
+ config.password = 'Password'
30
+ end
31
+ ```
32
+
33
+ Use the client to work with payments.
34
+
35
+ ```ruby
36
+ # Parameters: amount (in kopecks), order_id, data, options (hash, optional)
37
+ # data — a hash of arbitrary data (up to 20 pairs), "Email" key is required
38
+ # More info: https://oplata.tinkoff.ru/documentation/?section=Init
39
+ Tinkoff::Client.init(100, 1, { Email: 'foo@bar.com' })
40
+
41
+ # Parameters: payment_id, options (hash, optional)
42
+ Tinkoff::Client.confirm(1)
43
+
44
+ # Parameters: payment_id, rebill_id, options (hash, optional)
45
+ Tinkoff::Client.charge(1, 2)
46
+
47
+ # Parameters: payment_id, options (hash, optional)
48
+ Tinkoff::Client.cancel(1)
49
+
50
+ # Parameters: payment_id, options (hash, optional)
51
+ Tinkoff::Client.state(1)
52
+ ```
53
+
54
+ You can view all available options in the [official documentation](https://oplata.tinkoff.ru/documentation/?section=aboutMet).
55
+
56
+ ## Development
57
+
58
+ 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. To install this gem onto your local machine, run `bundle exec rake install`.
59
+
60
+ ## Contributing
61
+
62
+ Bug reports and pull requests are welcome on GitHub at https://github.com/dankimio/tinkoff. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
63
+
64
+ ## License
65
+
66
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << 'test'
6
+ t.libs << 'lib'
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task default: :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'tinkoff'
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,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,41 @@
1
+ module Tinkoff
2
+ class Client
3
+ # Инициирует платежную сессию и регистрирует заказ в системе Банка
4
+ def self.init(amount, order_id, data, params = {})
5
+ params = params.merge(Amount: amount, OrderId: order_id, DATA: data)
6
+ Tinkoff::Request.new('Init', params).perform
7
+ end
8
+
9
+ # Данный метод используется, если продавец обладает сертификацией PCI DSS
10
+ # и использует свою собственную платежную форму вместо формы банка.
11
+ # TODO: Implement
12
+ def self.finish_authorize(params = {})
13
+ Tinkoff::Request.new('FinishAuthorize', params).perform
14
+ end
15
+
16
+ # Подтверждает платеж и осуществляет списание заблокированных ранее денежных средств
17
+ def self.confirm(payment_id, params = {})
18
+ params = params.merge(PaymentId: payment_id)
19
+ Tinkoff::Request.new('Confirm', params).perform
20
+ end
21
+
22
+ # Осуществляет рекуррентный (повторный) платеж — безакцептное списание денежных средств
23
+ # со счета банковской карты Покупателя
24
+ def self.charge(payment_id, rebill_id, params = {})
25
+ params = params.merge(PaymentId: payment_id, RebillId: rebill_id)
26
+ Tinkoff::Request.new('Charge', params).perform
27
+ end
28
+
29
+ # Отменяет платежную сессию
30
+ def self.cancel(payment_id, params = {})
31
+ params = params.merge(PaymentId: payment_id)
32
+ Tinkoff::Request.new('Cancel', params).perform
33
+ end
34
+
35
+ # Возвращает текуший статус платежа
36
+ def self.state(payment_id, params = {})
37
+ params = params.merge(PaymentId: payment_id)
38
+ Tinkoff::Request.new('GetState', params).perform
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,26 @@
1
+ module Tinkoff
2
+ class Payment
3
+ attr_reader :terminal_key, :amount, :order_id, :success, :status,
4
+ :payment_id, :error_code, :payment_url, :message, :details
5
+
6
+ # Attributes for Cancel method
7
+ attr_reader :original_amount, :new_amount
8
+
9
+ def initialize(response)
10
+ @terminal_key = response['TerminalKey']
11
+ @amount = response['Amount']
12
+ @order_id = response['OrderId']
13
+ @success = response['Success']
14
+ @status = response['Status']
15
+ @payment_id = response['PaymentId']
16
+ @error_code = response['ErrorCode']
17
+ @payment_url = response['PaymentURL']
18
+ @message = response['Message']
19
+ @details = response['Details']
20
+
21
+ # Attributes for Cancel method
22
+ @original_amount = response['OriginalAmount']
23
+ @new_amount = response['NewAmount']
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,48 @@
1
+ module Tinkoff
2
+ class Request
3
+ BASE_URL = 'https://securepay.tinkoff.ru/rest/'
4
+
5
+ def initialize(path, params = {})
6
+ @url = BASE_URL + path
7
+ @params = params
8
+ end
9
+
10
+ def perform
11
+ prepare_params
12
+ response = HTTParty.post(@url, body: @params, format: :json).parsed_response
13
+ Tinkoff::Payment.new(response)
14
+ end
15
+
16
+ private
17
+
18
+ def prepare_params
19
+ # Encode and join DATA hash
20
+ prepare_data
21
+ # Add terminal key and password
22
+ @params.merge!(default_params)
23
+ # Sort params by key
24
+ @params = @params.sort.to_h
25
+ # Add token (signature)
26
+ @params[:Token] = token
27
+ end
28
+
29
+ # Params signature
30
+ def token
31
+ values = @params.values.join
32
+ Digest::SHA256.digest(values)
33
+ end
34
+
35
+ def default_params
36
+ {
37
+ TerminalKey: Tinkoff.config.terminal_key,
38
+ Password: Tinkoff.config.password
39
+ }
40
+ end
41
+
42
+ # Ключ=значение дополнительных параметров через “|”, например Email=a@test.ru|Phone=+71234567890
43
+ def prepare_data
44
+ return unless @params[:DATA].present?
45
+ @params[:DATA] = @params[:DATA].to_query.tr('&', '|')
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,19 @@
1
+ module Tinkoff
2
+ class Response
3
+ attr_reader :success, :error_code, :message, :details, :amount,
4
+ :merchant_email, :merchant_name, :order_id, :payment_id, :tran_date
5
+
6
+ def initialize(params)
7
+ @success = params['Success']
8
+ @error_code = params['ErrorCode']
9
+ @message = params['Message']
10
+ @details = params['Details']
11
+ @amount = params['Amount']
12
+ @merchant_email = params['MerchantEmail']
13
+ @merchant_name = params['MerchantName']
14
+ @order_id = params['OrderId']
15
+ @payment_id = params['PaymentId']
16
+ @tran_date = params['TranDate']
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,3 @@
1
+ module Tinkoff
2
+ VERSION = '0.1.0'
3
+ end
data/lib/tinkoff.rb ADDED
@@ -0,0 +1,11 @@
1
+ require 'httparty'
2
+ require 'active_support'
3
+ require 'active_support/core_ext/hash'
4
+ require 'tinkoff/request'
5
+ require 'tinkoff/client'
6
+ require 'tinkoff/payment'
7
+ require 'tinkoff/version'
8
+
9
+ module Tinkoff
10
+ include ActiveSupport::Configurable
11
+ end
data/tinkoff.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'tinkoff/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'tinkoff'
8
+ spec.version = Tinkoff::VERSION
9
+ spec.authors = ['Dan Kim']
10
+ spec.email = ['itsdanya@gmail.com']
11
+
12
+ spec.summary = 'Tinkoff API wrapper.'
13
+ spec.description = 'Ruby wrapper for Tinkoff Acquiring API.'
14
+ spec.homepage = 'https://github.com/dankimio/tinkoff'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test)/}) }
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.13'
23
+ spec.add_development_dependency 'rake', '~> 11.0'
24
+ spec.add_development_dependency 'minitest', '~> 5.0'
25
+
26
+ spec.add_runtime_dependency 'httparty', '~> 0.14'
27
+ spec.add_runtime_dependency 'activesupport', '~> 5.0'
28
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tinkoff
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Dan Kim
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-10-29 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.13'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.13'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '11.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '11.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: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: httparty
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.14'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.14'
69
+ - !ruby/object:Gem::Dependency
70
+ name: activesupport
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '5.0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '5.0'
83
+ description: Ruby wrapper for Tinkoff Acquiring API.
84
+ email:
85
+ - itsdanya@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".travis.yml"
92
+ - CODE_OF_CONDUCT.md
93
+ - Gemfile
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - bin/console
98
+ - bin/setup
99
+ - lib/tinkoff.rb
100
+ - lib/tinkoff/client.rb
101
+ - lib/tinkoff/payment.rb
102
+ - lib/tinkoff/request.rb
103
+ - lib/tinkoff/response.rb
104
+ - lib/tinkoff/version.rb
105
+ - tinkoff.gemspec
106
+ homepage: https://github.com/dankimio/tinkoff
107
+ licenses:
108
+ - MIT
109
+ metadata: {}
110
+ post_install_message:
111
+ rdoc_options: []
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ requirements: []
125
+ rubyforge_project:
126
+ rubygems_version: 2.5.1
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: Tinkoff API wrapper.
130
+ test_files: []