Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PAYM-1699] Update SDK for payment link #58

Merged
merged 3 commits into from
Feb 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## [2.6.0](https://github.com/conekta/conekta-python/releases/tag/v2.6.0) - 2020-12-30
### Change
- Support creation of a payment link in the SDK.

## [2.5.1](https://github.com/conekta/conekta-python/releases/tag/v2.5.1) - 2019-12-31
### Change
- Adds message field for error object where it was previously missing
Expand Down
31 changes: 30 additions & 1 deletion conekta/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

API_VERSION = '2.0.0'

__version__ = '2.5.1'
__version__ = '2.6.0'
__author__ = 'Leo Fischer'

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

if 'checkout' in attributes.keys():
self.checkout = CheckoutOrder(attributes['checkout'])

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

def createCheckout(self, params, api_key=None):
checkout = CheckoutOrder(DiscountLine.load_url("%s/orders" % self.instance_url(), 'POST', params, api_key=api_key))
self.checkout.append(checkout)
return checkout

class CustomerInfo(_UpdatableResource): pass

class OrderReturns(_UpdatableResource): pass
Expand Down Expand Up @@ -455,6 +462,23 @@ def default_card(self):
else:
return None

class Checkout(_CreatableResource, _UpdatableResource, _DeletableResource, _FindableResource):

def __init__(self, *args, **kwargs):
super(Checkouts, self).__init__(*args, **kwargs)

def create(self, params, api_key=None):
return self.load_via_http_request("%s/checkouts" % self.instance_url(), 'POST', params, api_key=api_key)

def cancel(self, params, api_key=None):
return self.load_via_http_request("%s/checkouts/cancel/%s" % (self.instance_url(), self.id), 'PUT', None, api_key=api_key)

def sendEmail(self, params, api_key=None):
return self.load_via_http_request("%s/checkouts/email" % self.instance_url(), 'POST', params, api_key=api_key)

def sendSms(self, params, api_key=None):
return self.load_via_http_request("%s/checkouts/sms" % self.instance_url(), 'POST', params, api_key=api_key)

class Event(_FindableResource): pass

class Log(_FindableResource): pass
Expand Down Expand Up @@ -598,3 +622,8 @@ def delete(self, params={}, api_key=None):
def events(self, params={}, api_key=None):
uri = "%s/shipping_contacts/%s/events" % (self.parent.instance_url(), self.id)
return Event(Event.load_url(uri, 'GET', params, api_key=api_key))

class CheckoutOrder(_CreatableResource, _UpdatableResource, _DeletableResource, _FindableResource):

def instance_url(self):
return "orders"
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from setuptools import setup, find_packages

version = "2.5.1"
version = "2.6.0"
author = "Conekta"

setup(
Expand Down
216 changes: 216 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,5 +302,221 @@ class BaseEndpointTestCase(unittest.TestCase):
"country": "CA",
"postal_code": "T4N 0B8"
}
}

checkout_object = {
"name": "Payment Link Name",
"type": "PaymentLink",
"recurrent": False,
"expired_at": 1590882634,
"allowed_payment_methods": ["cash", "card", "bank_transfer"],
"needs_shipping_contact": True,
"monthly_installments_enabled": False,
"monthly_installments_options": [3, 6, 9, 12],
"order_template": {
"line_items": [{
"name": "Red Wine",
"unit_price": 1000,
"quantity": 10
}],
"currency": "MXN",
"customer_info": {
"name": "Juan Perez",
"email": "test@conekta.com",
"phone": "5566982090"
}
}
}

checkout_object_multiple = {
"name": "Payment Link Name",
"type": "PaymentLink",
"recurrent": True,
"expired_at": 1590882634,
"allowed_payment_methods": ["cash", "card", "bank_transfer"],
"needs_shipping_contact": True,
"monthly_installments_enabled": False,
"monthly_installments_options": [3, 6, 9, 12],
"order_template": {
"line_items": [{
"name": "Red Wine",
"unit_price": 1000,
"quantity": 10
}],
"currency": "MXN",
"customer_info": {
"name": "Juan Perez",
"email": "test@conekta.com",
"phone": "5566982090"
}
}
}

checkout_object_msi = {
"name": "Payment Link Name",
"type": "PaymentLink",
"recurrent": True,
"expired_at": 1590882634,
"allowed_payment_methods": ["cash", "card", "bank_transfer"],
"needs_shipping_contact": True,
"monthly_installments_enabled": True,
"monthly_installments_options": [3, 6, 9, 12],
"order_template": {
"line_items": [{
"name": "Red Wine",
"unit_price": 1000,
"quantity": 10
}],
"currency": "MXN",
"customer_info": {
"name": "Juan Perez",
"email": "test@conekta.com",
"phone": "5566982090"
}
}
}

checkout_object_type_checkout = {
"name": "Payment Link Name",
"type": "checkout",
"recurrent": True,
"expired_at": 1590882634,
"allowed_payment_methods": ["cash", "card", "bank_transfer"],
"needs_shipping_contact": True,
"monthly_installments_enabled": True,
"monthly_installments_options": [3, 6, 9, 12],
"order_template": {
"line_items": [{
"name": "Red Wine",
"unit_price": 1000,
"quantity": 10
}],
"currency": "MXN",
"customer_info": {
"name": "Juan Perez",
"email": "test@conekta.com",
"phone": "5566982090"
}
}
}

checkout_object_send = {
"id": "05b25724-df59-4925-8762-105d627875fd"
"name": "Payment Link Name",
"type": "checkout",
"recurrent": True,
"expired_at": 1590882634,
"allowed_payment_methods": ["cash", "card", "bank_transfer"],
"needs_shipping_contact": True,
"monthly_installments_enabled": True,
"monthly_installments_options": [3, 6, 9, 12],
"order_template": {
"line_items": [{
"name": "Red Wine",
"unit_price": 1000,
"quantity": 10
}],
"currency": "MXN",
"customer_info": {
"name": "Juan Perez",
"email": "test@conekta.com",
"phone": "5566982090"
}
}
}


checkout_order_object =
"currency": "MXN",
"customer_info": {
"customer_id": "cus_2o3FvMEBiKitVK1vQ"
},
"line_items": [{
"name": "Box of Cohiba S1s",
"unit_price": 300000,
"quantity": 1
}],
"shipping_lines": [{
"amount": 0
}],
"checkout": {
"allowed_payment_methods": ["cash", "card", "bank_transfer"],
"multifactor_authentication": False,
"monthly_installments_enabled": False,
"monthly_installments_options": [3,6,9,12,18],
"expires_at": 1609891200
},
"shipping_contact": {
"phone": "+5215555555555",
"receiver": "Marvin Fuller",
"address": {
"street1": "Nuevo Leon 4",
"country": "MX",
"postal_code": "06100"
}
}

checkout_msi_order__object =
"currency": "MXN",
"customer_info": {
"customer_id": "cus_2o3FvMEBiKitVK1vQ"
},
"line_items": [{
"name": "Box of Cohiba S1s",
"unit_price": 300000,
"quantity": 1
}],
"shipping_lines": [{
"amount": 0
}],
"checkout": {
"type":"Integration",
"allowed_payment_methods": ["cash", "card", "bank_transfer"],
"multifactor_authentication": False,
"monthly_installments_enabled": True,
"monthly_installments_options": [3,6,9,12,18],
"expires_at": 1609891200
},
"shipping_contact": {
"phone": "+5215555555555",
"receiver": "Marvin Fuller",
"address": {
"street1": "Nuevo Leon 4",
"country": "MX",
"postal_code": "06100"
}
}


checkout_order__redirect_object =
"currency": "MXN",
"customer_info": {
"customer_id": "cus_2o3FvMEBiKitVK1vQ"
},
"line_items": [{
"name": "Box of Cohiba S1s",
"unit_price": 300000,
"quantity": 1
}],
"shipping_lines": [{
"amount": 0
}],
"checkout": {
"type":"HostedPayment",
"success_url": "testredirect.com",
"failure_url": "testredirect.com",
"allowed_payment_methods": ["cash", "card", "bank_transfer"],
"multifactor_authentication": False,
"monthly_installments_enabled": False,
"monthly_installments_options": [3,6,9,12,18],
"expires_at": 1609891200
},
"shipping_contact": {
"phone": "+5215555555555",
"receiver": "Marvin Fuller",
"address": {
"street1": "Nuevo Leon 4",
"country": "MX",
"postal_code": "06100"
}
}
Loading