rma-payment-gateway 1.0.2 → 1.0.4

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: bc31ce3ef352488d411e27123665afbe880004be3ae232e18c021e25d2221d87
4
- data.tar.gz: 52aaece35817e948239e8a7d7f8184fce8715e928508c8996f310616ab711dfa
3
+ metadata.gz: 8761398358087d863249d34a3d6df1a14b374829cde1fa6ae5b66fc6b42d8e3b
4
+ data.tar.gz: b7fdbfeb4d801c9c33ae681adfc98875eec6ad8391274563951fe1ce885a1450
5
5
  SHA512:
6
- metadata.gz: fc2689e5f19f3e9a92b7261f529071d3b55cf3cc55e0e9269dce09b267a0e94bb57f083a97e43875001214e37088197df9422f7aad15354d13aac99b48be0912
7
- data.tar.gz: 5aa1c1f656d85fd7b5734340910e5e77094f461aace32e70679a3dedd162ad458cc1fb035358b0496ae5c7c30970fa9585da2a3a570dca0b12bd863c0bfc8775
6
+ metadata.gz: d6c84e3a1444a374259f54bf3e3459058c304d1be2e2934b773ac043fe9d01a3e5d358d16498f42966fe40e1830d4491d54b2d20c5c1bebe1db9c61c6311237e
7
+ data.tar.gz: ad5b6800446530c316a499b453c255bb65996aeb3acbe3fa4659e5b88fb417157bc558f7b3703579e5b3e38b5454266b677e935469d6c5ff76d317c2cc7038b3
@@ -27,15 +27,7 @@ module Rma
27
27
  @transaction_id = transaction_id
28
28
  @bank_id = bank_id
29
29
  @account_no = account_no
30
- response = client.post(
31
- body: account_inquiry_request_body
32
- )
33
-
34
- validate_account_inquiry_response!(response)
35
-
36
- response["result"]
37
- rescue StandardError => e
38
- raise AuthenticationError, "Failed to fetch account inquiry: #{e.message}"
30
+ client.post(body: account_inquiry_request_body)
39
31
  end
40
32
 
41
33
  private
@@ -50,17 +42,6 @@ module Rma
50
42
  }
51
43
  end
52
44
 
53
- def validate_account_inquiry_response!(response)
54
- unless response.is_a?(Hash) && response["result"]["bfs_responseCode"] == "00"
55
- error_detail = response["result"]["bfs_responseDesc"] || "Unknown error"
56
- raise AuthenticationError, "Account inquiry failed: #{error_detail}"
57
- end
58
-
59
- # :nocov:
60
- return if response["result"]
61
- raise AuthenticationError, "No response data in response"
62
- # :nocov:
63
- end
64
45
  end
65
46
  end
66
47
  end
@@ -28,13 +28,7 @@ module Rma
28
28
  @amount = amount
29
29
  @email = email
30
30
  validate_authorization_request!
31
- response = client.post(body: authorization_request_body)
32
-
33
- validate_authorization_response!(response)
34
-
35
- response["result"]
36
- rescue StandardError => e
37
- raise AuthenticationError, "Failed to authorize: #{e.message}"
31
+ client.post(body: authorization_request_body)
38
32
  end
39
33
 
40
34
  private
@@ -60,18 +54,6 @@ module Rma
60
54
  raise InvalidParameterError, "Email is required" if email.to_s.strip.empty?
61
55
  raise InvalidParameterError, "Email must be a valid email" unless Utils.valid_email?(email.to_s)
62
56
  end
63
-
64
- def validate_authorization_response!(response)
65
- unless response.is_a?(Hash) && response["result"]["bfs_responseCode"] == "00"
66
- error_detail = response["result"]["bfs_responseDesc"] || "Unknown error"
67
- raise AuthenticationError, "Authorization failed: #{error_detail}"
68
- end
69
-
70
- # :nocov:
71
- return if response["result"]
72
- raise AuthenticationError, "No response data in response"
73
- # :nocov:
74
- end
75
57
  end
76
58
  end
77
59
  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, :private_key
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
- request(:post, body: body, headers: headers)
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.dig("result", "bfs_responseDesc") || "Client error"
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.dig("result", "bfs_responseDesc") || "Server error"
131
+ error_message = body["bfs_responseDesc"] || "Server error"
109
132
  raise APIError, error_message
110
133
  end
111
134
 
@@ -26,13 +26,7 @@ module Rma
26
26
  def call(transaction_id, otp)
27
27
  @transaction_id = transaction_id
28
28
  @otp = otp
29
- response = client.post(body: debit_request_body)
30
-
31
- validate_debit_request_response!(response)
32
-
33
- response["result"]
34
- rescue StandardError => e
35
- raise AuthenticationError, "Failed to fetch debit request: #{e.message}"
29
+ client.post(body: debit_request_body)
36
30
  end
37
31
 
38
32
  private
@@ -45,18 +39,6 @@ module Rma
45
39
  bfs_msgType: "DR"
46
40
  }
47
41
  end
48
-
49
- def validate_debit_request_response!(response)
50
- unless response.is_a?(Hash) && response["result"]["bfs_responseCode"] == "00"
51
- error_detail = response["result"]["bfs_responseDesc"] || "Unknown error"
52
- raise AuthenticationError, "Debit request failed: #{error_detail}"
53
- end
54
-
55
- # :nocov:
56
- return if response["result"]
57
- raise AuthenticationError, "No response data in response"
58
- # :nocov:
59
- end
60
42
  end
61
43
  end
62
44
  end
@@ -3,7 +3,7 @@
3
3
  module Rma
4
4
  module Payment
5
5
  module Gateway
6
- VERSION = "1.0.2"
6
+ VERSION = "1.0.4"
7
7
  end
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rma-payment-gateway
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tashi Dendup