rma-payment-gateway 1.0.2 → 1.0.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
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7e2093f132f0620f9d9455eae15c1d2b4b2a7eb31fc4cfab608fe0244683c50b
|
|
4
|
+
data.tar.gz: e62e9cef18f17683d4eb208f56dc09ca8d3991fa7ce7471f73dc93672d6854b0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: '0699e0a7456ca06ebac7a52e187b58aab1cab83ebf0cf835c10d78aa6d42891fba070094ade6ddc3d46b91d3780dd4a50783ae77fa8b83e250250a90bd3fb956'
|
|
7
|
+
data.tar.gz: '088a8cc8091ddbbde76bf65ea34ed473e6f51a4f4a64aedbb7d0b26801a70f20a21e5cc74c24c2091d4aad87bf297e4469a0cf231838435ef3c57d20463e6f42'
|
|
@@ -33,7 +33,7 @@ module Rma
|
|
|
33
33
|
|
|
34
34
|
validate_account_inquiry_response!(response)
|
|
35
35
|
|
|
36
|
-
response
|
|
36
|
+
response
|
|
37
37
|
rescue StandardError => e
|
|
38
38
|
raise AuthenticationError, "Failed to fetch account inquiry: #{e.message}"
|
|
39
39
|
end
|
|
@@ -51,15 +51,10 @@ module Rma
|
|
|
51
51
|
end
|
|
52
52
|
|
|
53
53
|
def validate_account_inquiry_response!(response)
|
|
54
|
-
unless response.is_a?(Hash) && response["
|
|
55
|
-
error_detail = response["
|
|
54
|
+
unless response.is_a?(Hash) && response["bfs_responseCode"] == "00"
|
|
55
|
+
error_detail = response["bfs_responseDesc"] || "Unknown error"
|
|
56
56
|
raise AuthenticationError, "Account inquiry failed: #{error_detail}"
|
|
57
57
|
end
|
|
58
|
-
|
|
59
|
-
# :nocov:
|
|
60
|
-
return if response["result"]
|
|
61
|
-
raise AuthenticationError, "No response data in response"
|
|
62
|
-
# :nocov:
|
|
63
58
|
end
|
|
64
59
|
end
|
|
65
60
|
end
|
|
@@ -32,7 +32,7 @@ module Rma
|
|
|
32
32
|
|
|
33
33
|
validate_authorization_response!(response)
|
|
34
34
|
|
|
35
|
-
response
|
|
35
|
+
response
|
|
36
36
|
rescue StandardError => e
|
|
37
37
|
raise AuthenticationError, "Failed to authorize: #{e.message}"
|
|
38
38
|
end
|
|
@@ -62,15 +62,10 @@ module Rma
|
|
|
62
62
|
end
|
|
63
63
|
|
|
64
64
|
def validate_authorization_response!(response)
|
|
65
|
-
unless response.is_a?(Hash) && response["
|
|
66
|
-
error_detail = response["
|
|
65
|
+
unless response.is_a?(Hash) && response["bfs_responseCode"] == "00"
|
|
66
|
+
error_detail = response["bfs_responseDesc"] || "Unknown error"
|
|
67
67
|
raise AuthenticationError, "Authorization failed: #{error_detail}"
|
|
68
68
|
end
|
|
69
|
-
|
|
70
|
-
# :nocov:
|
|
71
|
-
return if response["result"]
|
|
72
|
-
raise AuthenticationError, "No response data in response"
|
|
73
|
-
# :nocov:
|
|
74
69
|
end
|
|
75
70
|
end
|
|
76
71
|
end
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
require "faraday"
|
|
4
4
|
require "json"
|
|
5
|
+
require "openssl"
|
|
5
6
|
|
|
6
7
|
module Rma
|
|
7
8
|
module Payment
|
|
@@ -17,13 +18,17 @@ module Rma
|
|
|
17
18
|
#
|
|
18
19
|
# @param config [Rma::Payment::Gateway::Configuration] Configuration instance
|
|
19
20
|
class Client
|
|
20
|
-
attr_reader :config, :access_token
|
|
21
|
+
attr_reader :config, :access_token
|
|
21
22
|
|
|
22
23
|
def initialize(config = nil)
|
|
23
24
|
@config = config || Rma::Payment::Gateway.configuration
|
|
24
25
|
validate_configuration!
|
|
25
26
|
end
|
|
26
27
|
|
|
28
|
+
def private_key
|
|
29
|
+
@private_key ||= load_private_key
|
|
30
|
+
end
|
|
31
|
+
|
|
27
32
|
# Authorization methods
|
|
28
33
|
def authorization
|
|
29
34
|
@authorization ||= Authorization.new(self)
|
|
@@ -41,7 +46,8 @@ module Rma
|
|
|
41
46
|
|
|
42
47
|
# HTTP request methods
|
|
43
48
|
def post(body: {}, headers: {})
|
|
44
|
-
|
|
49
|
+
signed = body.empty? ? body : body.merge(bfs_checkSum: compute_checksum(body))
|
|
50
|
+
request(:post, body: signed, headers: headers)
|
|
45
51
|
end
|
|
46
52
|
|
|
47
53
|
def get(headers: {})
|
|
@@ -50,6 +56,23 @@ module Rma
|
|
|
50
56
|
|
|
51
57
|
private
|
|
52
58
|
|
|
59
|
+
def compute_checksum(params)
|
|
60
|
+
sorted_values = params.sort_by { |k, _| k }.to_h.values.join("|")
|
|
61
|
+
signature = private_key.sign(OpenSSL::Digest.new("SHA1"), sorted_values)
|
|
62
|
+
signature.unpack1("H*")&.upcase
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def load_private_key
|
|
66
|
+
key_content = if !config.rsa_key_path.to_s.strip.empty?
|
|
67
|
+
File.read(config.rsa_key_path)
|
|
68
|
+
else
|
|
69
|
+
config.rsa_key
|
|
70
|
+
end
|
|
71
|
+
OpenSSL::PKey::RSA.new(key_content)
|
|
72
|
+
rescue OpenSSL::PKey::RSAError => e
|
|
73
|
+
raise ConfigurationError, "Invalid RSA key: #{e.message}"
|
|
74
|
+
end
|
|
75
|
+
|
|
53
76
|
def validate_configuration!
|
|
54
77
|
raise ConfigurationError, "Configuration is required" if config.nil?
|
|
55
78
|
return if config.valid?
|
|
@@ -99,13 +122,13 @@ module Rma
|
|
|
99
122
|
|
|
100
123
|
def handle_client_error(response)
|
|
101
124
|
body = parse_body(response.body) || {}
|
|
102
|
-
error_message = body
|
|
125
|
+
error_message = body["bfs_responseDesc"] || "Client error"
|
|
103
126
|
raise InvalidParameterError, error_message
|
|
104
127
|
end
|
|
105
128
|
|
|
106
129
|
def handle_server_error(response)
|
|
107
130
|
body = parse_body(response.body) || {}
|
|
108
|
-
error_message = body
|
|
131
|
+
error_message = body["bfs_responseDesc"] || "Server error"
|
|
109
132
|
raise APIError, error_message
|
|
110
133
|
end
|
|
111
134
|
|
|
@@ -30,7 +30,7 @@ module Rma
|
|
|
30
30
|
|
|
31
31
|
validate_debit_request_response!(response)
|
|
32
32
|
|
|
33
|
-
response
|
|
33
|
+
response
|
|
34
34
|
rescue StandardError => e
|
|
35
35
|
raise AuthenticationError, "Failed to fetch debit request: #{e.message}"
|
|
36
36
|
end
|
|
@@ -47,15 +47,10 @@ module Rma
|
|
|
47
47
|
end
|
|
48
48
|
|
|
49
49
|
def validate_debit_request_response!(response)
|
|
50
|
-
unless response.is_a?(Hash) && response["
|
|
51
|
-
error_detail = response["
|
|
50
|
+
unless response.is_a?(Hash) && response["bfs_responseCode"] == "00"
|
|
51
|
+
error_detail = response["bfs_responseDesc"] || "Unknown error"
|
|
52
52
|
raise AuthenticationError, "Debit request failed: #{error_detail}"
|
|
53
53
|
end
|
|
54
|
-
|
|
55
|
-
# :nocov:
|
|
56
|
-
return if response["result"]
|
|
57
|
-
raise AuthenticationError, "No response data in response"
|
|
58
|
-
# :nocov:
|
|
59
54
|
end
|
|
60
55
|
end
|
|
61
56
|
end
|