fondy 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 57bc5a72e4c5d272e31aed137929ea388a7c4b88
4
- data.tar.gz: 138b4e44a69784bbf7f4d9d66617a82a77294b10
3
+ metadata.gz: ef61421423338fe035dd21c3caf23c6fa17eceb5
4
+ data.tar.gz: 48d29cc0c1f0c20d953eaa60f2d4b3f43a68aa70
5
5
  SHA512:
6
- metadata.gz: d6d369d94c931eca6a7ea9faec46a1db670ffa109950f4d180ba66e39181cb1463f032dd56f5695c4749f455500a3fffeb4c078e13363deb2d90140e921a73c3
7
- data.tar.gz: 0ac578585a0511c4f48be32479b559d0a0df07d8ca733eca74079d96d93ab2fdd27530b254d3ab3c362de747a93657879220adb0f57ba0d7641bdb04f71b002e
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
@@ -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: http_response, password: password)
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
@@ -1,8 +1,7 @@
1
1
  module Fondy
2
2
  class Response
3
- def initialize(http_response:, password:)
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
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Fondy
2
- VERSION = '0.1.2'.freeze
2
+ VERSION = '0.1.3'.freeze
3
3
  end
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.2
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-07 00:00:00.000000000 Z
11
+ date: 2016-11-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday