fondy 0.1.0 → 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 +4 -4
- data/README.md +13 -0
- data/lib/fondy/response.rb +12 -8
- data/lib/fondy/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cd7a2cb3bab7cf8652c5c9ffb062092765c3875f
|
4
|
+
data.tar.gz: 183b415692c4a4d742678c521c0ff32fbe585908
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 267dd9d9bf3f81466052f0f87a791ff7417bcac1c037825ef05e99f85929ddb5e48d999aa1d774b79fd6d7a64d964231d93b2a5b88d06989ca95c28056f46d4f
|
7
|
+
data.tar.gz: 99ae2a12d7a4c778c377331c649318be714692952a7e6f4a50b884c521f36dcc5cdbf75e58245ae16d0dd05d6bae6cc7c743d2a150ede8d081e057972fdc5236
|
data/README.md
CHANGED
@@ -38,6 +38,13 @@ response.success?
|
|
38
38
|
# => true
|
39
39
|
response.order_status
|
40
40
|
# => "approved"
|
41
|
+
response.to_h
|
42
|
+
# => {
|
43
|
+
# response_status: "success",
|
44
|
+
# order_status: "approved",
|
45
|
+
# actual_amount: 100,
|
46
|
+
# ...
|
47
|
+
# }
|
41
48
|
|
42
49
|
response.error?
|
43
50
|
# => true
|
@@ -45,6 +52,12 @@ response.error_code
|
|
45
52
|
# => 1018
|
46
53
|
response.error_message
|
47
54
|
# => "Order not found"
|
55
|
+
response.to_h
|
56
|
+
# => {
|
57
|
+
# response_status: "failure",
|
58
|
+
# error_message: "Order not found",
|
59
|
+
# error_code: 1018
|
60
|
+
# }
|
48
61
|
```
|
49
62
|
|
50
63
|
Capture payment:
|
data/lib/fondy/response.rb
CHANGED
@@ -5,8 +5,12 @@ module Fondy
|
|
5
5
|
check_signature(password) if success?
|
6
6
|
end
|
7
7
|
|
8
|
+
def to_h
|
9
|
+
response
|
10
|
+
end
|
11
|
+
|
8
12
|
def success?
|
9
|
-
response[
|
13
|
+
response[:response_status] == 'success'
|
10
14
|
end
|
11
15
|
|
12
16
|
def error?
|
@@ -14,26 +18,26 @@ module Fondy
|
|
14
18
|
end
|
15
19
|
|
16
20
|
def error_code
|
17
|
-
response[
|
21
|
+
response[:error_code]
|
18
22
|
end
|
19
23
|
|
20
24
|
def error_message
|
21
|
-
response[
|
25
|
+
response[:error_message]
|
22
26
|
end
|
23
27
|
|
24
28
|
def method_missing(method, *_args)
|
25
|
-
response[method
|
29
|
+
response[method] || super
|
26
30
|
end
|
27
31
|
|
28
32
|
def respond_to_missing?(method, *_args)
|
29
|
-
response.key?(method
|
33
|
+
response.key?(method)
|
30
34
|
end
|
31
35
|
|
32
36
|
private
|
33
37
|
|
34
38
|
# rubocop:disable Style/GuardClause
|
35
39
|
def check_signature(password)
|
36
|
-
signature = response[
|
40
|
+
signature = response[:signature]
|
37
41
|
unless signature
|
38
42
|
raise Fondy::InvalidSignatureError, 'Response signature not found'
|
39
43
|
end
|
@@ -45,13 +49,13 @@ module Fondy
|
|
45
49
|
end
|
46
50
|
|
47
51
|
def response
|
48
|
-
@response ||= json_body[
|
52
|
+
@response ||= json_body[:response] || raise(Fondy::Error, 'Invalid response')
|
49
53
|
end
|
50
54
|
|
51
55
|
def json_body
|
52
56
|
@json_body ||=
|
53
57
|
begin
|
54
|
-
JSON.parse(@http_response.body)
|
58
|
+
JSON.parse(@http_response.body, symbolize_names: true)
|
55
59
|
rescue
|
56
60
|
raise Fondy::InvalidResponseError, 'Invalid response'
|
57
61
|
end
|
data/lib/fondy/version.rb
CHANGED