fondy 0.1.2 → 0.1.3
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 +4 -4
- data/README.md +8 -0
- data/lib/fondy/client.rb +20 -2
- data/lib/fondy/response.rb +1 -15
- data/lib/fondy/signature.rb +17 -0
- data/lib/fondy/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ef61421423338fe035dd21c3caf23c6fa17eceb5
|
4
|
+
data.tar.gz: 48d29cc0c1f0c20d953eaa60f2d4b3f43a68aa70
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aaaa9f468e1f928bc551d1e847e2e55fc65cc569e5f4c2ae2b87e248eece0d2a5158dc4006179e08cdc4c406faccb1106de27d5ca0e1f852ff83a10bc19c6c61
|
7
|
+
data.tar.gz: a95f7facba55c64d1ded788424fe3a0fa0678fcd3db0023c1322ab692a15cdd17ba3890e738ff4ce29f57e477dcac75004b16b03bef7548ed7f1c8c8c1fb15ef
|
data/README.md
CHANGED
@@ -60,6 +60,14 @@ response.to_h
|
|
60
60
|
# }
|
61
61
|
```
|
62
62
|
|
63
|
+
Create payment:
|
64
|
+
|
65
|
+
```ruby
|
66
|
+
response = client.checkout(order_id: 2, order_desc: '...', amount: 100, currency: 'USD')
|
67
|
+
response.checkout_url
|
68
|
+
# => "https://api.fondy.eu/api/checkout?token=..."
|
69
|
+
```
|
70
|
+
|
63
71
|
Capture payment:
|
64
72
|
|
65
73
|
```ruby
|
data/lib/fondy/client.rb
CHANGED
@@ -7,6 +7,18 @@ module Fondy
|
|
7
7
|
@password = password
|
8
8
|
end
|
9
9
|
|
10
|
+
def checkout(order_id:, order_desc:, amount:, currency:, **other_params)
|
11
|
+
params = {
|
12
|
+
merchant_id: merchant_id,
|
13
|
+
order_id: order_id,
|
14
|
+
order_desc: order_desc,
|
15
|
+
amount: amount,
|
16
|
+
currency: currency,
|
17
|
+
**other_params,
|
18
|
+
}
|
19
|
+
send_request(:post, '/api/checkout/url', params, verify_signature: false)
|
20
|
+
end
|
21
|
+
|
10
22
|
def status(order_id:)
|
11
23
|
params = {
|
12
24
|
merchant_id: merchant_id,
|
@@ -38,10 +50,16 @@ module Fondy
|
|
38
50
|
|
39
51
|
private
|
40
52
|
|
41
|
-
def send_request(method, url, params)
|
53
|
+
def send_request(method, url, params, verify_signature: true)
|
42
54
|
params[:signature] = Signature.build(params: params, password: password)
|
43
55
|
http_response = Request.call(method, url, params)
|
44
|
-
Response.new(http_response
|
56
|
+
response = Response.new(http_response)
|
57
|
+
|
58
|
+
if verify_signature && response.success?
|
59
|
+
Signature.verify(params: response.to_h, password: password)
|
60
|
+
end
|
61
|
+
|
62
|
+
response
|
45
63
|
end
|
46
64
|
end
|
47
65
|
end
|
data/lib/fondy/response.rb
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
module Fondy
|
2
2
|
class Response
|
3
|
-
def initialize(http_response
|
3
|
+
def initialize(http_response)
|
4
4
|
@http_response = http_response
|
5
|
-
check_signature(password) if success?
|
6
5
|
end
|
7
6
|
|
8
7
|
def to_h
|
@@ -35,19 +34,6 @@ module Fondy
|
|
35
34
|
|
36
35
|
private
|
37
36
|
|
38
|
-
# rubocop:disable Style/GuardClause
|
39
|
-
def check_signature(password)
|
40
|
-
signature = response[:signature]
|
41
|
-
unless signature
|
42
|
-
raise Fondy::InvalidSignatureError, 'Response signature not found'
|
43
|
-
end
|
44
|
-
|
45
|
-
expected_signature = Signature.build(params: response, password: password)
|
46
|
-
unless signature == expected_signature
|
47
|
-
raise Fondy::InvalidSignatureError, 'Invalid response signature'
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
37
|
def response
|
52
38
|
@response ||= json_body[:response] || raise(Fondy::Error, 'Invalid response')
|
53
39
|
end
|
data/lib/fondy/signature.rb
CHANGED
@@ -4,6 +4,10 @@ module Fondy
|
|
4
4
|
new(*args).build
|
5
5
|
end
|
6
6
|
|
7
|
+
def self.verify(*args)
|
8
|
+
new(*args).verify
|
9
|
+
end
|
10
|
+
|
7
11
|
def initialize(params:, password:)
|
8
12
|
@params = params
|
9
13
|
@password = password
|
@@ -17,6 +21,19 @@ module Fondy
|
|
17
21
|
Digest::SHA1.hexdigest("#{password}|#{params_str}")
|
18
22
|
end
|
19
23
|
|
24
|
+
def verify
|
25
|
+
unless params[:signature]
|
26
|
+
raise Fondy::InvalidSignatureError, 'Response signature not found'
|
27
|
+
end
|
28
|
+
|
29
|
+
signature = build
|
30
|
+
unless params[:signature] == signature
|
31
|
+
raise Fondy::InvalidSignatureError, 'Invalid response signature'
|
32
|
+
end
|
33
|
+
|
34
|
+
true
|
35
|
+
end
|
36
|
+
|
20
37
|
private
|
21
38
|
|
22
39
|
attr_reader :params
|
data/lib/fondy/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fondy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Roman Khrebtov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-11-
|
11
|
+
date: 2016-11-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|