Skip to content

Commit de521e2

Browse files
ErickColinErick Colin
andauthored
[PAYM-1699] Update SDK for payment link (#58)
* Support creation of a payment link in the SDK. * Update to creation of a payment link in the SDK. * Version number is updated Co-authored-by: Erick Colin <[email protected]>
1 parent e529f0a commit de521e2

File tree

5 files changed

+351
-2
lines changed

5 files changed

+351
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## [2.6.0](https://github.com/conekta/conekta-python/releases/tag/v2.6.0) - 2020-12-30
2+
### Change
3+
- Support creation of a payment link in the SDK.
4+
15
## [2.5.1](https://github.com/conekta/conekta-python/releases/tag/v2.5.1) - 2019-12-31
26
### Change
37
- Adds message field for error object where it was previously missing

conekta/__init__.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
API_VERSION = '2.0.0'
1919

20-
__version__ = '2.5.1'
20+
__version__ = '2.6.0'
2121
__author__ = 'Leo Fischer'
2222

2323
API_BASE = 'https://api.conekta.io/'
@@ -338,6 +338,8 @@ def __init__(self, *args, **kwargs):
338338
charge.payment_method = payment_method
339339
self.charges.append(charge)
340340

341+
if 'checkout' in attributes.keys():
342+
self.checkout = CheckoutOrder(attributes['checkout'])
341343

342344
def capture(self, params={}, api_key=None):
343345
order = Order.load_url("%s/capture" % (self.instance_url()), 'PUT', params, api_key=api_key)
@@ -393,6 +395,11 @@ def createDiscountLine(self, params, api_key=None):
393395
self.discount_lines.append(discount_line)
394396
return discount_line
395397

398+
def createCheckout(self, params, api_key=None):
399+
checkout = CheckoutOrder(DiscountLine.load_url("%s/orders" % self.instance_url(), 'POST', params, api_key=api_key))
400+
self.checkout.append(checkout)
401+
return checkout
402+
396403
class CustomerInfo(_UpdatableResource): pass
397404

398405
class OrderReturns(_UpdatableResource): pass
@@ -455,6 +462,23 @@ def default_card(self):
455462
else:
456463
return None
457464

465+
class Checkout(_CreatableResource, _UpdatableResource, _DeletableResource, _FindableResource):
466+
467+
def __init__(self, *args, **kwargs):
468+
super(Checkouts, self).__init__(*args, **kwargs)
469+
470+
def create(self, params, api_key=None):
471+
return self.load_via_http_request("%s/checkouts" % self.instance_url(), 'POST', params, api_key=api_key)
472+
473+
def cancel(self, params, api_key=None):
474+
return self.load_via_http_request("%s/checkouts/cancel/%s" % (self.instance_url(), self.id), 'PUT', None, api_key=api_key)
475+
476+
def sendEmail(self, params, api_key=None):
477+
return self.load_via_http_request("%s/checkouts/email" % self.instance_url(), 'POST', params, api_key=api_key)
478+
479+
def sendSms(self, params, api_key=None):
480+
return self.load_via_http_request("%s/checkouts/sms" % self.instance_url(), 'POST', params, api_key=api_key)
481+
458482
class Event(_FindableResource): pass
459483

460484
class Log(_FindableResource): pass
@@ -598,3 +622,8 @@ def delete(self, params={}, api_key=None):
598622
def events(self, params={}, api_key=None):
599623
uri = "%s/shipping_contacts/%s/events" % (self.parent.instance_url(), self.id)
600624
return Event(Event.load_url(uri, 'GET', params, api_key=api_key))
625+
626+
class CheckoutOrder(_CreatableResource, _UpdatableResource, _DeletableResource, _FindableResource):
627+
628+
def instance_url(self):
629+
return "orders"

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from setuptools import setup, find_packages
66

7-
version = "2.5.1"
7+
version = "2.6.0"
88
author = "Conekta"
99

1010
setup(

tests/__init__.py

Lines changed: 216 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,5 +302,221 @@ class BaseEndpointTestCase(unittest.TestCase):
302302
"country": "CA",
303303
"postal_code": "T4N 0B8"
304304
}
305+
}
306+
307+
checkout_object = {
308+
"name": "Payment Link Name",
309+
"type": "PaymentLink",
310+
"recurrent": False,
311+
"expired_at": 1590882634,
312+
"allowed_payment_methods": ["cash", "card", "bank_transfer"],
313+
"needs_shipping_contact": True,
314+
"monthly_installments_enabled": False,
315+
"monthly_installments_options": [3, 6, 9, 12],
316+
"order_template": {
317+
"line_items": [{
318+
"name": "Red Wine",
319+
"unit_price": 1000,
320+
"quantity": 10
321+
}],
322+
"currency": "MXN",
323+
"customer_info": {
324+
"name": "Juan Perez",
325+
"email": "[email protected]",
326+
"phone": "5566982090"
327+
}
328+
}
329+
}
330+
331+
checkout_object_multiple = {
332+
"name": "Payment Link Name",
333+
"type": "PaymentLink",
334+
"recurrent": True,
335+
"expired_at": 1590882634,
336+
"allowed_payment_methods": ["cash", "card", "bank_transfer"],
337+
"needs_shipping_contact": True,
338+
"monthly_installments_enabled": False,
339+
"monthly_installments_options": [3, 6, 9, 12],
340+
"order_template": {
341+
"line_items": [{
342+
"name": "Red Wine",
343+
"unit_price": 1000,
344+
"quantity": 10
345+
}],
346+
"currency": "MXN",
347+
"customer_info": {
348+
"name": "Juan Perez",
349+
"email": "[email protected]",
350+
"phone": "5566982090"
351+
}
352+
}
353+
}
354+
355+
checkout_object_msi = {
356+
"name": "Payment Link Name",
357+
"type": "PaymentLink",
358+
"recurrent": True,
359+
"expired_at": 1590882634,
360+
"allowed_payment_methods": ["cash", "card", "bank_transfer"],
361+
"needs_shipping_contact": True,
362+
"monthly_installments_enabled": True,
363+
"monthly_installments_options": [3, 6, 9, 12],
364+
"order_template": {
365+
"line_items": [{
366+
"name": "Red Wine",
367+
"unit_price": 1000,
368+
"quantity": 10
369+
}],
370+
"currency": "MXN",
371+
"customer_info": {
372+
"name": "Juan Perez",
373+
"email": "[email protected]",
374+
"phone": "5566982090"
375+
}
376+
}
377+
}
305378

379+
checkout_object_type_checkout = {
380+
"name": "Payment Link Name",
381+
"type": "checkout",
382+
"recurrent": True,
383+
"expired_at": 1590882634,
384+
"allowed_payment_methods": ["cash", "card", "bank_transfer"],
385+
"needs_shipping_contact": True,
386+
"monthly_installments_enabled": True,
387+
"monthly_installments_options": [3, 6, 9, 12],
388+
"order_template": {
389+
"line_items": [{
390+
"name": "Red Wine",
391+
"unit_price": 1000,
392+
"quantity": 10
393+
}],
394+
"currency": "MXN",
395+
"customer_info": {
396+
"name": "Juan Perez",
397+
"email": "[email protected]",
398+
"phone": "5566982090"
399+
}
400+
}
306401
}
402+
403+
checkout_object_send = {
404+
"id": "05b25724-df59-4925-8762-105d627875fd"
405+
"name": "Payment Link Name",
406+
"type": "checkout",
407+
"recurrent": True,
408+
"expired_at": 1590882634,
409+
"allowed_payment_methods": ["cash", "card", "bank_transfer"],
410+
"needs_shipping_contact": True,
411+
"monthly_installments_enabled": True,
412+
"monthly_installments_options": [3, 6, 9, 12],
413+
"order_template": {
414+
"line_items": [{
415+
"name": "Red Wine",
416+
"unit_price": 1000,
417+
"quantity": 10
418+
}],
419+
"currency": "MXN",
420+
"customer_info": {
421+
"name": "Juan Perez",
422+
"email": "[email protected]",
423+
"phone": "5566982090"
424+
}
425+
}
426+
}
427+
428+
429+
checkout_order_object =
430+
"currency": "MXN",
431+
"customer_info": {
432+
"customer_id": "cus_2o3FvMEBiKitVK1vQ"
433+
},
434+
"line_items": [{
435+
"name": "Box of Cohiba S1s",
436+
"unit_price": 300000,
437+
"quantity": 1
438+
}],
439+
"shipping_lines": [{
440+
"amount": 0
441+
}],
442+
"checkout": {
443+
"allowed_payment_methods": ["cash", "card", "bank_transfer"],
444+
"multifactor_authentication": False,
445+
"monthly_installments_enabled": False,
446+
"monthly_installments_options": [3,6,9,12,18],
447+
"expires_at": 1609891200
448+
},
449+
"shipping_contact": {
450+
"phone": "+5215555555555",
451+
"receiver": "Marvin Fuller",
452+
"address": {
453+
"street1": "Nuevo Leon 4",
454+
"country": "MX",
455+
"postal_code": "06100"
456+
}
457+
}
458+
459+
checkout_msi_order__object =
460+
"currency": "MXN",
461+
"customer_info": {
462+
"customer_id": "cus_2o3FvMEBiKitVK1vQ"
463+
},
464+
"line_items": [{
465+
"name": "Box of Cohiba S1s",
466+
"unit_price": 300000,
467+
"quantity": 1
468+
}],
469+
"shipping_lines": [{
470+
"amount": 0
471+
}],
472+
"checkout": {
473+
"type":"Integration",
474+
"allowed_payment_methods": ["cash", "card", "bank_transfer"],
475+
"multifactor_authentication": False,
476+
"monthly_installments_enabled": True,
477+
"monthly_installments_options": [3,6,9,12,18],
478+
"expires_at": 1609891200
479+
},
480+
"shipping_contact": {
481+
"phone": "+5215555555555",
482+
"receiver": "Marvin Fuller",
483+
"address": {
484+
"street1": "Nuevo Leon 4",
485+
"country": "MX",
486+
"postal_code": "06100"
487+
}
488+
}
489+
490+
491+
checkout_order__redirect_object =
492+
"currency": "MXN",
493+
"customer_info": {
494+
"customer_id": "cus_2o3FvMEBiKitVK1vQ"
495+
},
496+
"line_items": [{
497+
"name": "Box of Cohiba S1s",
498+
"unit_price": 300000,
499+
"quantity": 1
500+
}],
501+
"shipping_lines": [{
502+
"amount": 0
503+
}],
504+
"checkout": {
505+
"type":"HostedPayment",
506+
"success_url": "testredirect.com",
507+
"failure_url": "testredirect.com",
508+
"allowed_payment_methods": ["cash", "card", "bank_transfer"],
509+
"multifactor_authentication": False,
510+
"monthly_installments_enabled": False,
511+
"monthly_installments_options": [3,6,9,12,18],
512+
"expires_at": 1609891200
513+
},
514+
"shipping_contact": {
515+
"phone": "+5215555555555",
516+
"receiver": "Marvin Fuller",
517+
"address": {
518+
"street1": "Nuevo Leon 4",
519+
"country": "MX",
520+
"postal_code": "06100"
521+
}
522+
}

0 commit comments

Comments
 (0)