fondy 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.rspec +2 -0
- data/.rubocop.yml +31 -0
- data/.travis.yml +6 -0
- data/Gemfile +4 -0
- data/LICENSE +21 -0
- data/README.md +71 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/fondy.gemspec +29 -0
- data/lib/fondy.rb +12 -0
- data/lib/fondy/client.rb +47 -0
- data/lib/fondy/errors.rb +13 -0
- data/lib/fondy/request.rb +34 -0
- data/lib/fondy/response.rb +60 -0
- data/lib/fondy/signature.rb +23 -0
- data/lib/fondy/version.rb +3 -0
- metadata +146 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 156f2c6fa3274248556be7b535462815c8c111f3
|
4
|
+
data.tar.gz: 91669185ff1f24a4674efe7ea408e36786ec0f9f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ed1fb35bc8d3ff2e19c60307d975aa3613d36ea427953abafc86a8366ee998d2eb3fd502dfe67490dbd0562a0a4fe0ec17233ab0807231cd2e9c2d32a3138df1
|
7
|
+
data.tar.gz: 7bd31d253d4e855a17dd45ed149850d7feb718ad0031e91d5abb9c4bff2b69bfbbf56dd64100469c4795ef29ae69df5832e2227e755a714b1bbfa012afbf398d
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.2
|
3
|
+
DisplayCopNames: true
|
4
|
+
DisplayStyleGuide: true
|
5
|
+
Exclude:
|
6
|
+
- 'fondy.gemspec'
|
7
|
+
|
8
|
+
Style/Documentation:
|
9
|
+
Enabled: false
|
10
|
+
|
11
|
+
Metrics/LineLength:
|
12
|
+
Max: 100
|
13
|
+
|
14
|
+
Style/TrailingCommaInLiteral:
|
15
|
+
EnforcedStyleForMultiline: comma
|
16
|
+
|
17
|
+
Style/TrailingCommaInArguments:
|
18
|
+
EnforcedStyleForMultiline: comma
|
19
|
+
|
20
|
+
Style/AlignParameters:
|
21
|
+
EnforcedStyle: with_fixed_indentation
|
22
|
+
|
23
|
+
Style/MultilineMethodCallBraceLayout:
|
24
|
+
EnforcedStyle: new_line
|
25
|
+
|
26
|
+
Style/MultilineMethodCallIndentation:
|
27
|
+
EnforcedStyle: indented
|
28
|
+
|
29
|
+
Style/EmptyLines:
|
30
|
+
Exclude:
|
31
|
+
- 'spec/**/*'
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2016
|
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 all
|
13
|
+
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 THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
# Fondy
|
2
|
+
|
3
|
+
[![Build status](https://travis-ci.org/busfor/fondy.svg?branch=master)](https://travis-ci.org/busfor/fondy)
|
4
|
+
[![Code Climate](https://codeclimate.com/github/busfor/fondy/badges/gpa.svg)](https://codeclimate.com/github/busfor/fondy)
|
5
|
+
|
6
|
+
Ruby wrapper for Fondy API: https://portal.fondy.eu/en/info/api/v1.0
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem 'fondy'
|
14
|
+
```
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
$ gem install fondy
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
First, create API client:
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
client = Fondy::Client.new(merchant_id: 1, password: 'qwerty')
|
30
|
+
```
|
31
|
+
|
32
|
+
Check payment status:
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
response = client.status(order_id: 2)
|
36
|
+
|
37
|
+
response.success?
|
38
|
+
# => true
|
39
|
+
response.order_status
|
40
|
+
# => "approved"
|
41
|
+
|
42
|
+
response.error?
|
43
|
+
# => true
|
44
|
+
response.error_code
|
45
|
+
# => 1018
|
46
|
+
response.error_message
|
47
|
+
# => "Order not found"
|
48
|
+
```
|
49
|
+
|
50
|
+
Capture payment:
|
51
|
+
|
52
|
+
```ruby
|
53
|
+
response = client.capture(order_id: 2, amount: 100, currency: 'USD')
|
54
|
+
```
|
55
|
+
|
56
|
+
Refund payment:
|
57
|
+
|
58
|
+
```ruby
|
59
|
+
response = client.reverse(order_id: 2, amount: 100, currency: 'USD')
|
60
|
+
|
61
|
+
response = client.reverse(order_id: 2, amount: 100, currency: 'USD', comment: '...')
|
62
|
+
```
|
63
|
+
|
64
|
+
## Contributing
|
65
|
+
|
66
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/busfor/fondy. 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.
|
67
|
+
|
68
|
+
|
69
|
+
## License
|
70
|
+
|
71
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'fondy'
|
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
data/fondy.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'fondy/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'fondy'
|
8
|
+
spec.version = Fondy::VERSION
|
9
|
+
spec.authors = ['Roman Khrebtov']
|
10
|
+
spec.email = ['r.hrebtov@busfor.com']
|
11
|
+
|
12
|
+
spec.summary = 'Ruby wrapper for Fondy API'
|
13
|
+
spec.description = 'Ruby wrapper for Fondy API'
|
14
|
+
spec.homepage = 'https://github.com/busfor/fondy'
|
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_dependency 'faraday'
|
23
|
+
|
24
|
+
spec.add_development_dependency 'bundler', '~> 1.12'
|
25
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
26
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
27
|
+
spec.add_development_dependency 'webmock'
|
28
|
+
spec.add_development_dependency 'rubocop'
|
29
|
+
end
|
data/lib/fondy.rb
ADDED
data/lib/fondy/client.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
module Fondy
|
2
|
+
class Client
|
3
|
+
attr_reader :merchant_id, :password
|
4
|
+
|
5
|
+
def initialize(merchant_id:, password:)
|
6
|
+
@merchant_id = merchant_id
|
7
|
+
@password = password
|
8
|
+
end
|
9
|
+
|
10
|
+
def status(order_id:)
|
11
|
+
params = {
|
12
|
+
merchant_id: merchant_id,
|
13
|
+
order_id: order_id,
|
14
|
+
}
|
15
|
+
send_request(:post, "/api/status/#{order_id}", params)
|
16
|
+
end
|
17
|
+
|
18
|
+
def capture(order_id:, amount:, currency:)
|
19
|
+
params = {
|
20
|
+
merchant_id: merchant_id,
|
21
|
+
order_id: order_id,
|
22
|
+
amount: amount,
|
23
|
+
currency: currency,
|
24
|
+
}
|
25
|
+
send_request(:post, "/api/capture/#{order_id}", params)
|
26
|
+
end
|
27
|
+
|
28
|
+
def reverse(order_id:, amount:, currency:, comment: nil)
|
29
|
+
params = {
|
30
|
+
merchant_id: merchant_id,
|
31
|
+
order_id: order_id,
|
32
|
+
amount: amount,
|
33
|
+
currency: currency,
|
34
|
+
}
|
35
|
+
params[:comment] = comment if comment
|
36
|
+
send_request(:post, "/api/reverse/#{order_id}", params)
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def send_request(method, url, params)
|
42
|
+
params[:signature] = Signature.build(params: params, password: password)
|
43
|
+
http_response = Request.call(method, url, params)
|
44
|
+
Response.new(http_response: http_response, password: password)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/lib/fondy/errors.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
module Fondy
|
2
|
+
class Request
|
3
|
+
API_HOST = 'https://api.fondy.eu'.freeze
|
4
|
+
|
5
|
+
def self.call(*args)
|
6
|
+
new(*args).call
|
7
|
+
end
|
8
|
+
|
9
|
+
def initialize(method, url, body)
|
10
|
+
@method = method
|
11
|
+
@url = url
|
12
|
+
@body = body
|
13
|
+
end
|
14
|
+
|
15
|
+
def call
|
16
|
+
connection = Faraday::Connection.new(API_HOST)
|
17
|
+
connection.public_send(method) do |request|
|
18
|
+
request.url url
|
19
|
+
if body
|
20
|
+
request.body = { request: body }.to_json
|
21
|
+
request.headers['Content-Type'] = 'application/json'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
rescue Faraday::Error => e
|
25
|
+
raise Fondy::RequestError, e.message
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
attr_reader :method
|
31
|
+
attr_reader :url
|
32
|
+
attr_reader :body
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module Fondy
|
2
|
+
class Response
|
3
|
+
def initialize(http_response:, password:)
|
4
|
+
@http_response = http_response
|
5
|
+
check_signature(password) if success?
|
6
|
+
end
|
7
|
+
|
8
|
+
def success?
|
9
|
+
response['response_status'] == 'success'
|
10
|
+
end
|
11
|
+
|
12
|
+
def error?
|
13
|
+
!success?
|
14
|
+
end
|
15
|
+
|
16
|
+
def error_code
|
17
|
+
response['error_code']
|
18
|
+
end
|
19
|
+
|
20
|
+
def error_message
|
21
|
+
response['error_message']
|
22
|
+
end
|
23
|
+
|
24
|
+
def method_missing(method, *_args)
|
25
|
+
response[method.to_s] || super
|
26
|
+
end
|
27
|
+
|
28
|
+
def respond_to_missing?(method, *_args)
|
29
|
+
response.key?(method.to_s)
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
# rubocop:disable Style/GuardClause
|
35
|
+
def check_signature(password)
|
36
|
+
signature = response['signature']
|
37
|
+
unless signature
|
38
|
+
raise Fondy::InvalidSignatureError, 'Response signature not found'
|
39
|
+
end
|
40
|
+
|
41
|
+
expected_signature = Signature.build(params: response, password: password)
|
42
|
+
unless signature == expected_signature
|
43
|
+
raise Fondy::InvalidSignatureError, 'Invalid response signature'
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def response
|
48
|
+
@response ||= json_body['response'] || raise(Fondy::Error, 'Invalid response')
|
49
|
+
end
|
50
|
+
|
51
|
+
def json_body
|
52
|
+
@json_body ||=
|
53
|
+
begin
|
54
|
+
JSON.parse(@http_response.body)
|
55
|
+
rescue
|
56
|
+
raise Fondy::InvalidResponseError, 'Invalid response'
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Fondy
|
2
|
+
class Signature
|
3
|
+
def self.build(*args)
|
4
|
+
new(*args).build
|
5
|
+
end
|
6
|
+
|
7
|
+
def initialize(params:, password:)
|
8
|
+
@params = params
|
9
|
+
@password = password
|
10
|
+
end
|
11
|
+
|
12
|
+
def build
|
13
|
+
filtered_params = params.reject { |k, _v| k.to_s == 'signature' }
|
14
|
+
params_str = filtered_params.sort_by(&:first).map(&:last).join('|')
|
15
|
+
Digest::SHA1.hexdigest("#{password}|#{params_str}")
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
attr_reader :params
|
21
|
+
attr_reader :password
|
22
|
+
end
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,146 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fondy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Roman Khrebtov
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-11-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.12'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.12'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: webmock
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rubocop
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: Ruby wrapper for Fondy API
|
98
|
+
email:
|
99
|
+
- r.hrebtov@busfor.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- ".rspec"
|
106
|
+
- ".rubocop.yml"
|
107
|
+
- ".travis.yml"
|
108
|
+
- Gemfile
|
109
|
+
- LICENSE
|
110
|
+
- README.md
|
111
|
+
- Rakefile
|
112
|
+
- bin/console
|
113
|
+
- bin/setup
|
114
|
+
- fondy.gemspec
|
115
|
+
- lib/fondy.rb
|
116
|
+
- lib/fondy/client.rb
|
117
|
+
- lib/fondy/errors.rb
|
118
|
+
- lib/fondy/request.rb
|
119
|
+
- lib/fondy/response.rb
|
120
|
+
- lib/fondy/signature.rb
|
121
|
+
- lib/fondy/version.rb
|
122
|
+
homepage: https://github.com/busfor/fondy
|
123
|
+
licenses:
|
124
|
+
- MIT
|
125
|
+
metadata: {}
|
126
|
+
post_install_message:
|
127
|
+
rdoc_options: []
|
128
|
+
require_paths:
|
129
|
+
- lib
|
130
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
131
|
+
requirements:
|
132
|
+
- - ">="
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: '0'
|
135
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - ">="
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '0'
|
140
|
+
requirements: []
|
141
|
+
rubyforge_project:
|
142
|
+
rubygems_version: 2.4.8
|
143
|
+
signing_key:
|
144
|
+
specification_version: 4
|
145
|
+
summary: Ruby wrapper for Fondy API
|
146
|
+
test_files: []
|