simplify 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/simplify.rb CHANGED
@@ -25,6 +25,8 @@
25
25
  # SUCH DAMAGE.
26
26
  #
27
27
 
28
+ require File.dirname(__FILE__) + '/simplify/authentication'
29
+ require File.dirname(__FILE__) + '/simplify/accesstoken'
28
30
  require File.dirname(__FILE__) + '/simplify/cardtoken'
29
31
  require File.dirname(__FILE__) + '/simplify/chargeback'
30
32
  require File.dirname(__FILE__) + '/simplify/coupon'
@@ -0,0 +1,111 @@
1
+ #
2
+ # Copyright (c) 2013, MasterCard International Incorporated
3
+ # All rights reserved.
4
+ #
5
+ # Redistribution and use in source and binary forms, with or without modification, are
6
+ # permitted provided that the following conditions are met:
7
+ #
8
+ # Redistributions of source code must retain the above copyright notice, this list of
9
+ # conditions and the following disclaimer.
10
+ # Redistributions in binary form must reproduce the above copyright notice, this list of
11
+ # conditions and the following disclaimer in the documentation and/or other materials
12
+ # provided with the distribution.
13
+ # Neither the name of the MasterCard International Incorporated nor the names of its
14
+ # contributors may be used to endorse or promote products derived from this software
15
+ # without specific prior written permission.
16
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
17
+ # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18
+ # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
19
+ # SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20
+ # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
21
+ # TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22
+ # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
23
+ # IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
24
+ # IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25
+ # SUCH DAMAGE.
26
+ #
27
+
28
+ module Simplify
29
+
30
+ require 'uri'
31
+
32
+ # An OAuth access token.
33
+ class AccessToken < Hash
34
+
35
+ #
36
+ # Construct a AccessToken from a hash.
37
+ #
38
+ def initialize(options = {})
39
+ self.merge!(options)
40
+ end
41
+
42
+
43
+ # Creates an OAuth access token object.
44
+ #
45
+ # auth_code: The OAuth authentication code.
46
+ # redirect_uri: The OAuth redirection URI.
47
+ # 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.
48
+ #
49
+ def self.create(auth_code, redirect_uri, *auth)
50
+
51
+ props = {
52
+ 'grant_type' => 'authorization_code',
53
+ 'code' => auth_code,
54
+ 'redirect_uri' => redirect_uri
55
+ }
56
+
57
+ h = Simplify::PaymentsApi.send_auth_request(props, 'token', Simplify::PaymentsApi.create_auth_object(auth))
58
+
59
+ obj = AccessToken.new()
60
+ obj = obj.merge!(h)
61
+
62
+ obj
63
+
64
+ end
65
+
66
+
67
+ # Refreshes the OAuth access token
68
+ #
69
+ # 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.
70
+ #
71
+ def refresh(*auth)
72
+
73
+ rt = self['refresh_token']
74
+ if rt == nil || rt.empty?
75
+ raise ArgumentError.new("Cannot refresh access token; refresh token is invalid.")
76
+ end
77
+
78
+ props = {
79
+ 'grant_type' => 'refresh_token',
80
+ 'refresh_token' => rt
81
+ }
82
+
83
+ h = Simplify::PaymentsApi.send_auth_request(props, 'token', Simplify::PaymentsApi.create_auth_object(auth))
84
+
85
+ self.merge!(h)
86
+ self
87
+ end
88
+
89
+
90
+ # Revokes the access token.
91
+ #
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.
93
+ #
94
+ def revoke(*auth)
95
+
96
+ token = self['access_token']
97
+ if token == nil || token.empty?
98
+ raise ArgumentError.new("Cannot revoke access token; access token is invalid.")
99
+ end
100
+
101
+ props = {
102
+ 'token' => token
103
+ }
104
+
105
+ h = Simplify::PaymentsApi.send_auth_request(props, 'revoke', Simplify::PaymentsApi.create_auth_object(auth))
106
+ self.clear
107
+ self
108
+ end
109
+
110
+ end
111
+ end
@@ -0,0 +1,64 @@
1
+ #
2
+ # Copyright (c) 2013, MasterCard International Incorporated
3
+ # All rights reserved.
4
+ #
5
+ # Redistribution and use in source and binary forms, with or without modification, are
6
+ # permitted provided that the following conditions are met:
7
+ #
8
+ # Redistributions of source code must retain the above copyright notice, this list of
9
+ # conditions and the following disclaimer.
10
+ # Redistributions in binary form must reproduce the above copyright notice, this list of
11
+ # conditions and the following disclaimer in the documentation and/or other materials
12
+ # provided with the distribution.
13
+ # Neither the name of the MasterCard International Incorporated nor the names of its
14
+ # contributors may be used to endorse or promote products derived from this software
15
+ # without specific prior written permission.
16
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
17
+ # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18
+ # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
19
+ # SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20
+ # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
21
+ # TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22
+ # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
23
+ # IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
24
+ # IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25
+ # SUCH DAMAGE.
26
+ #
27
+
28
+ module Simplify
29
+
30
+ # Holds Authentication information used when accessing the API
31
+ class Authentication
32
+
33
+ # Public key used to access the API.
34
+ attr_accessor :public_key
35
+
36
+ # Private key used to access the API.
37
+ attr_accessor :private_key
38
+
39
+ # OAuth token used to access the API.
40
+ attr_accessor :access_token
41
+
42
+ # Creates an Authentication object.
43
+ #
44
+ # options:: hash containing information to initialise the object. Valid options are :public_key, :private_key and :access_token.
45
+ # If no value for public_key is passed or the value is nil then Simplify::public_key is used. If no value for private_key is
46
+ # passed or the value is nil then Simplify::private_key is used.
47
+ #
48
+ def initialize(options = {})
49
+
50
+ @public_key = options[:public_key]
51
+ if @public_key == nil
52
+ @public_key = Simplify::public_key
53
+ end
54
+
55
+ @private_key = options[:private_key]
56
+ if private_key == nil
57
+ @private_key = Simplify::private_key
58
+ end
59
+
60
+ @access_token = options[:access_token]
61
+ end
62
+
63
+ end
64
+ end
@@ -33,12 +33,28 @@ module Simplify
33
33
  #
34
34
  class CardToken < 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
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
41
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 CardToken object
@@ -57,44 +73,30 @@ class CardToken < Hash
57
73
  # * <code>card => name</code> Name as appears on the card.
58
74
  # * <code>card => number</code> Card number as it appears on the card. <b>required </b>
59
75
  # * <code>key</code> Key used to create the card token.
60
- # public_key:: Public to use for the API call. If nil, the value of Simplify::public_key will be used.
61
- # private_key:: Private key to use for the API call. If nil, the value of Simplify::private_key will be used.
76
+ # 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.
62
77
  # Returns a CardToken object.
63
- def self.create(parms, public_key = nil, private_key = nil)
64
- if public_key == nil then
65
- public_key = Simplify::public_key
66
- end
67
- if private_key == nil then
68
- private_key = Simplify::private_key
69
- end
78
+ def self.create(parms, *auth)
70
79
 
71
- h = Simplify::PaymentsApi.execute("cardToken", 'create', parms, public_key, private_key)
80
+ auth_obj = Simplify::PaymentsApi.create_auth_object(auth)
81
+ h = Simplify::PaymentsApi.execute("cardToken", 'create', parms, auth_obj)
72
82
  obj = CardToken.new()
73
- obj.public_key = public_key
74
- obj.private_key = private_key
75
- obj = obj.merge(h)
83
+ obj.authentication = auth_obj
84
+ obj = obj.merge!(h)
76
85
  obj
77
86
  end
78
87
 
79
88
  # Retrieve a CardToken object from the API
80
89
  #
81
90
  # id:: ID of object to retrieve
82
- # public_key:: Public to use for the API call. If nil, the value of Simplify::public_key will be used.
83
- # private_key:: Private key to use for the API call. If nil, the value of Simplify::private_key will be used.
91
+ # 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.
84
92
  # Returns a CardToken object.
85
- def self.find(id, public_key = nil, private_key = nil)
86
- if public_key == nil then
87
- public_key = Simplify::public_key
88
- end
89
- if private_key == nil then
90
- private_key = Simplify::private_key
91
- end
93
+ def self.find(id, *auth)
92
94
 
93
- h = Simplify::PaymentsApi.execute("cardToken", 'show', {"id" => id}, public_key, private_key)
95
+ auth_obj = Simplify::PaymentsApi.create_auth_object(auth)
96
+ h = Simplify::PaymentsApi.execute("cardToken", 'show', {"id" => id}, auth_obj)
94
97
  obj = CardToken.new()
95
- obj.public_key = public_key
96
- obj.private_key = private_key
97
- obj = obj.merge(h)
98
+ obj.authentication = auth_obj
99
+ obj = obj.merge!(h)
98
100
  obj
99
101
  end
100
102
 
@@ -33,12 +33,28 @@ module Simplify
33
33
  #
34
34
  class Chargeback < 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
  # Retrieve Chargeback objects.
@@ -46,25 +62,17 @@ class Chargeback < Hash
46
62
  # * <code>filter</code> Filters to apply to the list.
47
63
  # * <code>max</code> Allows up to a max of 50 list items to return. <b>default:20</b>
48
64
  # * <code>offset</code> Used in paging of the list. This is the start offset of the page. <b>default:0</b>
49
- # * <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> id</code><code> amount</code><code> description</code><code> dateCreated</code><code> paymentDate</code>.
50
- # public_key:: Public to use for the API call. If nil, the value of Simplify::public_key will be used.
51
- # private_key:: Private key to use for the API call. If nil, the value of Simplify::private_key will be used.
65
+ # * <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> id</code><code> amount</code><code> description</code><code> dateCreated</code>.
66
+ # 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.
52
67
  # Returns an object where the <code>list</code> property contains the list of Chargeback objects and the <code>total</code>
53
68
  # property contains the total number of Chargeback objects available for the given criteria.
54
- def self.list(criteria = nil, public_key = nil, private_key = nil)
55
-
56
- if public_key == nil then
57
- public_key = Simplify::public_key
58
- end
59
- if private_key == nil then
60
- private_key = Simplify::private_key
61
- end
69
+ def self.list(criteria = nil, *auth)
62
70
 
63
- h = Simplify::PaymentsApi.execute("chargeback", 'list', criteria, public_key, private_key)
71
+ auth_obj = Simplify::PaymentsApi.create_auth_object(auth)
72
+ h = Simplify::PaymentsApi.execute("chargeback", 'list', criteria, auth_obj)
64
73
  obj = Chargeback.new()
65
- obj.public_key = public_key
66
- obj.private_key = private_key
67
- obj = obj.merge(h)
74
+ obj.authentication = auth_obj
75
+ obj = obj.merge!(h)
68
76
  obj
69
77
 
70
78
  end
@@ -72,22 +80,15 @@ class Chargeback < Hash
72
80
  # Retrieve a Chargeback object from the API
73
81
  #
74
82
  # id:: ID of object to retrieve
75
- # public_key:: Public to use for the API call. If nil, the value of Simplify::public_key will be used.
76
- # private_key:: Private key to use for the API call. If nil, the value of Simplify::private_key will be used.
83
+ # 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.
77
84
  # Returns a Chargeback object.
78
- def self.find(id, public_key = nil, private_key = nil)
79
- if public_key == nil then
80
- public_key = Simplify::public_key
81
- end
82
- if private_key == nil then
83
- private_key = Simplify::private_key
84
- end
85
+ def self.find(id, *auth)
85
86
 
86
- h = Simplify::PaymentsApi.execute("chargeback", 'show', {"id" => id}, public_key, private_key)
87
+ auth_obj = Simplify::PaymentsApi.create_auth_object(auth)
88
+ h = Simplify::PaymentsApi.execute("chargeback", 'show', {"id" => id}, auth_obj)
87
89
  obj = Chargeback.new()
88
- obj.public_key = public_key
89
- obj.private_key = private_key
90
- obj = obj.merge(h)
90
+ obj.authentication = auth_obj
91
+ obj = obj.merge!(h)
91
92
  obj
92
93
  end
93
94
 
@@ -30,10 +30,10 @@ module Simplify
30
30
  # Constants.
31
31
  class Constants
32
32
 
33
- @@version = '1.0.1'
33
+ @@version = '1.1.0'
34
34
  @@api_base_live_url = 'https://api.simplify.com/v1/api'
35
35
  @@api_base_sandbox_url = 'https://sandbox.simplify.com/v1/api'
36
-
36
+ @@oauth_base_url = 'https://www.simplify.com/commerce/oauth';
37
37
 
38
38
  # Returns the base URL for the live API.
39
39
  def self.api_base_live_url
@@ -45,12 +45,16 @@ module Simplify
45
45
  @@api_base_sandbox_url
46
46
  end
47
47
 
48
+ # Returns the base URL for OAuth.
49
+ def self.oauth_base_url
50
+ @@oauth_base_url
51
+ end
52
+
48
53
  # Returns the SDK version.
49
54
  def self.version
50
- @@version
55
+ @@version
51
56
  end
52
57
 
53
-
54
58
  end
55
59
  end
56
60
 
@@ -33,12 +33,28 @@ module Simplify
33
33
  #
34
34
  class Coupon < 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 Coupon object
@@ -52,28 +68,21 @@ class Coupon < Hash
52
68
  # * <code>maxRedemptions</code> Maximum number of redemptions allowed for the coupon. A redemption is defined as when the coupon is applied to the subscription for the first time.
53
69
  # * <code>percentOff</code> Percentage off of the price of the product. While this field is optional, you must provide either amountOff or percentOff for a coupon. The percent off is a whole number.
54
70
  # * <code>startDate</code> First date of the coupon in UTC millis that the coupon can be applied to a subscription. This starts at midnight of the merchant timezone. <b>required </b>
55
- # public_key:: Public to use for the API call. If nil, the value of Simplify::public_key will be used.
56
- # private_key:: Private key to use for the API call. If nil, the value of Simplify::private_key will be used.
71
+ # 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.
57
72
  # Returns a Coupon object.
58
- def self.create(parms, public_key = nil, private_key = nil)
59
- if public_key == nil then
60
- public_key = Simplify::public_key
61
- end
62
- if private_key == nil then
63
- private_key = Simplify::private_key
64
- end
65
-
66
- h = Simplify::PaymentsApi.execute("coupon", 'create', parms, public_key, private_key)
73
+ def self.create(parms, *auth)
74
+
75
+ auth_obj = Simplify::PaymentsApi.create_auth_object(auth)
76
+ h = Simplify::PaymentsApi.execute("coupon", 'create', parms, auth_obj)
67
77
  obj = Coupon.new()
68
- obj.public_key = public_key
69
- obj.private_key = private_key
70
- obj = obj.merge(h)
78
+ obj.authentication = auth_obj
79
+ obj = obj.merge!(h)
71
80
  obj
72
81
  end
73
82
 
74
83
  # Delete this object
75
84
  def delete()
76
- h = Simplify::PaymentsApi.execute("coupon", 'delete', self, self.public_key, self.private_key)
85
+ h = Simplify::PaymentsApi.execute("coupon", 'delete', self, self.authentication)
77
86
  self.merge!(h)
78
87
  self
79
88
  end
@@ -84,24 +93,16 @@ class Coupon < Hash
84
93
  # * <code>max</code> Allows up to a max of 50 list items to return. <b>default:20</b>
85
94
  # * <code>offset</code> Used in paging of the list. This is the start offset of the page. <b>default:0</b>
86
95
  # * <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> maxRedemptions</code><code> timesRedeemed</code><code> id</code><code> startDate</code><code> endDate</code><code> percentOff</code><code> couponCode</code><code> durationInMonths</code><code> amountOff</code>.
87
- # public_key:: Public to use for the API call. If nil, the value of Simplify::public_key will be used.
88
- # private_key:: Private key to use for the API call. If nil, the value of Simplify::private_key will be used.
96
+ # 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.
89
97
  # Returns an object where the <code>list</code> property contains the list of Coupon objects and the <code>total</code>
90
98
  # property contains the total number of Coupon objects available for the given criteria.
91
- def self.list(criteria = nil, public_key = nil, private_key = nil)
99
+ def self.list(criteria = nil, *auth)
92
100
 
93
- if public_key == nil then
94
- public_key = Simplify::public_key
95
- end
96
- if private_key == nil then
97
- private_key = Simplify::private_key
98
- end
99
-
100
- h = Simplify::PaymentsApi.execute("coupon", 'list', criteria, public_key, private_key)
101
+ auth_obj = Simplify::PaymentsApi.create_auth_object(auth)
102
+ h = Simplify::PaymentsApi.execute("coupon", 'list', criteria, auth_obj)
101
103
  obj = Coupon.new()
102
- obj.public_key = public_key
103
- obj.private_key = private_key
104
- obj = obj.merge(h)
104
+ obj.authentication = auth_obj
105
+ obj = obj.merge!(h)
105
106
  obj
106
107
 
107
108
  end
@@ -109,22 +110,15 @@ class Coupon < Hash
109
110
  # Retrieve a Coupon object from the API
110
111
  #
111
112
  # id:: ID of object to retrieve
112
- # public_key:: Public to use for the API call. If nil, the value of Simplify::public_key will be used.
113
- # private_key:: Private key to use for the API call. If nil, the value of Simplify::private_key will be used.
113
+ # 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.
114
114
  # Returns a Coupon object.
115
- def self.find(id, public_key = nil, private_key = nil)
116
- if public_key == nil then
117
- public_key = Simplify::public_key
118
- end
119
- if private_key == nil then
120
- private_key = Simplify::private_key
121
- end
122
-
123
- h = Simplify::PaymentsApi.execute("coupon", 'show', {"id" => id}, public_key, private_key)
115
+ def self.find(id, *auth)
116
+
117
+ auth_obj = Simplify::PaymentsApi.create_auth_object(auth)
118
+ h = Simplify::PaymentsApi.execute("coupon", 'show', {"id" => id}, auth_obj)
124
119
  obj = Coupon.new()
125
- obj.public_key = public_key
126
- obj.private_key = private_key
127
- obj = obj.merge(h)
120
+ obj.authentication = auth_obj
121
+ obj = obj.merge!(h)
128
122
  obj
129
123
  end
130
124
 
@@ -134,7 +128,7 @@ class Coupon < Hash
134
128
  # * <code>endDate</code> The ending date in UTC millis for the coupon. This must be after the starting date of the coupon.
135
129
  # * <code>maxRedemptions</code> Maximum number of redemptions allowed for the coupon. A redemption is defined as when the coupon is applied to the subscription for the first time.
136
130
  def update()
137
- h = Simplify::PaymentsApi.execute("coupon", 'update', self, self.public_key, self.private_key)
131
+ h = Simplify::PaymentsApi.execute("coupon", 'update', self, self.authentication)
138
132
  self.merge!(h)
139
133
  self
140
134
  end