tinkoff_client 0.1.0
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.
- checksums.yaml +7 -0
- data/lib/tinkoff_client/card_data.rb +17 -0
- data/lib/tinkoff_client/configuration.rb +13 -0
- data/lib/tinkoff_client/generators/service_generator.rb +25 -0
- data/lib/tinkoff_client/generators/templates/service_template.erb +16 -0
- data/lib/tinkoff_client/generators/templates/tinkoff_client_template.rb +5 -0
- data/lib/tinkoff_client/generators/tinkoff_client_generator.rb +12 -0
- data/lib/tinkoff_client/payment/payment.rb +40 -0
- data/lib/tinkoff_client/payment/request.rb +27 -0
- data/lib/tinkoff_client/requests.rb +26 -0
- data/lib/tinkoff_client/version.rb +5 -0
- data/lib/tinkoff_client.rb +27 -0
- metadata +139 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 384578a3b356320f2329b987a33548ae6fa7c362f28cb0157f531482bc38460e
|
|
4
|
+
data.tar.gz: a253c570d2e52c5accc722fa687809b17a6b0c890230970f7f1b0911daa56941
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: c0ca245978d0c853e377291171051f9e753f02421598636e3faad8e0dd520f88ebd82a2c1d64fed2e14fef185b6380c1a39399e017ab1c70cd7dcc0396160a15
|
|
7
|
+
data.tar.gz: f369c8ad05331b2a39d1b8af68d66958041480c779587af71318d353051040d321302920117698c18b89b63ef2cc755828e9e68ac2dfd5a9602c8c5f5b61bd1d
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "json"
|
|
4
|
+
require "rest-client"
|
|
5
|
+
require "openssl"
|
|
6
|
+
require "base64"
|
|
7
|
+
|
|
8
|
+
module TinkoffClient
|
|
9
|
+
module CardData
|
|
10
|
+
def encrypt_data(keys)
|
|
11
|
+
card = keys[:Card]
|
|
12
|
+
concatenated = card.map { |k, v| [k, v].join("=") }.join(";")
|
|
13
|
+
public_key = OpenSSL::PKey::RSA.new TinkoffClient.configuration.payment_public_key
|
|
14
|
+
card_data = Base64.encode64(public_key.public_encrypt(concatenated))
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module TinkoffClient
|
|
4
|
+
class Configuration
|
|
5
|
+
attr_accessor :payment_public_key, :payment_terminal_key, :payment_terminal_secret
|
|
6
|
+
|
|
7
|
+
def initialize
|
|
8
|
+
@payment_public_key = nil
|
|
9
|
+
@payment_terminal_key = nil
|
|
10
|
+
@payment_terminal_secret = nil
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
module TinkoffClient
|
|
2
|
+
module Generators
|
|
3
|
+
|
|
4
|
+
class ServiceGenerator < Rails::Generators::NamedBase
|
|
5
|
+
source_root File.expand_path('../templates', __FILE__)
|
|
6
|
+
|
|
7
|
+
argument :methods, type: :array, default: [], banner: "method method"
|
|
8
|
+
class_option :module, type: :string
|
|
9
|
+
|
|
10
|
+
def create_service_file
|
|
11
|
+
@module_name = options[:module]
|
|
12
|
+
|
|
13
|
+
service_dir_path = "app/services"
|
|
14
|
+
generator_dir_path = service_dir_path + ("/#{@module_name.underscore}" if @module_name.present?).to_s
|
|
15
|
+
generator_path = generator_dir_path + "/#{file_name}.rb"
|
|
16
|
+
|
|
17
|
+
Dir.mkdir(service_dir_path) unless File.exist?(service_dir_path)
|
|
18
|
+
Dir.mkdir(generator_dir_path) unless File.exist?(generator_dir_path)
|
|
19
|
+
|
|
20
|
+
template "service.erb", generator_path
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
<% if @module_name.present? %> module <%= @module_name.camelize %> <% end %>
|
|
2
|
+
class <%= class_name %>
|
|
3
|
+
|
|
4
|
+
def initialize
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def call
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
<% if methods.present? %> private <% end %>
|
|
11
|
+
<% for method in methods %>
|
|
12
|
+
def <%= method %>
|
|
13
|
+
end
|
|
14
|
+
<% end %>
|
|
15
|
+
end
|
|
16
|
+
<% if @module_name.present? %> end <% end %>
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
module TinkoffClient
|
|
2
|
+
module Generators
|
|
3
|
+
class TinkoffClientGenerator < Rails::Generators::Base
|
|
4
|
+
namespace "tinkoff_client"
|
|
5
|
+
source_root File.expand_path("templates", __dir__)
|
|
6
|
+
|
|
7
|
+
def copy_initializer_file
|
|
8
|
+
template "tinkoff_client_template.rb", "config/initializers/tinkoff_client.rb"
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "./request"
|
|
4
|
+
require_relative "../card_data"
|
|
5
|
+
|
|
6
|
+
module TinkoffClient
|
|
7
|
+
module Payment
|
|
8
|
+
extend CardData
|
|
9
|
+
|
|
10
|
+
def self.init(keys)
|
|
11
|
+
Request.request(path: "Init", keys: keys)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def self.confirm(keys)
|
|
15
|
+
Request.request(path: "Confirm", keys: keys)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def self.get_state(keys)
|
|
19
|
+
Request.request(path: "GetState", keys: keys)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def self.cancel(keys)
|
|
23
|
+
Request.request(path: "Cancel", keys: keys)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def self.check_order(keys)
|
|
27
|
+
Request.request(path: "CheckOrder", keys: keys)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def self.send_closing_receipt(keys)
|
|
31
|
+
Request.request(path: "SendClosingReceipt", keys: keys)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def self.finish_authorize(keys)
|
|
35
|
+
card_data = encrypt_data(keys)
|
|
36
|
+
keys[:CardData] = card_data
|
|
37
|
+
Request.request(path: "FinishAuthorize", keys: keys.except(:Card))
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "../requests"
|
|
4
|
+
|
|
5
|
+
module TinkoffClient
|
|
6
|
+
module Payment
|
|
7
|
+
class Request
|
|
8
|
+
include Requests
|
|
9
|
+
|
|
10
|
+
attr_reader :url
|
|
11
|
+
|
|
12
|
+
def initialize(url)
|
|
13
|
+
@url = "https://securepay.tinkoff.ru/v2/".freeze
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def self.request(*args, &block)
|
|
17
|
+
params = args[0]
|
|
18
|
+
new(*args, &block).request(path: params[:path], keys: params[:keys])
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def generate_token(keys)
|
|
22
|
+
params = keys.except(:Receipt, :Shops, :DATA).sort.transpose[1].join
|
|
23
|
+
digest = Digest::SHA2.new(256).hexdigest params
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "json"
|
|
4
|
+
require "rest-client"
|
|
5
|
+
|
|
6
|
+
module TinkoffClient
|
|
7
|
+
module Requests
|
|
8
|
+
def request(path:, keys:)
|
|
9
|
+
url = @url + path
|
|
10
|
+
payload = init_params(keys).to_json
|
|
11
|
+
result = RestClient.post(url, payload, content_type: :json)
|
|
12
|
+
data = JSON.parse result.body
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def init_params(keys)
|
|
16
|
+
payload = {
|
|
17
|
+
TerminalKey: TinkoffClient.configuration.payment_terminal_key,
|
|
18
|
+
Password: TinkoffClient.configuration.payment_terminal_secret,
|
|
19
|
+
**keys,
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
payload[:Token] = generate_token(payload)
|
|
23
|
+
payload.except(:Password)
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "tinkoff_client/version"
|
|
4
|
+
require_relative "tinkoff_client/configuration"
|
|
5
|
+
require_relative "tinkoff_client/payment/payment"
|
|
6
|
+
|
|
7
|
+
module TinkoffClient
|
|
8
|
+
class Error < StandardError; end
|
|
9
|
+
|
|
10
|
+
include Payment
|
|
11
|
+
|
|
12
|
+
class << self
|
|
13
|
+
attr_accessor :configuration
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def self.configuration
|
|
17
|
+
@configuration ||= Configuration.new
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def self.reset
|
|
21
|
+
@configuration = Configuration.new
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def self.configure
|
|
25
|
+
yield(configuration)
|
|
26
|
+
end
|
|
27
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: tinkoff_client
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- netsky_prod
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2022-11-15 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: rspec
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '3.0'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '3.0'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: pry
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: 0.14.1
|
|
34
|
+
type: :runtime
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: 0.14.1
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: openssl
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: 3.0.1
|
|
48
|
+
type: :runtime
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: 3.0.1
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: base64
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - "~>"
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: 0.1.1
|
|
62
|
+
type: :runtime
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - "~>"
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: 0.1.1
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: rest-client
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - "~>"
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: 2.1.0
|
|
76
|
+
type: :runtime
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - "~>"
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: 2.1.0
|
|
83
|
+
- !ruby/object:Gem::Dependency
|
|
84
|
+
name: rake
|
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
|
86
|
+
requirements:
|
|
87
|
+
- - "~>"
|
|
88
|
+
- !ruby/object:Gem::Version
|
|
89
|
+
version: '13.0'
|
|
90
|
+
type: :runtime
|
|
91
|
+
prerelease: false
|
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
93
|
+
requirements:
|
|
94
|
+
- - "~>"
|
|
95
|
+
- !ruby/object:Gem::Version
|
|
96
|
+
version: '13.0'
|
|
97
|
+
description: Tinkoff Ruby API wrapper for payments and e2c payouts.
|
|
98
|
+
email:
|
|
99
|
+
- arenda244@ya.ru
|
|
100
|
+
executables: []
|
|
101
|
+
extensions: []
|
|
102
|
+
extra_rdoc_files: []
|
|
103
|
+
files:
|
|
104
|
+
- lib/tinkoff_client.rb
|
|
105
|
+
- lib/tinkoff_client/card_data.rb
|
|
106
|
+
- lib/tinkoff_client/configuration.rb
|
|
107
|
+
- lib/tinkoff_client/generators/service_generator.rb
|
|
108
|
+
- lib/tinkoff_client/generators/templates/service_template.erb
|
|
109
|
+
- lib/tinkoff_client/generators/templates/tinkoff_client_template.rb
|
|
110
|
+
- lib/tinkoff_client/generators/tinkoff_client_generator.rb
|
|
111
|
+
- lib/tinkoff_client/payment/payment.rb
|
|
112
|
+
- lib/tinkoff_client/payment/request.rb
|
|
113
|
+
- lib/tinkoff_client/requests.rb
|
|
114
|
+
- lib/tinkoff_client/version.rb
|
|
115
|
+
homepage: https://netsky.dev/opensource/tinkoff_client
|
|
116
|
+
licenses: []
|
|
117
|
+
metadata:
|
|
118
|
+
source_code_uri: https://github.com/netsky-dev/tinkoff_client
|
|
119
|
+
post_install_message:
|
|
120
|
+
rdoc_options: []
|
|
121
|
+
require_paths:
|
|
122
|
+
- lib
|
|
123
|
+
- lib/tinkoff_client
|
|
124
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
125
|
+
requirements:
|
|
126
|
+
- - ">="
|
|
127
|
+
- !ruby/object:Gem::Version
|
|
128
|
+
version: 2.6.0
|
|
129
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
130
|
+
requirements:
|
|
131
|
+
- - ">="
|
|
132
|
+
- !ruby/object:Gem::Version
|
|
133
|
+
version: '0'
|
|
134
|
+
requirements: []
|
|
135
|
+
rubygems_version: 3.3.3
|
|
136
|
+
signing_key:
|
|
137
|
+
specification_version: 4
|
|
138
|
+
summary: Tinkoff Ruby API wrapper for payments and e2c payouts.
|
|
139
|
+
test_files: []
|