processout 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +10 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/deploy.sh +25 -0
- data/lib/processout.rb +130 -0
- data/lib/processout/activity.rb +147 -0
- data/lib/processout/authorization_request.rb +248 -0
- data/lib/processout/card.rb +156 -0
- data/lib/processout/coupon.rb +284 -0
- data/lib/processout/customer.rb +418 -0
- data/lib/processout/customer_action.rb +50 -0
- data/lib/processout/discount.rb +217 -0
- data/lib/processout/errors/authentication_error.rb +7 -0
- data/lib/processout/errors/generic_error.rb +7 -0
- data/lib/processout/errors/internal_error.rb +7 -0
- data/lib/processout/errors/notfound_error.rb +7 -0
- data/lib/processout/errors/validation_error.rb +7 -0
- data/lib/processout/event.rb +176 -0
- data/lib/processout/gateway.rb +104 -0
- data/lib/processout/gateway_configuration.rb +91 -0
- data/lib/processout/invoice.rb +457 -0
- data/lib/processout/networking/request.rb +95 -0
- data/lib/processout/networking/response.rb +61 -0
- data/lib/processout/plan.rb +280 -0
- data/lib/processout/product.rb +313 -0
- data/lib/processout/project.rb +105 -0
- data/lib/processout/refund.rb +161 -0
- data/lib/processout/subscription.rb +633 -0
- data/lib/processout/token.rb +167 -0
- data/lib/processout/transaction.rb +302 -0
- data/lib/processout/version.rb +3 -0
- data/lib/processout/webhook.rb +154 -0
- data/processout.gemspec +26 -0
- metadata +125 -0
@@ -0,0 +1,105 @@
|
|
1
|
+
# The content of this file was automatically generated
|
2
|
+
|
3
|
+
require "cgi"
|
4
|
+
require "processout/networking/request"
|
5
|
+
require "processout/networking/response"
|
6
|
+
|
7
|
+
module ProcessOut
|
8
|
+
class Project
|
9
|
+
|
10
|
+
attr_reader :id
|
11
|
+
attr_reader :name
|
12
|
+
attr_reader :logo_url
|
13
|
+
attr_reader :email
|
14
|
+
attr_reader :created_at
|
15
|
+
|
16
|
+
|
17
|
+
def id=(val)
|
18
|
+
@id = val
|
19
|
+
end
|
20
|
+
|
21
|
+
def name=(val)
|
22
|
+
@name = val
|
23
|
+
end
|
24
|
+
|
25
|
+
def logo_url=(val)
|
26
|
+
@logo_url = val
|
27
|
+
end
|
28
|
+
|
29
|
+
def email=(val)
|
30
|
+
@email = val
|
31
|
+
end
|
32
|
+
|
33
|
+
def created_at=(val)
|
34
|
+
@created_at = val
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
# Initializes the Project object
|
39
|
+
# Params:
|
40
|
+
# +client+:: +ProcessOut+ client instance
|
41
|
+
def initialize(client)
|
42
|
+
@client = client
|
43
|
+
|
44
|
+
@id = ""
|
45
|
+
@name = ""
|
46
|
+
@logo_url = ""
|
47
|
+
@email = ""
|
48
|
+
@created_at = ""
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
# Fills the object with data coming from the API
|
53
|
+
# Params:
|
54
|
+
# +data+:: +Hash+ of data coming from the API
|
55
|
+
def fill_with_data(data)
|
56
|
+
if data.include? "id"
|
57
|
+
@id = data["id"]
|
58
|
+
end
|
59
|
+
if data.include? "name"
|
60
|
+
@name = data["name"]
|
61
|
+
end
|
62
|
+
if data.include? "logo_url"
|
63
|
+
@logo_url = data["logo_url"]
|
64
|
+
end
|
65
|
+
if data.include? "email"
|
66
|
+
@email = data["email"]
|
67
|
+
end
|
68
|
+
if data.include? "created_at"
|
69
|
+
@created_at = data["created_at"]
|
70
|
+
end
|
71
|
+
|
72
|
+
self
|
73
|
+
end
|
74
|
+
|
75
|
+
# Get all the gateway configurations of the project
|
76
|
+
# Params:
|
77
|
+
# +options+:: +Hash+ of options
|
78
|
+
def gateway_configurations(options = nil)
|
79
|
+
request = Request.new(@client)
|
80
|
+
path = "/projects/" + CGI.escape(@id) + "/gateway-configurations"
|
81
|
+
data = {
|
82
|
+
|
83
|
+
}
|
84
|
+
|
85
|
+
response = Response.new(request.get(path, data, options))
|
86
|
+
return_values = Array.new
|
87
|
+
|
88
|
+
a = Array.new
|
89
|
+
body = response.body
|
90
|
+
for v in body['gateway_configurations']
|
91
|
+
tmp = GatewayConfiguration(@client)
|
92
|
+
tmp.fill_with_data(v)
|
93
|
+
a.push(tmp)
|
94
|
+
end
|
95
|
+
|
96
|
+
return_values.push(a)
|
97
|
+
|
98
|
+
|
99
|
+
|
100
|
+
return_values[0]
|
101
|
+
end
|
102
|
+
|
103
|
+
|
104
|
+
end
|
105
|
+
end
|
@@ -0,0 +1,161 @@
|
|
1
|
+
# The content of this file was automatically generated
|
2
|
+
|
3
|
+
require "cgi"
|
4
|
+
require "processout/networking/request"
|
5
|
+
require "processout/networking/response"
|
6
|
+
|
7
|
+
module ProcessOut
|
8
|
+
class Refund
|
9
|
+
|
10
|
+
attr_reader :id
|
11
|
+
attr_reader :transaction
|
12
|
+
attr_reader :reason
|
13
|
+
attr_reader :information
|
14
|
+
attr_reader :amount
|
15
|
+
attr_reader :metadata
|
16
|
+
attr_reader :sandbox
|
17
|
+
attr_reader :created_at
|
18
|
+
|
19
|
+
|
20
|
+
def id=(val)
|
21
|
+
@id = val
|
22
|
+
end
|
23
|
+
|
24
|
+
def transaction=(val)
|
25
|
+
if val.instance_of? Transaction
|
26
|
+
@transaction = val
|
27
|
+
else
|
28
|
+
obj = Transaction.new(@client)
|
29
|
+
obj.fill_with_data(val)
|
30
|
+
@transaction = obj
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
def reason=(val)
|
36
|
+
@reason = val
|
37
|
+
end
|
38
|
+
|
39
|
+
def information=(val)
|
40
|
+
@information = val
|
41
|
+
end
|
42
|
+
|
43
|
+
def amount=(val)
|
44
|
+
@amount = val
|
45
|
+
end
|
46
|
+
|
47
|
+
def metadata=(val)
|
48
|
+
@metadata = val
|
49
|
+
end
|
50
|
+
|
51
|
+
def sandbox=(val)
|
52
|
+
@sandbox = val
|
53
|
+
end
|
54
|
+
|
55
|
+
def created_at=(val)
|
56
|
+
@created_at = val
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
# Initializes the Refund object
|
61
|
+
# Params:
|
62
|
+
# +client+:: +ProcessOut+ client instance
|
63
|
+
def initialize(client)
|
64
|
+
@client = client
|
65
|
+
|
66
|
+
@id = ""
|
67
|
+
@transaction = nil
|
68
|
+
@reason = ""
|
69
|
+
@information = ""
|
70
|
+
@amount = ""
|
71
|
+
@metadata = Hash.new
|
72
|
+
@sandbox = false
|
73
|
+
@created_at = ""
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
# Fills the object with data coming from the API
|
78
|
+
# Params:
|
79
|
+
# +data+:: +Hash+ of data coming from the API
|
80
|
+
def fill_with_data(data)
|
81
|
+
if data.include? "id"
|
82
|
+
@id = data["id"]
|
83
|
+
end
|
84
|
+
if data.include? "transaction"
|
85
|
+
@transaction = data["transaction"]
|
86
|
+
end
|
87
|
+
if data.include? "reason"
|
88
|
+
@reason = data["reason"]
|
89
|
+
end
|
90
|
+
if data.include? "information"
|
91
|
+
@information = data["information"]
|
92
|
+
end
|
93
|
+
if data.include? "amount"
|
94
|
+
@amount = data["amount"]
|
95
|
+
end
|
96
|
+
if data.include? "metadata"
|
97
|
+
@metadata = data["metadata"]
|
98
|
+
end
|
99
|
+
if data.include? "sandbox"
|
100
|
+
@sandbox = data["sandbox"]
|
101
|
+
end
|
102
|
+
if data.include? "created_at"
|
103
|
+
@created_at = data["created_at"]
|
104
|
+
end
|
105
|
+
|
106
|
+
self
|
107
|
+
end
|
108
|
+
|
109
|
+
# Find a transaction's refund by its ID.
|
110
|
+
# Params:
|
111
|
+
# +transaction_id+:: ID of the transaction
|
112
|
+
# +refund_id+:: ID of the refund
|
113
|
+
# +options+:: +Hash+ of options
|
114
|
+
def find(transaction_id, refund_id, options = nil)
|
115
|
+
request = Request.new(@client)
|
116
|
+
path = "/transactions/" + CGI.escape(transaction_id) + "/refunds/" + CGI.escape(refund_id) + ""
|
117
|
+
data = {
|
118
|
+
|
119
|
+
}
|
120
|
+
|
121
|
+
response = Response.new(request.get(path, data, options))
|
122
|
+
return_values = Array.new
|
123
|
+
|
124
|
+
body = response.body
|
125
|
+
body = body["refund"]
|
126
|
+
|
127
|
+
|
128
|
+
obj = Refund.new(@client)
|
129
|
+
return_values.push(obj.fill_with_data(body))
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
return_values[0]
|
134
|
+
end
|
135
|
+
|
136
|
+
# Apply a refund to a transaction.
|
137
|
+
# Params:
|
138
|
+
# +transaction_id+:: ID of the transaction
|
139
|
+
# +options+:: +Hash+ of options
|
140
|
+
def apply(transaction_id, options = nil)
|
141
|
+
request = Request.new(@client)
|
142
|
+
path = "/transactions/" + CGI.escape(transaction_id) + "/refunds"
|
143
|
+
data = {
|
144
|
+
"amount": @amount,
|
145
|
+
"metadata": @metadata,
|
146
|
+
"reason": @reason,
|
147
|
+
"information": @information
|
148
|
+
}
|
149
|
+
|
150
|
+
response = Response.new(request.post(path, data, options))
|
151
|
+
return_values = Array.new
|
152
|
+
|
153
|
+
return_values.push(response.success)
|
154
|
+
|
155
|
+
|
156
|
+
return_values[0]
|
157
|
+
end
|
158
|
+
|
159
|
+
|
160
|
+
end
|
161
|
+
end
|
@@ -0,0 +1,633 @@
|
|
1
|
+
# The content of this file was automatically generated
|
2
|
+
|
3
|
+
require "cgi"
|
4
|
+
require "processout/networking/request"
|
5
|
+
require "processout/networking/response"
|
6
|
+
|
7
|
+
module ProcessOut
|
8
|
+
class Subscription
|
9
|
+
|
10
|
+
attr_reader :id
|
11
|
+
attr_reader :project
|
12
|
+
attr_reader :plan
|
13
|
+
attr_reader :customer
|
14
|
+
attr_reader :token
|
15
|
+
attr_reader :url
|
16
|
+
attr_reader :name
|
17
|
+
attr_reader :amount
|
18
|
+
attr_reader :currency
|
19
|
+
attr_reader :metadata
|
20
|
+
attr_reader :interval
|
21
|
+
attr_reader :trial_end_at
|
22
|
+
attr_reader :activated
|
23
|
+
attr_reader :active
|
24
|
+
attr_reader :canceled
|
25
|
+
attr_reader :cancellation_reason
|
26
|
+
attr_reader :pending_cancellation
|
27
|
+
attr_reader :cancel_at
|
28
|
+
attr_reader :return_url
|
29
|
+
attr_reader :cancel_url
|
30
|
+
attr_reader :sandbox
|
31
|
+
attr_reader :created_at
|
32
|
+
attr_reader :activated_at
|
33
|
+
attr_reader :iterate_at
|
34
|
+
|
35
|
+
|
36
|
+
def id=(val)
|
37
|
+
@id = val
|
38
|
+
end
|
39
|
+
|
40
|
+
def project=(val)
|
41
|
+
if val.instance_of? Project
|
42
|
+
@project = val
|
43
|
+
else
|
44
|
+
obj = Project.new(@client)
|
45
|
+
obj.fill_with_data(val)
|
46
|
+
@project = obj
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
def plan=(val)
|
52
|
+
if val.instance_of? Plan
|
53
|
+
@plan = val
|
54
|
+
else
|
55
|
+
obj = Plan.new(@client)
|
56
|
+
obj.fill_with_data(val)
|
57
|
+
@plan = obj
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
def customer=(val)
|
63
|
+
if val.instance_of? Customer
|
64
|
+
@customer = val
|
65
|
+
else
|
66
|
+
obj = Customer.new(@client)
|
67
|
+
obj.fill_with_data(val)
|
68
|
+
@customer = obj
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
def token=(val)
|
74
|
+
if val.instance_of? Token
|
75
|
+
@token = val
|
76
|
+
else
|
77
|
+
obj = Token.new(@client)
|
78
|
+
obj.fill_with_data(val)
|
79
|
+
@token = obj
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
|
84
|
+
def url=(val)
|
85
|
+
@url = val
|
86
|
+
end
|
87
|
+
|
88
|
+
def name=(val)
|
89
|
+
@name = val
|
90
|
+
end
|
91
|
+
|
92
|
+
def amount=(val)
|
93
|
+
@amount = val
|
94
|
+
end
|
95
|
+
|
96
|
+
def currency=(val)
|
97
|
+
@currency = val
|
98
|
+
end
|
99
|
+
|
100
|
+
def metadata=(val)
|
101
|
+
@metadata = val
|
102
|
+
end
|
103
|
+
|
104
|
+
def interval=(val)
|
105
|
+
@interval = val
|
106
|
+
end
|
107
|
+
|
108
|
+
def trial_end_at=(val)
|
109
|
+
@trial_end_at = val
|
110
|
+
end
|
111
|
+
|
112
|
+
def activated=(val)
|
113
|
+
@activated = val
|
114
|
+
end
|
115
|
+
|
116
|
+
def active=(val)
|
117
|
+
@active = val
|
118
|
+
end
|
119
|
+
|
120
|
+
def canceled=(val)
|
121
|
+
@canceled = val
|
122
|
+
end
|
123
|
+
|
124
|
+
def cancellation_reason=(val)
|
125
|
+
@cancellation_reason = val
|
126
|
+
end
|
127
|
+
|
128
|
+
def pending_cancellation=(val)
|
129
|
+
@pending_cancellation = val
|
130
|
+
end
|
131
|
+
|
132
|
+
def cancel_at=(val)
|
133
|
+
@cancel_at = val
|
134
|
+
end
|
135
|
+
|
136
|
+
def return_url=(val)
|
137
|
+
@return_url = val
|
138
|
+
end
|
139
|
+
|
140
|
+
def cancel_url=(val)
|
141
|
+
@cancel_url = val
|
142
|
+
end
|
143
|
+
|
144
|
+
def sandbox=(val)
|
145
|
+
@sandbox = val
|
146
|
+
end
|
147
|
+
|
148
|
+
def created_at=(val)
|
149
|
+
@created_at = val
|
150
|
+
end
|
151
|
+
|
152
|
+
def activated_at=(val)
|
153
|
+
@activated_at = val
|
154
|
+
end
|
155
|
+
|
156
|
+
def iterate_at=(val)
|
157
|
+
@iterate_at = val
|
158
|
+
end
|
159
|
+
|
160
|
+
|
161
|
+
# Initializes the Subscription object
|
162
|
+
# Params:
|
163
|
+
# +client+:: +ProcessOut+ client instance
|
164
|
+
def initialize(client)
|
165
|
+
@client = client
|
166
|
+
|
167
|
+
@id = ""
|
168
|
+
@project = nil
|
169
|
+
@plan = nil
|
170
|
+
@customer = nil
|
171
|
+
@token = nil
|
172
|
+
@url = ""
|
173
|
+
@name = ""
|
174
|
+
@amount = ""
|
175
|
+
@currency = ""
|
176
|
+
@metadata = Hash.new
|
177
|
+
@interval = ""
|
178
|
+
@trial_end_at = ""
|
179
|
+
@activated = false
|
180
|
+
@active = false
|
181
|
+
@canceled = false
|
182
|
+
@cancellation_reason = ""
|
183
|
+
@pending_cancellation = false
|
184
|
+
@cancel_at = ""
|
185
|
+
@return_url = ""
|
186
|
+
@cancel_url = ""
|
187
|
+
@sandbox = false
|
188
|
+
@created_at = ""
|
189
|
+
@activated_at = ""
|
190
|
+
@iterate_at = ""
|
191
|
+
|
192
|
+
end
|
193
|
+
|
194
|
+
# Fills the object with data coming from the API
|
195
|
+
# Params:
|
196
|
+
# +data+:: +Hash+ of data coming from the API
|
197
|
+
def fill_with_data(data)
|
198
|
+
if data.include? "id"
|
199
|
+
@id = data["id"]
|
200
|
+
end
|
201
|
+
if data.include? "project"
|
202
|
+
@project = data["project"]
|
203
|
+
end
|
204
|
+
if data.include? "plan"
|
205
|
+
@plan = data["plan"]
|
206
|
+
end
|
207
|
+
if data.include? "customer"
|
208
|
+
@customer = data["customer"]
|
209
|
+
end
|
210
|
+
if data.include? "token"
|
211
|
+
@token = data["token"]
|
212
|
+
end
|
213
|
+
if data.include? "url"
|
214
|
+
@url = data["url"]
|
215
|
+
end
|
216
|
+
if data.include? "name"
|
217
|
+
@name = data["name"]
|
218
|
+
end
|
219
|
+
if data.include? "amount"
|
220
|
+
@amount = data["amount"]
|
221
|
+
end
|
222
|
+
if data.include? "currency"
|
223
|
+
@currency = data["currency"]
|
224
|
+
end
|
225
|
+
if data.include? "metadata"
|
226
|
+
@metadata = data["metadata"]
|
227
|
+
end
|
228
|
+
if data.include? "interval"
|
229
|
+
@interval = data["interval"]
|
230
|
+
end
|
231
|
+
if data.include? "trial_end_at"
|
232
|
+
@trial_end_at = data["trial_end_at"]
|
233
|
+
end
|
234
|
+
if data.include? "activated"
|
235
|
+
@activated = data["activated"]
|
236
|
+
end
|
237
|
+
if data.include? "active"
|
238
|
+
@active = data["active"]
|
239
|
+
end
|
240
|
+
if data.include? "canceled"
|
241
|
+
@canceled = data["canceled"]
|
242
|
+
end
|
243
|
+
if data.include? "cancellation_reason"
|
244
|
+
@cancellation_reason = data["cancellation_reason"]
|
245
|
+
end
|
246
|
+
if data.include? "pending_cancellation"
|
247
|
+
@pending_cancellation = data["pending_cancellation"]
|
248
|
+
end
|
249
|
+
if data.include? "cancel_at"
|
250
|
+
@cancel_at = data["cancel_at"]
|
251
|
+
end
|
252
|
+
if data.include? "return_url"
|
253
|
+
@return_url = data["return_url"]
|
254
|
+
end
|
255
|
+
if data.include? "cancel_url"
|
256
|
+
@cancel_url = data["cancel_url"]
|
257
|
+
end
|
258
|
+
if data.include? "sandbox"
|
259
|
+
@sandbox = data["sandbox"]
|
260
|
+
end
|
261
|
+
if data.include? "created_at"
|
262
|
+
@created_at = data["created_at"]
|
263
|
+
end
|
264
|
+
if data.include? "activated_at"
|
265
|
+
@activated_at = data["activated_at"]
|
266
|
+
end
|
267
|
+
if data.include? "iterate_at"
|
268
|
+
@iterate_at = data["iterate_at"]
|
269
|
+
end
|
270
|
+
|
271
|
+
self
|
272
|
+
end
|
273
|
+
|
274
|
+
# Get the customer owning the subscription.
|
275
|
+
# Params:
|
276
|
+
# +options+:: +Hash+ of options
|
277
|
+
def customer(options = nil)
|
278
|
+
request = Request.new(@client)
|
279
|
+
path = "/subscriptions/" + CGI.escape(@id) + "/customers"
|
280
|
+
data = {
|
281
|
+
|
282
|
+
}
|
283
|
+
|
284
|
+
response = Response.new(request.get(path, data, options))
|
285
|
+
return_values = Array.new
|
286
|
+
|
287
|
+
body = response.body
|
288
|
+
body = body["customer"]
|
289
|
+
customer = Customer(self._client)
|
290
|
+
return_values.push(customer.fill_with_data(body))
|
291
|
+
|
292
|
+
|
293
|
+
return_values[0]
|
294
|
+
end
|
295
|
+
|
296
|
+
# Get the discounts applied to the subscription.
|
297
|
+
# Params:
|
298
|
+
# +options+:: +Hash+ of options
|
299
|
+
def discounts(options = nil)
|
300
|
+
request = Request.new(@client)
|
301
|
+
path = "/subscriptions/" + CGI.escape(@id) + "/discounts"
|
302
|
+
data = {
|
303
|
+
|
304
|
+
}
|
305
|
+
|
306
|
+
response = Response.new(request.get(path, data, options))
|
307
|
+
return_values = Array.new
|
308
|
+
|
309
|
+
a = Array.new
|
310
|
+
body = response.body
|
311
|
+
for v in body['discounts']
|
312
|
+
tmp = Discount(@client)
|
313
|
+
tmp.fill_with_data(v)
|
314
|
+
a.push(tmp)
|
315
|
+
end
|
316
|
+
|
317
|
+
return_values.push(a)
|
318
|
+
|
319
|
+
|
320
|
+
|
321
|
+
return_values[0]
|
322
|
+
end
|
323
|
+
|
324
|
+
# Remove a discount applied to a subscription.
|
325
|
+
# Params:
|
326
|
+
# +discount_id+:: ID of the discount or coupon to be removed from the subscription
|
327
|
+
# +options+:: +Hash+ of options
|
328
|
+
def remove_discount(discount_id, options = nil)
|
329
|
+
request = Request.new(@client)
|
330
|
+
path = "/subscriptions/" + CGI.escape(@id) + "/discounts/" + CGI.escape(discount_id) + ""
|
331
|
+
data = {
|
332
|
+
|
333
|
+
}
|
334
|
+
|
335
|
+
response = Response.new(request.delete(path, data, options))
|
336
|
+
return_values = Array.new
|
337
|
+
|
338
|
+
body = response.body
|
339
|
+
body = body["discount"]
|
340
|
+
|
341
|
+
|
342
|
+
return_values.push(self.fill_with_data(body))
|
343
|
+
|
344
|
+
|
345
|
+
|
346
|
+
return_values[0]
|
347
|
+
end
|
348
|
+
|
349
|
+
# Get the subscriptions past transactions.
|
350
|
+
# Params:
|
351
|
+
# +options+:: +Hash+ of options
|
352
|
+
def transactions(options = nil)
|
353
|
+
request = Request.new(@client)
|
354
|
+
path = "/subscriptions/" + CGI.escape(@id) + "/transactions"
|
355
|
+
data = {
|
356
|
+
|
357
|
+
}
|
358
|
+
|
359
|
+
response = Response.new(request.get(path, data, options))
|
360
|
+
return_values = Array.new
|
361
|
+
|
362
|
+
a = Array.new
|
363
|
+
body = response.body
|
364
|
+
for v in body['transactions']
|
365
|
+
tmp = Transaction(@client)
|
366
|
+
tmp.fill_with_data(v)
|
367
|
+
a.push(tmp)
|
368
|
+
end
|
369
|
+
|
370
|
+
return_values.push(a)
|
371
|
+
|
372
|
+
|
373
|
+
|
374
|
+
return_values[0]
|
375
|
+
end
|
376
|
+
|
377
|
+
# Get all the subscriptions.
|
378
|
+
# Params:
|
379
|
+
# +options+:: +Hash+ of options
|
380
|
+
def all(options = nil)
|
381
|
+
request = Request.new(@client)
|
382
|
+
path = "/subscriptions"
|
383
|
+
data = {
|
384
|
+
|
385
|
+
}
|
386
|
+
|
387
|
+
response = Response.new(request.get(path, data, options))
|
388
|
+
return_values = Array.new
|
389
|
+
|
390
|
+
a = Array.new
|
391
|
+
body = response.body
|
392
|
+
for v in body['subscriptions']
|
393
|
+
tmp = Subscription(@client)
|
394
|
+
tmp.fill_with_data(v)
|
395
|
+
a.push(tmp)
|
396
|
+
end
|
397
|
+
|
398
|
+
return_values.push(a)
|
399
|
+
|
400
|
+
|
401
|
+
|
402
|
+
return_values[0]
|
403
|
+
end
|
404
|
+
|
405
|
+
# Create a new subscription for the given customer.
|
406
|
+
# Params:
|
407
|
+
# +customer_id+:: ID of the customer
|
408
|
+
# +options+:: +Hash+ of options
|
409
|
+
def create(customer_id, options = nil)
|
410
|
+
request = Request.new(@client)
|
411
|
+
path = "/subscriptions"
|
412
|
+
data = {
|
413
|
+
"cancel_at": @cancel_at,
|
414
|
+
"name": @name,
|
415
|
+
"amount": @amount,
|
416
|
+
"currency": @currency,
|
417
|
+
"metadata": @metadata,
|
418
|
+
"interval": @interval,
|
419
|
+
"trial_end_at": @trial_end_at,
|
420
|
+
"return_url": @return_url,
|
421
|
+
"cancel_url": @cancel_url,
|
422
|
+
'customer_id': customer_id
|
423
|
+
}
|
424
|
+
|
425
|
+
response = Response.new(request.post(path, data, options))
|
426
|
+
return_values = Array.new
|
427
|
+
|
428
|
+
body = response.body
|
429
|
+
body = body["subscription"]
|
430
|
+
|
431
|
+
|
432
|
+
return_values.push(self.fill_with_data(body))
|
433
|
+
|
434
|
+
|
435
|
+
|
436
|
+
return_values[0]
|
437
|
+
end
|
438
|
+
|
439
|
+
# Create a new subscription for the customer from the given plan ID.
|
440
|
+
# Params:
|
441
|
+
# +customer_id+:: ID of the customer
|
442
|
+
# +plan_id+:: ID of the plan
|
443
|
+
# +options+:: +Hash+ of options
|
444
|
+
def create_from_plan(customer_id, plan_id, options = nil)
|
445
|
+
request = Request.new(@client)
|
446
|
+
path = "/subscriptions"
|
447
|
+
data = {
|
448
|
+
"cancel_at": @cancel_at,
|
449
|
+
"name": @name,
|
450
|
+
"amount": @amount,
|
451
|
+
"currency": @currency,
|
452
|
+
"metadata": @metadata,
|
453
|
+
"interval": @interval,
|
454
|
+
"trial_end_at": @trial_end_at,
|
455
|
+
"return_url": @return_url,
|
456
|
+
"cancel_url": @cancel_url,
|
457
|
+
'customer_id': customer_id,
|
458
|
+
'plan_id': plan_id
|
459
|
+
}
|
460
|
+
|
461
|
+
response = Response.new(request.post(path, data, options))
|
462
|
+
return_values = Array.new
|
463
|
+
|
464
|
+
body = response.body
|
465
|
+
body = body["subscription"]
|
466
|
+
|
467
|
+
|
468
|
+
return_values.push(self.fill_with_data(body))
|
469
|
+
|
470
|
+
|
471
|
+
|
472
|
+
return_values[0]
|
473
|
+
end
|
474
|
+
|
475
|
+
# Find a subscription by its ID.
|
476
|
+
# Params:
|
477
|
+
# +subscription_id+:: ID of the subscription
|
478
|
+
# +options+:: +Hash+ of options
|
479
|
+
def find(subscription_id, options = nil)
|
480
|
+
request = Request.new(@client)
|
481
|
+
path = "/subscriptions/" + CGI.escape(subscription_id) + ""
|
482
|
+
data = {
|
483
|
+
|
484
|
+
}
|
485
|
+
|
486
|
+
response = Response.new(request.get(path, data, options))
|
487
|
+
return_values = Array.new
|
488
|
+
|
489
|
+
body = response.body
|
490
|
+
body = body["subscription"]
|
491
|
+
|
492
|
+
|
493
|
+
obj = Subscription.new(@client)
|
494
|
+
return_values.push(obj.fill_with_data(body))
|
495
|
+
|
496
|
+
|
497
|
+
|
498
|
+
return_values[0]
|
499
|
+
end
|
500
|
+
|
501
|
+
# Update the subscription.
|
502
|
+
# Params:
|
503
|
+
# +prorate+:: Define if proration should be done when updating the plan
|
504
|
+
# +options+:: +Hash+ of options
|
505
|
+
def update(prorate, options = nil)
|
506
|
+
request = Request.new(@client)
|
507
|
+
path = "/subscriptions/" + CGI.escape(@id) + ""
|
508
|
+
data = {
|
509
|
+
"trial_end_at": @trial_end_at,
|
510
|
+
'prorate': prorate
|
511
|
+
}
|
512
|
+
|
513
|
+
response = Response.new(request.put(path, data, options))
|
514
|
+
return_values = Array.new
|
515
|
+
|
516
|
+
body = response.body
|
517
|
+
body = body["subscription"]
|
518
|
+
|
519
|
+
|
520
|
+
return_values.push(self.fill_with_data(body))
|
521
|
+
|
522
|
+
|
523
|
+
|
524
|
+
return_values[0]
|
525
|
+
end
|
526
|
+
|
527
|
+
# Update the subscription's plan.
|
528
|
+
# Params:
|
529
|
+
# +plan_id+:: ID of the new plan to be applied on the subscription
|
530
|
+
# +prorate+:: Define if proration should be done when updating the plan
|
531
|
+
# +options+:: +Hash+ of options
|
532
|
+
def update_plan(plan_id, prorate, options = nil)
|
533
|
+
request = Request.new(@client)
|
534
|
+
path = "/subscriptions/" + CGI.escape(@id) + ""
|
535
|
+
data = {
|
536
|
+
'plan_id': plan_id,
|
537
|
+
'prorate': prorate
|
538
|
+
}
|
539
|
+
|
540
|
+
response = Response.new(request.put(path, data, options))
|
541
|
+
return_values = Array.new
|
542
|
+
|
543
|
+
body = response.body
|
544
|
+
body = body["subscription"]
|
545
|
+
|
546
|
+
|
547
|
+
return_values.push(self.fill_with_data(body))
|
548
|
+
|
549
|
+
|
550
|
+
|
551
|
+
return_values[0]
|
552
|
+
end
|
553
|
+
|
554
|
+
# Apply a source to the subscription to activate or update the subscription's source.
|
555
|
+
# Params:
|
556
|
+
# +source+:: Source to be applied on the subscription and used to pay future invoices. Can be a card, a token or a gateway request
|
557
|
+
# +options+:: +Hash+ of options
|
558
|
+
def apply_source(source, options = nil)
|
559
|
+
request = Request.new(@client)
|
560
|
+
path = "/subscriptions/" + CGI.escape(@id) + ""
|
561
|
+
data = {
|
562
|
+
'source': source
|
563
|
+
}
|
564
|
+
|
565
|
+
response = Response.new(request.put(path, data, options))
|
566
|
+
return_values = Array.new
|
567
|
+
|
568
|
+
body = response.body
|
569
|
+
body = body["subscription"]
|
570
|
+
|
571
|
+
|
572
|
+
return_values.push(self.fill_with_data(body))
|
573
|
+
|
574
|
+
|
575
|
+
|
576
|
+
return_values[0]
|
577
|
+
end
|
578
|
+
|
579
|
+
# Cancel a subscription. The reason may be provided as well.
|
580
|
+
# Params:
|
581
|
+
# +cancellation_reason+:: Cancellation reason
|
582
|
+
# +options+:: +Hash+ of options
|
583
|
+
def cancel(cancellation_reason, options = nil)
|
584
|
+
request = Request.new(@client)
|
585
|
+
path = "/subscriptions/" + CGI.escape(@id) + ""
|
586
|
+
data = {
|
587
|
+
'cancellation_reason': cancellation_reason
|
588
|
+
}
|
589
|
+
|
590
|
+
response = Response.new(request.delete(path, data, options))
|
591
|
+
return_values = Array.new
|
592
|
+
|
593
|
+
body = response.body
|
594
|
+
body = body["subscription"]
|
595
|
+
|
596
|
+
|
597
|
+
return_values.push(self.fill_with_data(body))
|
598
|
+
|
599
|
+
|
600
|
+
|
601
|
+
return_values[0]
|
602
|
+
end
|
603
|
+
|
604
|
+
# Schedule the cancellation of the subscription. The reason may be provided as well.
|
605
|
+
# Params:
|
606
|
+
# +cancel_at+:: Cancellation date, in the form of a string
|
607
|
+
# +cancellation_reason+:: Cancellation reason
|
608
|
+
# +options+:: +Hash+ of options
|
609
|
+
def cancel_at(cancel_at, cancellation_reason, options = nil)
|
610
|
+
request = Request.new(@client)
|
611
|
+
path = "/subscriptions/" + CGI.escape(@id) + ""
|
612
|
+
data = {
|
613
|
+
'cancel_at': cancel_at,
|
614
|
+
'cancellation_reason': cancellation_reason
|
615
|
+
}
|
616
|
+
|
617
|
+
response = Response.new(request.delete(path, data, options))
|
618
|
+
return_values = Array.new
|
619
|
+
|
620
|
+
body = response.body
|
621
|
+
body = body["subscription"]
|
622
|
+
|
623
|
+
|
624
|
+
return_values.push(self.fill_with_data(body))
|
625
|
+
|
626
|
+
|
627
|
+
|
628
|
+
return_values[0]
|
629
|
+
end
|
630
|
+
|
631
|
+
|
632
|
+
end
|
633
|
+
end
|