berbix 0.0.11 → 1.0.0

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/berbix.rb +29 -43
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d8eeff509c87fe0264cbb510132a0c5ffbf8a61ac79f8bd56980663b876d6e5d
4
- data.tar.gz: ed88bdd49a00bc99866e8782eadcf7c3b155f5bf0e0e24e250dd6b04e58cbce9
3
+ metadata.gz: 5ea5395ef3e8e47cebb65f69c83faa5c6befc4cf1d47b78f758d46e7293b1263
4
+ data.tar.gz: 9f04b290e0b12d58d337185e5edb30df7b0372b2aa53702e59cec6eba518b284
5
5
  SHA512:
6
- metadata.gz: 180971c8bcb4837224b24d7e3c16cddf9dd78e2242dc7c93c0596d241ca733af3cc1fc925b1edc78c56fa4fdeb48af2d12bad1747186276f3c135c161b1e08b6
7
- data.tar.gz: c28b91d6b07c4bfe566af03b2f7b25ad67538154433b16773067f1675948b16692c895ce5f7c7b28ec051478dff15755275cbd25837042e9fcde0c135108c8ea
6
+ metadata.gz: 4934d3f1bd936605c9105bdfb81b7f2d758df5fbefdaf003f1701a8fa92b316dbbc7ba99ee67433e96a4d3ccba1855bfa61e63c30ca00e8d20c9e39a91f37d8c
7
+ data.tar.gz: 388dd769a94142986e96288335016700e1126f8b7cb28a365aab9888a4e46e3f40fe734da397029cd7bba17a1f02abe5ba175f6b60d8e3f26bf4d4f2919b33be
data/lib/berbix.rb CHANGED
@@ -2,12 +2,12 @@ require 'net/https'
2
2
  require 'json'
3
3
 
4
4
  module Berbix
5
- SDK_VERSION = '0.0.11'
5
+ SDK_VERSION = '1.0.0'
6
6
  CLOCK_DRIFT = 300
7
7
 
8
8
  class HTTPClient
9
9
  def request(method, url, headers, opts={})
10
- raise 'subclass must implement request'
10
+ raise(Berbix::BerbixError, 'subclass must implement request')
11
11
  end
12
12
  end
13
13
 
@@ -47,7 +47,7 @@ module Berbix
47
47
  res = cli.request(req)
48
48
  code = res.code.to_i
49
49
  if code < 200 || code >= 300
50
- raise(Berbix::BerbixError, 'unexpected status code returned')
50
+ raise(Berbix::BerbixError, "unexpected status code returned: #{code}")
51
51
  end
52
52
  if code == 204
53
53
  return
@@ -65,7 +65,6 @@ module Berbix
65
65
  @client_token = client_token
66
66
  @expiry = expiry
67
67
  @transaction_id = transaction_id
68
- @user_id = transaction_id
69
68
  @response = response
70
69
  end
71
70
 
@@ -74,7 +73,6 @@ module Berbix
74
73
  @client_token = client_token
75
74
  @expiry = expiry
76
75
  @transaction_id = transaction_id
77
- @user_id = transaction_id
78
76
  end
79
77
 
80
78
  def needs_refresh?
@@ -86,6 +84,15 @@ module Berbix
86
84
  end
87
85
  end
88
86
 
87
+ class HostedTransactionResponse
88
+ attr_reader :tokens, :hosted_url
89
+
90
+ def initialize(tokens, hosted_url)
91
+ @tokens = tokens
92
+ @hosted_url = hosted_url
93
+ end
94
+ end
95
+
89
96
  class Client
90
97
  def initialize(opts={})
91
98
  @api_secret = opts[:api_secret] || opts[:client_secret]
@@ -93,7 +100,7 @@ module Berbix
93
100
  @http_client = opts[:http_client] || NetHTTPClient.new
94
101
 
95
102
  if @api_secret.nil?
96
- raise ':api_secret must be provided when instantiating Berbix client'
103
+ raise(Berbix::BerbixError, ':api_secret must be provided when instantiating Berbix client')
97
104
  end
98
105
  end
99
106
 
@@ -101,15 +108,24 @@ module Berbix
101
108
  payload = {}
102
109
  payload[:email] = opts[:email] unless opts[:email].nil?
103
110
  payload[:phone] = opts[:phone] unless opts[:phone].nil?
104
- payload[:customer_uid] = opts[:customer_uid].to_s unless opts[:customer_uid].nil?
105
- payload[:template_key] = opts[:template_key] unless opts[:template_key].nil?
111
+ if opts[:customer_uid].nil?
112
+ raise(Berbix::BerbixError, ':customer_uid must be provided when creating a transaction')
113
+ else
114
+ payload[:customer_uid] = opts[:customer_uid].to_s
115
+ end
116
+ if opts[:template_key].nil?
117
+ raise(Berbix::BerbixError, ':template_key must be provided when creating a transaction')
118
+ else
119
+ payload[:template_key] = opts[:template_key]
120
+ end
106
121
  payload[:hosted_options] = opts[:hosted_options] unless opts[:hosted_options].nil?
107
122
  fetch_tokens('/v0/transactions', payload)
108
123
  end
109
124
 
110
- # This method is deprecated, please use create_transaction instead
111
- def create_user(opts={})
112
- create_transaction(opts)
125
+ def create_hosted_transaction(opts={})
126
+ opts[:hosted_options] = {} if opts[:hosted_options].nil?
127
+ tokens = create_transaction(opts)
128
+ HostedTransactionResponse.new(tokens, tokens.response["hosted_url"])
113
129
  end
114
130
 
115
131
  def refresh_tokens(tokens)
@@ -119,13 +135,6 @@ module Berbix
119
135
  })
120
136
  end
121
137
 
122
- def exchange_code(code)
123
- fetch_tokens('/v0/tokens', {
124
- 'code' => code,
125
- 'grant_type' => 'authorization_code',
126
- })
127
- end
128
-
129
138
  def fetch_transaction(tokens)
130
139
  token_auth_request(:get, tokens, '/v0/transactions')
131
140
  end
@@ -149,16 +158,6 @@ module Berbix
149
158
  token_auth_request(:patch, tokens, '/v0/transactions/override', data: payload)
150
159
  end
151
160
 
152
- # This method is deprecated, please use fetch_transaction instead
153
- def fetch_user(tokens)
154
- fetch_transaction(tokens)
155
- end
156
-
157
- def create_continuation(tokens)
158
- result = token_auth_request(:post, tokens, '/v0/continuations')
159
- result['value']
160
- end
161
-
162
161
  def validate_signature(secret, body, header)
163
162
  parts = header.split(',')
164
163
  # Version (parts[0]) is currently unused
@@ -221,22 +220,9 @@ module Berbix
221
220
  end
222
221
 
223
222
  def api_host(opts)
224
- unless opts[:api_host].nil?
225
- return opts[:api_host]
226
- end
227
-
228
- opts[:environment] ||= :production
229
- case opts[:environment]
230
- when :production
231
- return 'https://api.berbix.com'
232
- when :staging
233
- return 'https://api.staging.berbix.com'
234
- when :sandbox
235
- return 'https://api.sandbox.berbix.com'
236
- else
237
- raise 'invalid environment value specified';
238
- end
223
+ opts[:api_host].nil? ? 'https://api.berbix.com' : opts[:api_host]
239
224
  end
225
+
240
226
  end
241
227
 
242
228
  class BerbixError < StandardError
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: berbix
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Levine
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-09 00:00:00.000000000 Z
11
+ date: 2021-03-12 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Backend SDKs to interact with the Berbix Verify API endpoints.
14
14
  email: eric@berbix.com