berbix 0.0.3 → 0.0.5
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/lib/berbix.rb +28 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a623bd8b3c467b7821497d7fae7b39423e5c0d7e115895c96af431903f16eb5a
|
4
|
+
data.tar.gz: 9ad98f9ce7c872cba73dcde207beef4ea4e010656981427c1d86c0e44968c8bd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8ab58b14a285077d3b1d0016061ec418c14701008b690a84aa0076d63308f07d4a2e4e5dfb44bb1af09098db4df33cec27670cbe004129d1e941cfde1eb8ff59
|
7
|
+
data.tar.gz: 260e5f5f407cc89d2f10c7b8955f810c983bea7e1bf990369d1e6cd1565f5b2310fb9716bd5c107b14c01e036a4fd0dfda05eef459f5a73107ffa648e46c34fd
|
data/lib/berbix.rb
CHANGED
@@ -3,6 +3,9 @@ require 'json'
|
|
3
3
|
|
4
4
|
module Berbix
|
5
5
|
|
6
|
+
SDK_VERSION = '0.0.5'
|
7
|
+
CLOCK_DRIFT = 300
|
8
|
+
|
6
9
|
class HTTPClient
|
7
10
|
def request(method, url, headers, opts={})
|
8
11
|
raise 'subclass must implement request'
|
@@ -84,7 +87,8 @@ module Berbix
|
|
84
87
|
payload = {}
|
85
88
|
payload[:email] = opts[:email] unless opts[:email].nil?
|
86
89
|
payload[:phone] = opts[:phone] unless opts[:phone].nil?
|
87
|
-
payload[:customer_uid] = opts[:customer_uid] unless opts[:customer_uid].nil?
|
90
|
+
payload[:customer_uid] = opts[:customer_uid].to_s unless opts[:customer_uid].nil?
|
91
|
+
payload[:template_key] = opts[:template_key] unless opts[:template_key].nil?
|
88
92
|
fetch_tokens('/v0/transactions', payload)
|
89
93
|
end
|
90
94
|
|
@@ -121,6 +125,24 @@ module Berbix
|
|
121
125
|
result['value']
|
122
126
|
end
|
123
127
|
|
128
|
+
def validate_signature(secret, body, header)
|
129
|
+
parts = header.split(',')
|
130
|
+
# Version (parts[0]) is currently unused
|
131
|
+
timestamp = parts[1]
|
132
|
+
signature = parts[2]
|
133
|
+
if timestamp.to_i < Time.now.to_i - CLOCK_DRIFT
|
134
|
+
return false
|
135
|
+
end
|
136
|
+
digest = OpenSSL::Digest::SHA256.new
|
137
|
+
hmac = OpenSSL::HMAC.new(secret, digest)
|
138
|
+
hmac << timestamp
|
139
|
+
hmac << ','
|
140
|
+
hmac << secret
|
141
|
+
hmac << ','
|
142
|
+
hmac << body
|
143
|
+
hmac.hexdigest == signature
|
144
|
+
end
|
145
|
+
|
124
146
|
private
|
125
147
|
|
126
148
|
def refresh_if_necessary!(tokens)
|
@@ -135,12 +157,16 @@ module Berbix
|
|
135
157
|
headers = {
|
136
158
|
'Authorization' => 'Bearer ' + tokens.access_token,
|
137
159
|
'Content-Type' => 'application/json',
|
160
|
+
'User-Agent' => 'BerbixRuby/' + SDK_VERSION,
|
138
161
|
}
|
139
162
|
@http_client.request(method, @api_host + path, headers)
|
140
163
|
end
|
141
164
|
|
142
165
|
def fetch_tokens(path, payload)
|
143
|
-
headers = {
|
166
|
+
headers = {
|
167
|
+
'Content-Type' => 'application/json',
|
168
|
+
'User-Agent' => 'BerbixRuby/' + SDK_VERSION,
|
169
|
+
}
|
144
170
|
result = @http_client.request(
|
145
171
|
:post,
|
146
172
|
@api_host + path,
|