Skip to content

Commit 3231bab

Browse files
Manuel HuezManuel Huez
authored andcommitted
Fix function name & improve addon support
1 parent dc9f147 commit 3231bab

File tree

8 files changed

+149
-65
lines changed

8 files changed

+149
-65
lines changed

processout/addon.py

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -277,15 +277,44 @@ def fill_with_data(self, data):
277277

278278
return self
279279

280-
def apply(self, subscription_id, options = {}):
281-
"""Apply a new addon to the given subscription ID.
280+
def fetch_subscription_addons(self, subscription_id, options = {}):
281+
"""Get the addons applied to the subscription.
282282
Keyword argument:
283283
subscription_id -- ID of the subscription
284284
options -- Options for the request"""
285285
self.fill_with_data(options)
286286

287287
request = Request(self._client)
288288
path = "/subscriptions/" + quote_plus(subscription_id) + "/addons"
289+
data = {
290+
291+
}
292+
293+
response = Response(request.get(path, data, options))
294+
return_values = []
295+
296+
a = []
297+
body = response.body
298+
for v in body['addons']:
299+
tmp = processout.Addon(self._client)
300+
tmp.fill_with_data(v)
301+
a.append(tmp)
302+
303+
return_values.append(a)
304+
305+
306+
307+
return return_values[0]
308+
309+
def create(self, options = {}):
310+
"""Create a new addon to the given subscription ID.
311+
Keyword argument:
312+
313+
options -- Options for the request"""
314+
self.fill_with_data(options)
315+
316+
request = Request(self._client)
317+
path = "/subscriptions/" + quote_plus(self.subscription_id) + "/addons"
289318
data = {
290319
'plan_id': self.plan_id,
291320
'type': self.type,
@@ -374,16 +403,15 @@ def save(self, options = {}):
374403

375404
return return_values[0]
376405

377-
def remove(self, subscription_id, addon_id, options = {}):
378-
"""Remove an addon applied to a subscription.
406+
def delete(self, options = {}):
407+
"""Delete an addon applied to a subscription.
379408
Keyword argument:
380-
subscription_id -- ID of the subscription on which the addon was applied
381-
addon_id -- ID of the addon
409+
382410
options -- Options for the request"""
383411
self.fill_with_data(options)
384412

385413
request = Request(self._client)
386-
path = "/subscriptions/" + quote_plus(subscription_id) + "/addons/" + quote_plus(addon_id) + ""
414+
path = "/subscriptions/" + quote_plus(self.subscription_id) + "/addons/" + quote_plus(self.id) + ""
387415
data = {
388416
'prorate': options.get("prorate"),
389417
'proration_date': options.get("proration_date"),

processout/authorizationrequest.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -317,21 +317,21 @@ def fetch_customer(self, options = {}):
317317

318318
return return_values[0]
319319

320-
def create(self, customer_id, options = {}):
320+
def create(self, options = {}):
321321
"""Create a new authorization request for the given customer ID.
322322
Keyword argument:
323-
customer_id -- ID of the customer
323+
324324
options -- Options for the request"""
325325
self.fill_with_data(options)
326326

327327
request = Request(self._client)
328328
path = "/authorization-requests"
329329
data = {
330+
'customer_id': self.customer_id,
330331
'name': self.name,
331332
'currency': self.currency,
332333
'return_url': self.return_url,
333-
'cancel_url': self.cancel_url,
334-
'customer_id': customer_id
334+
'cancel_url': self.cancel_url
335335
}
336336

337337
response = Response(request.post(path, data, options))

processout/discount.py

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -277,15 +277,44 @@ def fill_with_data(self, data):
277277

278278
return self
279279

280-
def apply(self, subscription_id, options = {}):
281-
"""Apply a new discount to the given subscription ID.
280+
def fetch_subscription_discounts(self, subscription_id, options = {}):
281+
"""Get the discounts applied to the subscription.
282282
Keyword argument:
283283
subscription_id -- ID of the subscription
284284
options -- Options for the request"""
285285
self.fill_with_data(options)
286286

287287
request = Request(self._client)
288288
path = "/subscriptions/" + quote_plus(subscription_id) + "/discounts"
289+
data = {
290+
291+
}
292+
293+
response = Response(request.get(path, data, options))
294+
return_values = []
295+
296+
a = []
297+
body = response.body
298+
for v in body['discounts']:
299+
tmp = processout.Discount(self._client)
300+
tmp.fill_with_data(v)
301+
a.append(tmp)
302+
303+
return_values.append(a)
304+
305+
306+
307+
return return_values[0]
308+
309+
def create(self, options = {}):
310+
"""Create a new discount for the given subscription ID.
311+
Keyword argument:
312+
313+
options -- Options for the request"""
314+
self.fill_with_data(options)
315+
316+
request = Request(self._client)
317+
path = "/subscriptions/" + quote_plus(self.subscription_id) + "/discounts"
289318
data = {
290319
'coupon_id': self.coupon_id,
291320
'name': self.name,
@@ -335,16 +364,15 @@ def find(self, subscription_id, discount_id, options = {}):
335364

336365
return return_values[0]
337366

338-
def remove(self, subscription_id, discount_id, options = {}):
339-
"""Remove a discount applied to a subscription.
367+
def delete(self, options = {}):
368+
"""Delete a discount applied to a subscription.
340369
Keyword argument:
341-
subscription_id -- ID of the subscription on which the discount was applied
342-
discount_id -- ID of the discount
370+
343371
options -- Options for the request"""
344372
self.fill_with_data(options)
345373

346374
request = Request(self._client)
347-
path = "/subscriptions/" + quote_plus(subscription_id) + "/discounts/" + quote_plus(discount_id) + ""
375+
path = "/subscriptions/" + quote_plus(self.subscription_id) + "/discounts/" + quote_plus(self.id) + ""
348376
data = {
349377

350378
}

processout/refund.py

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,35 @@ def fill_with_data(self, data):
195195

196196
return self
197197

198+
def fetch_transaction_refunds(self, transaction_id, options = {}):
199+
"""Get the transaction's refunds.
200+
Keyword argument:
201+
transaction_id -- ID of the transaction
202+
options -- Options for the request"""
203+
self.fill_with_data(options)
204+
205+
request = Request(self._client)
206+
path = "/transactions/" + quote_plus(transaction_id) + "/refunds"
207+
data = {
208+
209+
}
210+
211+
response = Response(request.get(path, data, options))
212+
return_values = []
213+
214+
a = []
215+
body = response.body
216+
for v in body['refunds']:
217+
tmp = processout.Refund(self._client)
218+
tmp.fill_with_data(v)
219+
a.append(tmp)
220+
221+
return_values.append(a)
222+
223+
224+
225+
return return_values[0]
226+
198227
def find(self, transaction_id, refund_id, options = {}):
199228
"""Find a transaction's refund by its ID.
200229
Keyword argument:
@@ -223,15 +252,15 @@ def find(self, transaction_id, refund_id, options = {}):
223252

224253
return return_values[0]
225254

226-
def apply(self, transaction_id, options = {}):
227-
"""Apply a refund to a transaction.
255+
def create(self, options = {}):
256+
"""Create a refund for a transaction.
228257
Keyword argument:
229-
transaction_id -- ID of the transaction
258+
230259
options -- Options for the request"""
231260
self.fill_with_data(options)
232261

233262
request = Request(self._client)
234-
path = "/transactions/" + quote_plus(transaction_id) + "/refunds"
263+
path = "/transactions/" + quote_plus(self.transaction_id) + "/refunds"
235264
data = {
236265
'amount': self.amount,
237266
'metadata': self.metadata,

processout/subscription.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -711,8 +711,8 @@ def find_addon(self, addon_id, options = {}):
711711

712712
return return_values[0]
713713

714-
def remove_addon(self, addon_id, options = {}):
715-
"""Remove an addon applied to a subscription.
714+
def delete_addon(self, addon_id, options = {}):
715+
"""Delete an addon applied to a subscription.
716716
Keyword argument:
717717
addon_id -- ID of the addon or plan to be removed from the subscription
718718
options -- Options for the request"""
@@ -811,8 +811,8 @@ def find_discount(self, discount_id, options = {}):
811811

812812
return return_values[0]
813813

814-
def remove_discount(self, discount_id, options = {}):
815-
"""Remove a discount applied to a subscription.
814+
def delete_discount(self, discount_id, options = {}):
815+
"""Delete a discount applied to a subscription.
816816
Keyword argument:
817817
discount_id -- ID of the discount or coupon to be removed from the subscription
818818
options -- Options for the request"""
@@ -890,10 +890,10 @@ def all(self, options = {}):
890890

891891
return return_values[0]
892892

893-
def create(self, customer_id, options = {}):
893+
def create(self, options = {}):
894894
"""Create a new subscription for the given customer.
895895
Keyword argument:
896-
customer_id -- ID of the customer
896+
897897
options -- Options for the request"""
898898
self.fill_with_data(options)
899899

@@ -908,11 +908,11 @@ def create(self, customer_id, options = {}):
908908
'metadata': self.metadata,
909909
'interval': self.interval,
910910
'trial_end_at': self.trial_end_at,
911+
'customer_id': self.customer_id,
911912
'return_url': self.return_url,
912913
'cancel_url': self.cancel_url,
913914
'source': options.get("source"),
914-
'coupon_id': options.get("coupon_id"),
915-
'customer_id': customer_id
915+
'coupon_id': options.get("coupon_id")
916916
}
917917

918918
response = Response(request.post(path, data, options))
@@ -991,19 +991,19 @@ def save(self, options = {}):
991991

992992
return return_values[0]
993993

994-
def cancel(self, cancellation_reason, options = {}):
994+
def cancel(self, options = {}):
995995
"""Cancel a subscription. The reason may be provided as well.
996996
Keyword argument:
997-
cancellation_reason -- Cancellation reason
997+
998998
options -- Options for the request"""
999999
self.fill_with_data(options)
10001000

10011001
request = Request(self._client)
10021002
path = "/subscriptions/" + quote_plus(self.id) + ""
10031003
data = {
10041004
'cancel_at': self.cancel_at,
1005-
'cancel_at_end': options.get("cancel_at_end"),
1006-
'cancellation_reason': cancellation_reason
1005+
'cancellation_reason': self.cancellation_reason,
1006+
'cancel_at_end': options.get("cancel_at_end")
10071007
}
10081008

10091009
response = Response(request.delete(path, data, options))

processout/token.py

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -245,80 +245,78 @@ def fill_with_data(self, data):
245245

246246
return self
247247

248-
def find(self, customer_id, token_id, options = {}):
249-
"""Find a customer's token by its ID.
248+
def fetch_customer_tokens(self, customer_id, options = {}):
249+
"""Get the customer's tokens.
250250
Keyword argument:
251251
customer_id -- ID of the customer
252-
token_id -- ID of the token
253252
options -- Options for the request"""
254253
self.fill_with_data(options)
255254

256255
request = Request(self._client)
257-
path = "/customers/" + quote_plus(customer_id) + "/tokens/" + quote_plus(token_id) + ""
256+
path = "/customers/" + quote_plus(customer_id) + "/tokens"
258257
data = {
259258

260259
}
261260

262261
response = Response(request.get(path, data, options))
263262
return_values = []
264263

264+
a = []
265265
body = response.body
266-
body = body["token"]
267-
268-
269-
obj = processout.Token(self._client)
270-
return_values.append(obj.fill_with_data(body))
271-
266+
for v in body['tokens']:
267+
tmp = processout.Token(self._client)
268+
tmp.fill_with_data(v)
269+
a.append(tmp)
270+
271+
return_values.append(a)
272+
272273

273274

274275
return return_values[0]
275276

276-
def create(self, customer_id, source, options = {}):
277-
"""Create a new token for the given customer ID.
277+
def find(self, customer_id, token_id, options = {}):
278+
"""Find a customer's token by its ID.
278279
Keyword argument:
279280
customer_id -- ID of the customer
280-
source -- Source used to create the token (most likely a card token generated by ProcessOut.js)
281+
token_id -- ID of the token
281282
options -- Options for the request"""
282283
self.fill_with_data(options)
283284

284285
request = Request(self._client)
285-
path = "/customers/" + quote_plus(customer_id) + "/tokens"
286+
path = "/customers/" + quote_plus(customer_id) + "/tokens/" + quote_plus(token_id) + ""
286287
data = {
287-
'metadata': self.metadata,
288-
'settings': options.get("settings"),
289-
'target': options.get("target"),
290-
'source': source
288+
291289
}
292290

293-
response = Response(request.post(path, data, options))
291+
response = Response(request.get(path, data, options))
294292
return_values = []
295293

296294
body = response.body
297295
body = body["token"]
298296

299297

300-
return_values.append(self.fill_with_data(body))
298+
obj = processout.Token(self._client)
299+
return_values.append(obj.fill_with_data(body))
301300

302301

303302

304303
return return_values[0]
305304

306-
def create_from_request(self, customer_id, source, target, options = {}):
307-
"""Create a new token for the given customer ID from an authorization request
305+
def create(self, options = {}):
306+
"""Create a new token for the given customer ID.
308307
Keyword argument:
309-
customer_id -- ID of the customer
310-
source -- Source used to create the token (most likely a card token generated by ProcessOut.js)
311-
target -- Authorization request ID
308+
312309
options -- Options for the request"""
313310
self.fill_with_data(options)
314311

315312
request = Request(self._client)
316-
path = "/customers/" + quote_plus(customer_id) + "/tokens"
313+
path = "/customers/" + quote_plus(self.customer_id) + "/tokens"
317314
data = {
318315
'metadata': self.metadata,
316+
'source': options.get("source"),
319317
'settings': options.get("settings"),
320-
'source': source,
321-
'target': target
318+
'target': options.get("target"),
319+
'set_default': options.get("set_default")
322320
}
323321

324322
response = Response(request.post(path, data, options))

0 commit comments

Comments
 (0)