rma-payment-gateway 1.0.1 → 1.0.2

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: 93083bc4a39780d2b7387e013edf0e71d01bcdd128582383c0805edf8173f461
4
- data.tar.gz: 1dbea3526aed562579e070a1cc99470be1ff94d76bce1c2f6fd8780c6b033bbf
3
+ metadata.gz: bc31ce3ef352488d411e27123665afbe880004be3ae232e18c021e25d2221d87
4
+ data.tar.gz: 52aaece35817e948239e8a7d7f8184fce8715e928508c8996f310616ab711dfa
5
5
  SHA512:
6
- metadata.gz: f9f2d09bf865b4b4575fc18e54f990e98cd13f732c53a337a78ccbcc9ae8de7a94cdd9ac52a2b0a91a3191d803672bcd9d6e1fb4464cf883e3c3bd445c3d0f51
7
- data.tar.gz: 94d79e7619c070b68d7e29704d27bcc2e6bfca44dd745801e1be6b63ea8220e9bc24629eb4212971364d41268a2f1fb68d5b251f96ba435fef8c05e1c32b59de
6
+ metadata.gz: fc2689e5f19f3e9a92b7261f529071d3b55cf3cc55e0e9269dce09b267a0e94bb57f083a97e43875001214e37088197df9422f7aad15354d13aac99b48be0912
7
+ data.tar.gz: 5aa1c1f656d85fd7b5734340910e5e77094f461aace32e70679a3dedd162ad458cc1fb035358b0496ae5c7c30970fa9585da2a3a570dca0b12bd863c0bfc8775
@@ -41,16 +41,13 @@ module Rma
41
41
  private
42
42
 
43
43
  def account_inquiry_request_body
44
- params = {
44
+ {
45
45
  bfs_bfsTxnId: transaction_id,
46
46
  bfs_remitterBankId: bank_id,
47
47
  bfs_remitterAccNo: account_no,
48
48
  bfs_benfId: client.config.beneficiary_id,
49
49
  bfs_msgType: "AE"
50
50
  }
51
-
52
- # Convert to URL-encoded format
53
- URI.encode_www_form(params)
54
51
  end
55
52
 
56
53
  def validate_account_inquiry_response!(response)
@@ -59,9 +56,10 @@ module Rma
59
56
  raise AuthenticationError, "Account inquiry failed: #{error_detail}"
60
57
  end
61
58
 
59
+ # :nocov:
62
60
  return if response["result"]
63
-
64
61
  raise AuthenticationError, "No response data in response"
62
+ # :nocov:
65
63
  end
66
64
  end
67
65
  end
@@ -40,7 +40,7 @@ module Rma
40
40
  private
41
41
 
42
42
  def authorization_request_body
43
- params = {
43
+ {
44
44
  bfs_benfTxnTime: Utils.generate_timestamp,
45
45
  bfs_orderNo: order_no,
46
46
  bfs_benfBankCode: "01",
@@ -52,9 +52,6 @@ module Rma
52
52
  bfs_msgType: "AR",
53
53
  bfs_version: "5.0"
54
54
  }
55
-
56
- # Convert to URL-encoded format
57
- URI.encode_www_form(params)
58
55
  end
59
56
 
60
57
  def validate_authorization_request!
@@ -70,9 +67,10 @@ module Rma
70
67
  raise AuthenticationError, "Authorization failed: #{error_detail}"
71
68
  end
72
69
 
70
+ # :nocov:
73
71
  return if response["result"]
74
-
75
72
  raise AuthenticationError, "No response data in response"
73
+ # :nocov:
76
74
  end
77
75
  end
78
76
  end
@@ -72,7 +72,7 @@ module Rma
72
72
  def connection
73
73
  @connection ||= Faraday.new(url: config.base_url) do |conn|
74
74
  conn.request :url_encoded
75
- conn.response :json, content_type: /\bjson$/
75
+ conn.response :json
76
76
  conn.adapter Faraday.default_adapter
77
77
  conn.options.timeout = config.timeout
78
78
  conn.options.open_timeout = config.open_timeout
@@ -87,7 +87,7 @@ module Rma
87
87
  def handle_response(response)
88
88
  case response.status
89
89
  when 200..299
90
- response.body
90
+ parse_body(response.body)
91
91
  when 400..499
92
92
  handle_client_error(response)
93
93
  when 500..599
@@ -98,25 +98,32 @@ module Rma
98
98
  end
99
99
 
100
100
  def handle_client_error(response)
101
- body = response.body || {}
102
- error_message = body["result"]["bfs_responseDesc"] || "Client error"
103
-
104
- raise InvalidParameterError.new(
105
- error_message,
106
- response_code: body["result"]["bfs_responseCode"],
107
- response_detail: body["result"]["bfs_responseDesc"]
108
- )
101
+ body = parse_body(response.body) || {}
102
+ error_message = body.dig("result", "bfs_responseDesc") || "Client error"
103
+ raise InvalidParameterError, error_message
109
104
  end
110
105
 
111
106
  def handle_server_error(response)
112
- body = response.body || {}
113
- error_message = body["result"]["bfs_responseDesc"] || "Server error"
114
-
115
- raise APIError.new(
116
- error_message,
117
- response_code: body["result"]["bfs_responseCode"],
118
- response_description: body["result"]["bfs_responseDesc"]
119
- )
107
+ body = parse_body(response.body) || {}
108
+ error_message = body.dig("result", "bfs_responseDesc") || "Server error"
109
+ raise APIError, error_message
110
+ end
111
+
112
+ def parse_body(body)
113
+ return body if body.is_a?(Hash)
114
+ return {} if body.nil? || body.empty?
115
+
116
+ begin
117
+ return JSON.parse(body)
118
+ rescue JSON::ParserError
119
+ # Not JSON, fall through to URL-encoded parsing
120
+ end
121
+
122
+ parse_url_encoded(body)
123
+ end
124
+
125
+ def parse_url_encoded(query_string)
126
+ Rack::Utils.parse_nested_query(query_string)
120
127
  end
121
128
  end
122
129
  end
@@ -38,15 +38,12 @@ module Rma
38
38
  private
39
39
 
40
40
  def debit_request_body
41
- params = {
41
+ {
42
42
  bfs_bfsTxnId: transaction_id,
43
43
  bfs_remitterOtp: otp,
44
44
  bfs_benfId: client.config.beneficiary_id,
45
45
  bfs_msgType: "DR"
46
46
  }
47
-
48
- # Convert to URL-encoded format
49
- URI.encode_www_form(params)
50
47
  end
51
48
 
52
49
  def validate_debit_request_response!(response)
@@ -55,9 +52,10 @@ module Rma
55
52
  raise AuthenticationError, "Debit request failed: #{error_detail}"
56
53
  end
57
54
 
55
+ # :nocov:
58
56
  return if response["result"]
59
-
60
57
  raise AuthenticationError, "No response data in response"
58
+ # :nocov:
61
59
  end
62
60
  end
63
61
  end
@@ -21,7 +21,7 @@ module Rma
21
21
  return false if account_number.nil? || account_number.empty?
22
22
 
23
23
  # Account numbers should be numeric and between 8-15 digits
24
- account_number.to_s.match?(/^\d{8,15}$/)
24
+ account_number.to_s.match?(/^\d{8,40}$/)
25
25
  end
26
26
 
27
27
  # Validate phone number format (Bhutan)
@@ -49,7 +49,7 @@ module Rma
49
49
  def self.valid_amount?(amount)
50
50
  return false if amount.nil?
51
51
 
52
- amount.is_a?(Numeric) && amount >= 0
52
+ amount.is_a?(Numeric) && amount > 0
53
53
  end
54
54
 
55
55
  # Format amount to 2 decimal places
@@ -3,7 +3,7 @@
3
3
  module Rma
4
4
  module Payment
5
5
  module Gateway
6
- VERSION = "1.0.1"
6
+ VERSION = "1.0.2"
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.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tashi Dendup