inplat 0.1.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e446f50a1d879395c175d908fb6ce0e3ac1102cf
4
+ data.tar.gz: dbeebd9cace162612deacba808d46726c58498da
5
+ SHA512:
6
+ metadata.gz: 23e3c3b95021ead7538d44016f363a44401f73d620cd7d2c0f60bf2cd3f08bfc90f968e5b0c8cec61ba5a6caf7c69cdca32cc44a8f4ea9dfcf219d675e215c97
7
+ data.tar.gz: b9c32a85d52c16fe654516f2a44bf94809c0ddcfa31d19c2924385f0138a024d826de3a9db8f6e4f2bd27059edc65cce0a66852d089901b415a3843fcda6fe1e
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.0
5
+ before_install: gem install bundler -v 1.13.6
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
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,65 @@
1
+ # Inplat
2
+
3
+ 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/inplat`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'inplat'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install inplat
22
+
23
+ ## Usage
24
+ First configure gem(e.g. for Rails prokects this can be put into `initializers/inplat.rb`):
25
+
26
+ ```ruby
27
+ Inplat.configure do |config|
28
+ config.api_key = "your api key"
29
+ config.secret = "your api secret"
30
+ config.environment = :demo
31
+ end
32
+ ```
33
+
34
+ Then you can perform requests in the following way:
35
+
36
+ ```ruby
37
+ api = Inplat.build
38
+
39
+ init_params = {
40
+ redirect_url: "google.com",
41
+ pay_type: "card",
42
+ params: { account: "test",
43
+ sum: 10000,
44
+ email: "pay@example.com",
45
+ details: "LALALALLA",
46
+ address: "test" },
47
+ pay_params: { pan: "5457210001000019", expire_month: "12", expire_year: "2025", cvv:"123", cardholder_name: "Test Card" }
48
+ }
49
+
50
+ api.init(init_params)
51
+
52
+ # => {"id"=>533728005314193050, "fail_callback_url"=>"http://7359e5b6.ngrok.io/inplat_callbacks",
53
+ # "success_callback_url"=>"http://7359e5b6.ngrok.io/inplat_callbacks",
54
+ # "success_redirect_url"=>"http://7359e5b6.ngrok.io/inplat_redirects", "code"=>0,
55
+ # "fail_redirect_url"=>"http://7359e5b6.ngrok.io/inplat_redirects", "message"=>"Операция выполнена успешно. ",
56
+ # "url"=>"google.com?payment_id=533728005314193050&orderId=af5408c2-e550-444d-8ccb-4edc0adf3602"}
57
+ ```
58
+ ## Contributing
59
+
60
+ Bug reports and pull requests are welcome on GitHub at https://github.com/creepychese/inplat.
61
+
62
+ ## License
63
+
64
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
65
+
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,12 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "inplat"
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
+
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
data/inplat.gemspec ADDED
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'inplat/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "inplat"
8
+ spec.version = Inplat::VERSION
9
+ spec.authors = ["Evgeniy Burdaev"]
10
+ spec.email = ["hate2me@yandex.ru"]
11
+
12
+ spec.summary = %q{Wrapper for inplat API}
13
+ spec.description = %q{Wrapper for Inplat API according to its specification}
14
+ spec.homepage = ""
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+
21
+ spec.bindir = "exe"
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.13"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "pry"
28
+ spec.add_development_dependency "minitest", "~> 5.0"
29
+
30
+ spec.add_runtime_dependency "rest-client"
31
+ end
data/lib/inplat.rb ADDED
@@ -0,0 +1,23 @@
1
+ require "inplat/version"
2
+ require "inplat/configuration"
3
+ require "inplat/api"
4
+ require "rest-client"
5
+ require "openssl"
6
+ require "Base64"
7
+ require "json"
8
+
9
+ module Inplat
10
+ extend self
11
+
12
+ def configure(&block)
13
+ block.call(configuration)
14
+ end
15
+
16
+ def configuration
17
+ @configuration ||= Configuration.new
18
+ end
19
+
20
+ def build
21
+ Api.new(configuration, RestClient)
22
+ end
23
+ end
data/lib/inplat/api.rb ADDED
@@ -0,0 +1,58 @@
1
+ module Inplat
2
+ class SignedRequest
3
+ attr_reader :host, :secret, :api_key
4
+
5
+ def initialize(params)
6
+ @host = params.fetch(:host)
7
+ @request_params = params.fetch(:request_params)
8
+ @secret = params.fetch(:secret)
9
+ @api_key = params.fetch(:api_key)
10
+ end
11
+
12
+ def request_body
13
+ @request_body ||= @request_params.to_json
14
+ end
15
+
16
+ def signed_uri
17
+ @uri ||= "#{host}/?api_key=#{api_key}&sign=#{sign}"
18
+ end
19
+
20
+ private
21
+
22
+ def sign
23
+ @sign = OpenSSL::HMAC.hexdigest('SHA256', secret, request_body)
24
+ end
25
+ end
26
+
27
+ class Api
28
+ POST_METHODS = ["form",
29
+ "init",
30
+ "check",
31
+ "pay",
32
+ "refund",
33
+ "link",
34
+ "links",
35
+ "unlink",
36
+ "reverse"
37
+ ].freeze
38
+
39
+ def initialize(configuration, client)
40
+ @configuration = configuration
41
+ @client = client
42
+ end
43
+
44
+ POST_METHODS.each do |method_name|
45
+ define_method(method_name) do |params|
46
+ params = params.merge(method: method_name)
47
+ signed_request = SignedRequest.new(host: configuration.host, request_params: params,
48
+ secret: configuration.secret, api_key: configuration.api_key)
49
+
50
+ JSON.parse(client.post(signed_request.signed_uri, signed_request.request_body, { content_type: "application/json; charset=utf-8" }))
51
+ end
52
+ end
53
+
54
+ private
55
+
56
+ attr_reader :configuration, :client
57
+ end
58
+ end
@@ -0,0 +1,10 @@
1
+ module Inplat
2
+ class Configuration
3
+ HOSTS = { production: "https://demo-api2.inplat.ru", demo: "https://demo-api2.inplat.ru"}
4
+ attr_accessor :api_key, :secret, :environment
5
+
6
+ def host
7
+ HOSTS[environment]
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,3 @@
1
+ module Inplat
2
+ VERSION = "0.1.1"
3
+ end
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: inplat
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Evgeniy Burdaev
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-11-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: '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: pry
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: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '5.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '5.0'
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: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Wrapper for Inplat API according to its specification
84
+ email:
85
+ - hate2me@yandex.ru
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".travis.yml"
92
+ - Gemfile
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - bin/console
97
+ - bin/setup
98
+ - inplat.gemspec
99
+ - lib/inplat.rb
100
+ - lib/inplat/api.rb
101
+ - lib/inplat/configuration.rb
102
+ - lib/inplat/version.rb
103
+ homepage: ''
104
+ licenses:
105
+ - MIT
106
+ metadata: {}
107
+ post_install_message:
108
+ rdoc_options: []
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ requirements: []
122
+ rubyforge_project:
123
+ rubygems_version: 2.5.1
124
+ signing_key:
125
+ specification_version: 4
126
+ summary: Wrapper for inplat API
127
+ test_files: []