simplify 1.0.1 → 1.1.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.
@@ -33,12 +33,28 @@ module Simplify
33
33
  #
34
34
  class Payment < Hash
35
35
 
36
- # Public key used to access the API.
37
- attr_accessor :public_key
36
+ # Authentication object used to access the API (See Simplify::Authentication for details)
37
+ attr_accessor :authentication
38
38
 
39
- # Private key used to access the API.
40
- attr_accessor :private_key
39
+ # Returns the public key used when accessing this object. <b>Deprecated: please use 'authentication' instead.</b>
40
+ def public_key
41
+ return self.authentication.public_key
42
+ end
41
43
 
44
+ # Sets the public key used when accessing this object. <b>Deprecated: please use 'authentication' instead.</b>
45
+ def public_key=(k)
46
+ return self.authentication.public_key = k
47
+ end
48
+
49
+ # Returns the private key used when accessing this object. <b>Deprecated: please use 'authentication' instead.</b>
50
+ def private_key
51
+ return self.authentication.private_key
52
+ end
53
+
54
+ # Sets the private key used when accessing this object. <b>Deprecated: please use 'authentication' instead.</b>
55
+ def private_key=(k)
56
+ return self.authentication.private_key = k
57
+ end
42
58
 
43
59
 
44
60
  # Creates an Payment object
@@ -59,23 +75,17 @@ class Payment < Hash
59
75
  # * <code>currency</code> Currency code (ISO-4217) for the transaction. Must match the currency associated with your account. <b>required </b><b>default:USD</b>
60
76
  # * <code>customer</code> ID of customer. If specified, card on file of customer will be used.
61
77
  # * <code>description</code> Custom naming of payment for external systems to use.
78
+ # * <code>reference</code> Custom reference field to be used with outside systems.
62
79
  # * <code>token</code> If specified, card associated with card token will be used.
63
- # public_key:: Public to use for the API call. If nil, the value of Simplify::public_key will be used.
64
- # private_key:: Private key to use for the API call. If nil, the value of Simplify::private_key will be used.
80
+ # auth:: Authentication information used for the API call. If no value is passed the global keys Simplify::public_key and Simplify::private_key are used. For backwards compatibility the public and private keys may be passed instead of the authentication object.
65
81
  # Returns a Payment object.
66
- def self.create(parms, public_key = nil, private_key = nil)
67
- if public_key == nil then
68
- public_key = Simplify::public_key
69
- end
70
- if private_key == nil then
71
- private_key = Simplify::private_key
72
- end
73
-
74
- h = Simplify::PaymentsApi.execute("payment", 'create', parms, public_key, private_key)
82
+ def self.create(parms, *auth)
83
+
84
+ auth_obj = Simplify::PaymentsApi.create_auth_object(auth)
85
+ h = Simplify::PaymentsApi.execute("payment", 'create', parms, auth_obj)
75
86
  obj = Payment.new()
76
- obj.public_key = public_key
77
- obj.private_key = private_key
78
- obj = obj.merge(h)
87
+ obj.authentication = auth_obj
88
+ obj = obj.merge!(h)
79
89
  obj
80
90
  end
81
91
 
@@ -85,24 +95,16 @@ class Payment < Hash
85
95
  # * <code>max</code> Allows up to a max of 50 list items to return. <b>default:20</b>
86
96
  # * <code>offset</code> Used in paging of the list. This is the start offset of the page. <b>default:0</b>
87
97
  # * <code>sorting</code> Allows for ascending or descending sorting of the list. The value maps properties to the sort direction (either <code>asc</code> for ascending or <code>desc</code> for descending). Sortable properties are: <code> dateCreated</code><code> amount</code><code> id</code><code> description</code><code> paymentDate</code>.
88
- # public_key:: Public to use for the API call. If nil, the value of Simplify::public_key will be used.
89
- # private_key:: Private key to use for the API call. If nil, the value of Simplify::private_key will be used.
98
+ # auth:: Authentication information used for the API call. If no value is passed the global keys Simplify::public_key and Simplify::private_key are used. For backwards compatibility the public and private keys may be passed instead of the authentication object.
90
99
  # Returns an object where the <code>list</code> property contains the list of Payment objects and the <code>total</code>
91
100
  # property contains the total number of Payment objects available for the given criteria.
92
- def self.list(criteria = nil, public_key = nil, private_key = nil)
101
+ def self.list(criteria = nil, *auth)
93
102
 
94
- if public_key == nil then
95
- public_key = Simplify::public_key
96
- end
97
- if private_key == nil then
98
- private_key = Simplify::private_key
99
- end
100
-
101
- h = Simplify::PaymentsApi.execute("payment", 'list', criteria, public_key, private_key)
103
+ auth_obj = Simplify::PaymentsApi.create_auth_object(auth)
104
+ h = Simplify::PaymentsApi.execute("payment", 'list', criteria, auth_obj)
102
105
  obj = Payment.new()
103
- obj.public_key = public_key
104
- obj.private_key = private_key
105
- obj = obj.merge(h)
106
+ obj.authentication = auth_obj
107
+ obj = obj.merge!(h)
106
108
  obj
107
109
 
108
110
  end
@@ -110,22 +112,15 @@ class Payment < Hash
110
112
  # Retrieve a Payment object from the API
111
113
  #
112
114
  # id:: ID of object to retrieve
113
- # public_key:: Public to use for the API call. If nil, the value of Simplify::public_key will be used.
114
- # private_key:: Private key to use for the API call. If nil, the value of Simplify::private_key will be used.
115
+ # auth:: Authentication information used for the API call. If no value is passed the global keys Simplify::public_key and Simplify::private_key are used. For backwards compatibility the public and private keys may be passed instead of the authentication object.
115
116
  # Returns a Payment object.
116
- def self.find(id, public_key = nil, private_key = nil)
117
- if public_key == nil then
118
- public_key = Simplify::public_key
119
- end
120
- if private_key == nil then
121
- private_key = Simplify::private_key
122
- end
123
-
124
- h = Simplify::PaymentsApi.execute("payment", 'show', {"id" => id}, public_key, private_key)
117
+ def self.find(id, *auth)
118
+
119
+ auth_obj = Simplify::PaymentsApi.create_auth_object(auth)
120
+ h = Simplify::PaymentsApi.execute("payment", 'show', {"id" => id}, auth_obj)
125
121
  obj = Payment.new()
126
- obj.public_key = public_key
127
- obj.private_key = private_key
128
- obj = obj.merge(h)
122
+ obj.authentication = auth_obj
123
+ obj = obj.merge!(h)
129
124
  obj
130
125
  end
131
126
 
@@ -31,6 +31,7 @@ require 'open-uri'
31
31
  require 'json'
32
32
  require 'hmac-sha2'
33
33
  require 'securerandom'
34
+ require 'simplify/authentication'
34
35
  require 'simplify/apiexception'
35
36
  require 'simplify/constants'
36
37
  require 'simplify/event'
@@ -41,6 +42,7 @@ module Simplify
41
42
  @@private_key = nil
42
43
  @@api_base_live_url = Constants::api_base_live_url
43
44
  @@api_base_sandbox_url = Constants::api_base_sandbox_url
45
+ @@oauth_base_url = Constants::oauth_base_url
44
46
  @@user_agent = nil
45
47
 
46
48
 
@@ -84,6 +86,16 @@ module Simplify
84
86
  @@api_base_sandbox_url = url
85
87
  end
86
88
 
89
+ # Returns the base URL for the OAuth API.
90
+ def self.oauth_base_url
91
+ @@oauth_base_url
92
+ end
93
+
94
+ # Sets the base URL for the OAuth API.
95
+ def self.oauth_base_url=(url)
96
+ @@oauth_base_url = url
97
+ end
98
+
87
99
  # Returns the user agent value sent in requests to the API.
88
100
  def self.user_agent
89
101
  @@user_agent
@@ -104,6 +116,8 @@ module Simplify
104
116
  @@JWS_HDR_URI = 'api.simplifycommerce.com/uri'
105
117
  @@JWS_HDR_TIMESTAMP = 'api.simplifycommerce.com/timestamp'
106
118
  @@JWS_HDR_NONCE = 'api.simplifycommerce.com/nonce'
119
+ @@JWS_HDR_TOKEN = "api.simplifycommerce.com/token";
120
+
107
121
  @@JWS_TIMESTAMP_MAX_DIFF = 1000 * 60 * 5 # 5 minutes
108
122
 
109
123
  @@HTTP_SUCCESS = 200
@@ -112,29 +126,59 @@ module Simplify
112
126
  @@HTTP_NOT_FOUND = 404
113
127
  @@HTTP_NOT_ALLOWED = 405
114
128
  @@HTTP_BAD_REQUEST = 400
129
+ @@HTTP_SERVER_ERROR = 500
130
+
131
+ def self.create_auth_object(auth)
132
+
133
+ case auth.length
134
+ when 0
135
+ auth_obj = Authentication.new(:public_key => Simplify::public_key, :private_key => Simplify::private_key)
136
+ when 1
137
+ auth_obj = auth[0]
138
+ if ! auth_obj.is_a? Authentication
139
+ raise ArgumentError.new("Invalid Authentication object passed")
140
+ end
141
+ when 2
142
+ # Deprecated case where public and private keys are passed
143
+ public_key = auth[0]
144
+ if public_key == nil
145
+ public_key = Simplify::public_key
146
+ end
147
+ private_key = auth[1]
148
+ if private_key == nil
149
+ private_key = Simplify::private_key
150
+ end
151
+ auth_obj = Authentication.new(:public_key => public_key, :private_key => private_key)
152
+ else
153
+ raise ArgumentError.new("Invalid authentication arguments passed")
154
+ end
115
155
 
116
- def self.execute(type, action, objectMap, public_key = nil, private_key = nil)
156
+ return auth_obj
157
+ end
117
158
 
118
- if public_key == nil
119
- public_key = Simplify::public_key
159
+ def self.check_auth(auth)
160
+ if auth == nil
161
+ raise ArgumentError.new("Missing authentication object")
120
162
  end
121
163
 
122
- if public_key == nil
123
- raise ArgumentError.new("Must have a valid public key to connect to the API")
164
+ if auth.public_key == nil
165
+ raise ArgumentError.new("Must have a valid public key to connect to the API")
124
166
  end
125
167
 
126
- if private_key == nil
127
- private_key = Simplify::private_key
168
+ if auth.private_key == nil
169
+ raise ArgumentError.new("Must have a valid private key to connect to the API")
128
170
  end
171
+ end
129
172
 
130
- if private_key == nil
131
- raise ArgumentError.new("Must have a valid API key to connect to the API", nil, nil)
132
- end
173
+
174
+ def self.execute(type, action, objectMap, auth)
175
+
176
+ check_auth(auth)
133
177
 
134
178
  content_type = 'application/json'
135
- url = build_url(get_base_url(public_key), type, action, objectMap)
179
+ url = build_url(get_base_url(auth.public_key), type, action, objectMap)
136
180
 
137
- signature = jws_encode(public_key, private_key, url, objectMap, action == 'update' || action == 'create')
181
+ signature = jws_encode(auth, url, objectMap, action == 'update' || action == 'create')
138
182
 
139
183
  opts = case action
140
184
  when 'show', 'projections' then
@@ -190,7 +234,7 @@ module Simplify
190
234
  end
191
235
 
192
236
  if e.response.code == @@HTTP_REDIRECTED
193
- raise BadRequestException.new("Unexpected response code returned from the API, have you got the correct URL?", responseCode, e.response.code, errorData)
237
+ raise BadRequestException.new("Unexpected response code returned from the API, have you got the correct URL?", e.response.code, errorData)
194
238
  elsif e.response.code == @@HTTP_BAD_REQUEST
195
239
  raise BadRequestException.new("Bad request", e.response.code, errorData)
196
240
  elsif e.response.code == @@HTTP_UNAUTHORIZED
@@ -199,7 +243,7 @@ module Simplify
199
243
  raise ObjectNotFoundException.new("Object not found", e.response.code, errorData)
200
244
  elsif e.response.code == @@HTTP_NOT_ALLOWED
201
245
  raise NotAllowedException.new("Operation not allowed", e.response.code, errorData)
202
- elsif e.response.code < 500
246
+ elsif e.response.code < @@HTTP_SERVER_ERROR
203
247
  raise BadRequestException.new("Bad request", e.response.code, errorData)
204
248
  else
205
249
  raise SystemException.new("An unexpected error has been raised. Looks like there's something wrong at our end.", e.response.code, errorData)
@@ -207,6 +251,78 @@ module Simplify
207
251
  end
208
252
  end
209
253
 
254
+
255
+ def self.send_auth_request(props, context, auth)
256
+
257
+ check_auth(auth)
258
+
259
+ content_type = 'application/json'
260
+
261
+ url = "#{Simplify::oauth_base_url}/#{context}"
262
+
263
+ signature = oauth_jws_encode(auth, url, props)
264
+
265
+ opts = {
266
+ :method => 'POST',
267
+ :payload => signature
268
+ }
269
+
270
+ user_agent = "Ruby-SDK/#{Constants::version}"
271
+ if Simplify::user_agent != nil
272
+ user_agent = "#{user_agent} #{Simplify::user_agent}"
273
+ end
274
+
275
+ opts = opts.merge({
276
+ :url => url,
277
+ :headers => {
278
+ 'Content-Type' => content_type,
279
+ 'Accept' => 'application/json',
280
+ 'User-Agent' => user_agent
281
+ }.merge(opts[:headers] || {})
282
+ })
283
+
284
+ begin
285
+ response = RestClient::Request.execute(opts)
286
+ JSON.parse(response.body)
287
+ rescue RestClient::Exception => e
288
+
289
+ begin
290
+ errorData = JSON.parse(e.response.body)
291
+ rescue JSON::ParserError => e2
292
+ raise ApiException.new("Unknown error", nil, nil)
293
+ end
294
+
295
+ if e.response.code == @@HTTP_REDIRECTED
296
+ raise BadRequestException.new("Unexpected response code returned from the API, have you got the correct URL?", e.response.code, {})
297
+ elsif e.response.code >= @@HTTP_BAD_REQUEST and e.response.code < @@HTTP_SERVER_ERROR
298
+ error_code = errorData['error']
299
+ error_desc = errorData['error_description']
300
+ if (error_code == 'invalid_request')
301
+ raise BadRequestException.new("", e.response.code, get_oauth_error("Error during OAuth request", error_code, error_desc))
302
+ elsif (error_code == 'access_denied')
303
+ raise AuthenticationException.new("", e.response.code, get_oauth_error("Access denied for OAuth request", error_code, error_desc))
304
+ elsif (error_code == 'invalid_client')
305
+ raise AuthenticationException.new("", e.response.code, get_oauth_error("Invalid client ID in OAuth request", error_code, error_desc))
306
+ elsif (error_code == 'unauthorized_client')
307
+ raise AuthenticationException.new("", e.response.code, get_oauth_error("Unauthorized client in OAuth request", error_code, error_desc))
308
+ elsif (error_code == 'unsupported_grant_type')
309
+ raise BadRequestException.new("", e.response.code, get_oauth_error("Unsupported grant type in OAuth request", error_code, error_desc))
310
+ elsif (error_code == 'invalid_scope')
311
+ raise BadRequestException.new("", e.response.code, get_oauth_error("Invalid scope in OAuth request", error_code, error_desc))
312
+ else
313
+ raise BadRequestException.new("", e.response.code, get_oauth_error("Unknown OAuth error", error_code, error_desc))
314
+ end
315
+ else
316
+ raise SystemException.new("An unexpected error has been raised. Looks like there's something wrong at our end.", e.response.code, nil)
317
+ end
318
+ end
319
+
320
+ end
321
+
322
+ def self.get_oauth_error(msg, error_code, error_desc)
323
+ error_data = {'error' => {'code' => 'oauth_error', 'message' => "#{msg}, error code '#{error_code}', description '#{error_desc}'"}}
324
+ end
325
+
210
326
  def self.build_url(base_url, type, action, objectMap)
211
327
  parts = []
212
328
  parts << base_url
@@ -256,15 +372,20 @@ module Simplify
256
372
 
257
373
  end
258
374
 
259
- def self.jws_encode(public_key, private_key, url, objectMap, hasPayload)
375
+ def self.jws_encode(auth, url, objectMap, hasPayload)
260
376
 
261
377
  jws_hdr = {'typ' => @@JWS_TYPE,
262
378
  'alg' => @@JWS_ALGORITHM,
263
- 'kid' => public_key,
379
+ 'kid' => auth.public_key,
264
380
  @@JWS_HDR_URI => url,
265
381
  @@JWS_HDR_TIMESTAMP => Time.now.to_i * 1000,
266
382
  @@JWS_HDR_NONCE => SecureRandom.hex }
267
383
 
384
+ token = auth.access_token
385
+ if token != nil && !token.empty?
386
+ jws_hdr[@@JWS_HDR_TOKEN] = token
387
+ end
388
+
268
389
  hdr = urlsafe_encode64(jws_hdr.to_json)
269
390
 
270
391
  payload = ''
@@ -273,19 +394,30 @@ module Simplify
273
394
  end
274
395
 
275
396
  msg = hdr + '.' + payload
276
- return msg + '.' + jws_sign(private_key, msg)
397
+ return msg + '.' + jws_sign(auth.private_key, msg)
277
398
 
278
399
  end
279
400
 
280
- def self.jws_decode(params, public_key, private_key)
401
+ def self.oauth_jws_encode(auth, url, props)
281
402
 
282
- if public_key == nil
283
- raise ArgumentError.new("Must have a valid public key to connect to the API")
284
- end
403
+ jws_hdr = {'typ' => @@JWS_TYPE,
404
+ 'alg' => @@JWS_ALGORITHM,
405
+ 'kid' => auth.public_key,
406
+ @@JWS_HDR_URI => url,
407
+ @@JWS_HDR_TIMESTAMP => Time.now.to_i * 1000,
408
+ @@JWS_HDR_NONCE => SecureRandom.hex }
285
409
 
286
- if private_key == nil
287
- raise ArgumentError.new("Must have a valid API key to connect to the API")
288
- end
410
+ hdr = urlsafe_encode64(jws_hdr.to_json)
411
+
412
+ msg = hdr + '.' + urlsafe_encode64(props.map{|k,v| "#{k}=#{v}"}.join('&'))
413
+
414
+ return msg + '.' + jws_sign(auth.private_key, msg)
415
+
416
+ end
417
+
418
+ def self.jws_decode(params, auth)
419
+
420
+ check_auth(auth)
289
421
 
290
422
  payload = params['payload']
291
423
  if payload == nil
@@ -304,8 +436,8 @@ module Simplify
304
436
  header = urlsafe_decode64(data[0])
305
437
  payload = urlsafe_decode64(data[1])
306
438
 
307
- jws_verify_header(header, params['url'], public_key)
308
- if !jws_verify_signature(private_key, msg, data[2])
439
+ jws_verify_header(header, params['url'], auth.public_key)
440
+ if !jws_verify_signature(auth.private_key, msg, data[2])
309
441
  jws_auth_error("JWS signature does not match")
310
442
  end
311
443
 
data/lib/simplify/plan.rb CHANGED
@@ -33,12 +33,28 @@ module Simplify
33
33
  #
34
34
  class Plan < Hash
35
35
 
36
- # Public key used to access the API.
37
- attr_accessor :public_key
36
+ # Authentication object used to access the API (See Simplify::Authentication for details)
37
+ attr_accessor :authentication
38
38
 
39
- # Private key used to access the API.
40
- attr_accessor :private_key
39
+ # Returns the public key used when accessing this object. <b>Deprecated: please use 'authentication' instead.</b>
40
+ def public_key
41
+ return self.authentication.public_key
42
+ end
41
43
 
44
+ # Sets the public key used when accessing this object. <b>Deprecated: please use 'authentication' instead.</b>
45
+ def public_key=(k)
46
+ return self.authentication.public_key = k
47
+ end
48
+
49
+ # Returns the private key used when accessing this object. <b>Deprecated: please use 'authentication' instead.</b>
50
+ def private_key
51
+ return self.authentication.private_key
52
+ end
53
+
54
+ # Sets the private key used when accessing this object. <b>Deprecated: please use 'authentication' instead.</b>
55
+ def private_key=(k)
56
+ return self.authentication.private_key = k
57
+ end
42
58
 
43
59
 
44
60
  # Creates an Plan object
@@ -48,28 +64,21 @@ class Plan < Hash
48
64
  # * <code>currency</code> Currency code (ISO-4217) for the plan. Must match the currency associated with your account. <b>required </b><b>default:USD</b>
49
65
  # * <code>frequency</code> Frequency of payment for the plan. Example: Monthly <b>required </b>
50
66
  # * <code>name</code> Name of the plan <b>required </b>
51
- # public_key:: Public to use for the API call. If nil, the value of Simplify::public_key will be used.
52
- # private_key:: Private key to use for the API call. If nil, the value of Simplify::private_key will be used.
67
+ # auth:: Authentication information used for the API call. If no value is passed the global keys Simplify::public_key and Simplify::private_key are used. For backwards compatibility the public and private keys may be passed instead of the authentication object.
53
68
  # Returns a Plan object.
54
- def self.create(parms, public_key = nil, private_key = nil)
55
- if public_key == nil then
56
- public_key = Simplify::public_key
57
- end
58
- if private_key == nil then
59
- private_key = Simplify::private_key
60
- end
61
-
62
- h = Simplify::PaymentsApi.execute("plan", 'create', parms, public_key, private_key)
69
+ def self.create(parms, *auth)
70
+
71
+ auth_obj = Simplify::PaymentsApi.create_auth_object(auth)
72
+ h = Simplify::PaymentsApi.execute("plan", 'create', parms, auth_obj)
63
73
  obj = Plan.new()
64
- obj.public_key = public_key
65
- obj.private_key = private_key
66
- obj = obj.merge(h)
74
+ obj.authentication = auth_obj
75
+ obj = obj.merge!(h)
67
76
  obj
68
77
  end
69
78
 
70
79
  # Delete this object
71
80
  def delete()
72
- h = Simplify::PaymentsApi.execute("plan", 'delete', self, self.public_key, self.private_key)
81
+ h = Simplify::PaymentsApi.execute("plan", 'delete', self, self.authentication)
73
82
  self.merge!(h)
74
83
  self
75
84
  end
@@ -80,24 +89,16 @@ class Plan < Hash
80
89
  # * <code>max</code> Allows up to a max of 50 list items to return. <b>default:20</b>
81
90
  # * <code>offset</code> Used in paging of the list. This is the start offset of the page. <b>default:0</b>
82
91
  # * <code>sorting</code> Allows for ascending or descending sorting of the list. The value maps properties to the sort direction (either <code>asc</code> for ascending or <code>desc</code> for descending). Sortable properties are: <code> dateCreated</code><code> amount</code><code> frequency</code><code> name</code><code> id</code>.
83
- # public_key:: Public to use for the API call. If nil, the value of Simplify::public_key will be used.
84
- # private_key:: Private key to use for the API call. If nil, the value of Simplify::private_key will be used.
92
+ # auth:: Authentication information used for the API call. If no value is passed the global keys Simplify::public_key and Simplify::private_key are used. For backwards compatibility the public and private keys may be passed instead of the authentication object.
85
93
  # Returns an object where the <code>list</code> property contains the list of Plan objects and the <code>total</code>
86
94
  # property contains the total number of Plan objects available for the given criteria.
87
- def self.list(criteria = nil, public_key = nil, private_key = nil)
95
+ def self.list(criteria = nil, *auth)
88
96
 
89
- if public_key == nil then
90
- public_key = Simplify::public_key
91
- end
92
- if private_key == nil then
93
- private_key = Simplify::private_key
94
- end
95
-
96
- h = Simplify::PaymentsApi.execute("plan", 'list', criteria, public_key, private_key)
97
+ auth_obj = Simplify::PaymentsApi.create_auth_object(auth)
98
+ h = Simplify::PaymentsApi.execute("plan", 'list', criteria, auth_obj)
97
99
  obj = Plan.new()
98
- obj.public_key = public_key
99
- obj.private_key = private_key
100
- obj = obj.merge(h)
100
+ obj.authentication = auth_obj
101
+ obj = obj.merge!(h)
101
102
  obj
102
103
 
103
104
  end
@@ -105,22 +106,15 @@ class Plan < Hash
105
106
  # Retrieve a Plan object from the API
106
107
  #
107
108
  # id:: ID of object to retrieve
108
- # public_key:: Public to use for the API call. If nil, the value of Simplify::public_key will be used.
109
- # private_key:: Private key to use for the API call. If nil, the value of Simplify::private_key will be used.
109
+ # auth:: Authentication information used for the API call. If no value is passed the global keys Simplify::public_key and Simplify::private_key are used. For backwards compatibility the public and private keys may be passed instead of the authentication object.
110
110
  # Returns a Plan object.
111
- def self.find(id, public_key = nil, private_key = nil)
112
- if public_key == nil then
113
- public_key = Simplify::public_key
114
- end
115
- if private_key == nil then
116
- private_key = Simplify::private_key
117
- end
118
-
119
- h = Simplify::PaymentsApi.execute("plan", 'show', {"id" => id}, public_key, private_key)
111
+ def self.find(id, *auth)
112
+
113
+ auth_obj = Simplify::PaymentsApi.create_auth_object(auth)
114
+ h = Simplify::PaymentsApi.execute("plan", 'show', {"id" => id}, auth_obj)
120
115
  obj = Plan.new()
121
- obj.public_key = public_key
122
- obj.private_key = private_key
123
- obj = obj.merge(h)
116
+ obj.authentication = auth_obj
117
+ obj = obj.merge!(h)
124
118
  obj
125
119
  end
126
120
 
@@ -129,7 +123,7 @@ class Plan < Hash
129
123
  # The properties that can be updated:
130
124
  # * <code>name</code> Name of the plan. <b>(required)</b>
131
125
  def update()
132
- h = Simplify::PaymentsApi.execute("plan", 'update', self, self.public_key, self.private_key)
126
+ h = Simplify::PaymentsApi.execute("plan", 'update', self, self.authentication)
133
127
  self.merge!(h)
134
128
  self
135
129
  end