Skip to content

Commit

Permalink
- Update Code to obtain de fault message to API in responses.py respo…
Browse files Browse the repository at this point in the history
…nse_operation_payments.

- Update code in enzona_business_payment.py
- Update code in enzona_api.py
  • Loading branch information
dennisbr91 committed Jul 31, 2022
1 parent d6878b8 commit b1ded5f
Show file tree
Hide file tree
Showing 4 changed files with 173 additions and 83 deletions.
7 changes: 4 additions & 3 deletions enzona_api/enzona_api.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
'''
"""
This library is still in the process of being created. It is not recommended to use it yet in development.
Author: Josué Carballo Baños
License: GNU GPL from the Free Software Foundation v3 and later.
'''
"""

import base64
from io import BytesIO
Expand Down Expand Up @@ -39,6 +39,7 @@ def get_token(self):
self.token = json_response["access_token"]
return json_response['access_token']

def get_base64(self, text):
@staticmethod
def get_base64(text):
return str(base64.b64encode(bytes(text, "utf-8"))).__str__()

115 changes: 74 additions & 41 deletions enzona_api/enzona_business_payment.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
'''
This library is still in the process of being created. It is not recommended to use it yet in development.
"""
This library is still in the process of being created. It is not recommended
to use it yet in development.
Author: Josué Carballo Baños
License: GNU GPL from the Free Software Foundation v3 and later.
'''
"""

import json
import requests

from enzona_api import enzona_api
from enzona_api.responses import response_payments, response_operation_payments, response_return_payments, response_refound, response_get_refound
from enzona_api.responses import response_payments, \
response_operation_payments, response_return_payments, response_refound, \
response_get_refound
from enzona_api.error import EnzonaError


Expand All @@ -33,7 +36,9 @@ def create_payments(self, payment):
'Content-Type': 'application/json',
"Authorization": "Bearer {0}".format(self.token)
}
response = requests.post("https://api.enzona.net/payment/v1.0.0/payments", data= json.dumps(payment), headers=headers)
response = requests.post(
"https://api.enzona.net/payment/v1.0.0/payments",
data=json.dumps(payment), headers=headers)
try:
return response_payments(response.json())
except EnzonaError as e:
Expand All @@ -49,13 +54,15 @@ def cancel_payments(self, transaction_uuid):
'Content-Type': 'application/json',
"Authorization": "Bearer {0}".format(self.token)
}
response = requests.post("https://api.enzona.net/payment/v1.0.0/payments/{0}/cancel".format(transaction_uuid), headers=headers)
response = requests.post(
"https://api.enzona.net/payment/v1.0.0/payments/{0}/cancel".format(
transaction_uuid), headers=headers)
try:
return response_operation_payments(response.json())
except EnzonaError as e:
print(e)

#Completar un pago
# Completar un pago
def complete_payments(self, transaction_uuid):
"""
Allows you to complete a payment
Expand All @@ -67,16 +74,21 @@ def complete_payments(self, transaction_uuid):
"Authorization": "Bearer {0}".format(self.token)
}
data = {}
response = requests.post("https://api.enzona.net/payment/v1.0.0/payments/{0}/complete".format(transaction_uuid),data=data, headers=headers)
response = requests.post(
"https://api.enzona.net/payment/v1.0.0/payments/{0}/"
"complete".format(transaction_uuid), data=data, headers=headers)
try:
return response_operation_payments(response.json())
except EnzonaError as e:
print(e)


def get_payments(self, merchant_uuid, offset =0, limit =10, status_filter = None, start_date_filter="", end_date_filter=""):
def get_payments(self, merchant_uuid, offset=0, limit=10,
status_filter=None, start_date_filter="",
end_date_filter=""):
"""
You get a list of payments made
:param end_date_filter:
:param start_date_filter:
:param merchant_uuid: Business Identifier
:param offset: Where to start showing the data
:param limit: Amount of data to be displayed
Expand All @@ -87,18 +99,18 @@ def get_payments(self, merchant_uuid, offset =0, limit =10, status_filter = None
'Content-Type': 'application/json',
"Authorization": "Bearer {0}".format(self.token)
}
if status_filter != None:
status_filter = "&status_filter="+str(status_filter)
if status_filter is not None:
status_filter = "&status_filter=" + str(status_filter)
else:
status_filter = ""
response = requests.get("https://api.enzona.net/payment/v1.0.0/payments?"+
"merchant_uuid="+merchant_uuid+
"&limit="+str(limit)+
"&offset="+str(offset)+
"&order_filter=desc"+status_filter+
"&start_date_filter="+start_date_filter+
"&end_date_filter="+end_date_filter
, headers=headers)
response = requests.get(
"https://api.enzona.net/payment/v1.0.0/payments?" +
"merchant_uuid=" + merchant_uuid +
"&limit=" + str(limit) +
"&offset=" + str(offset) +
"&order_filter=desc" + status_filter +
"&start_date_filter=" + start_date_filter +
"&end_date_filter=" + end_date_filter, headers=headers)
try:
return response_return_payments(response.json())
except EnzonaError as e:
Expand All @@ -114,17 +126,21 @@ def payments_refund(self, transaction_uuid, Payload=None):
'Content-Type': 'application/json',
"Authorization": "Bearer {0}".format(self.token)
}
if Payload == None:
if Payload is None:
payload = {}
else:
payload = Payload.get_payload()
try:
response = requests.post("https://api.enzona.net/payment/v1.0.0/payments/"+transaction_uuid+"/refund" , data= json.dumps(payload), headers=headers)
response = requests.post(
"https://api.enzona.net/payment/v1.0.0/payments/" +
transaction_uuid + "/refund",
data=json.dumps(payload), headers=headers)
return response_refound(response.json())
except EnzonaError as e:
print(e)

def get_payments_refund(self, merchant_uuid, offset=0, limit=10, status_filter = None):
def get_payments_refund(self, merchant_uuid, offset=0, limit=10,
status_filter=None):
"""
You get a list of returns made
:param merchant_uuid: Business Identifier
Expand All @@ -137,11 +153,16 @@ def get_payments_refund(self, merchant_uuid, offset=0, limit=10, status_filter =
'Content-Type': 'application/json',
"Authorization": "Bearer {0}".format(self.token)
}
if status_filter != None:
status_filter = "&status_filter="+str(status_filter)
if status_filter is not None:
status_filter = "&status_filter=" + str(status_filter)
else:
status_filter = ""
response = requests.get("https://api.enzona.net/payment/v1.0.0/payments/refunds?merchant_uuid=" + merchant_uuid +"&limit="+str(limit)+"&offset=" + str(offset) +"&order_filter=desc"+status_filter, headers=headers)
response = requests.get(
"https://api.enzona.net/payment/v1.0.0/payments/refunds?"
"merchant_uuid=" + merchant_uuid + "&limit=" + str(
limit) + "&offset=" + str(
offset) + "&order_filter=desc" + status_filter,
headers=headers)
try:
return response_get_refound(response.json())
except EnzonaError as e:
Expand All @@ -152,15 +173,17 @@ class Payload():
def __init__(self, total, description):
self.total = total
self.description = description

def get_payload(self):
if len(str(self.total).split(".")[1]) < 2:
total = str(self.total) + "0"
else: total = self.total
else:
total = self.total
return {
"amount": {
"total": total
},
"description": self.description
"total": total
},
"description": self.description
}


Expand All @@ -175,15 +198,19 @@ def __init__(self, name, description, quantity, price, tax):
def get_product(self):
if len(str(self.price).split(".")[1]) < 2:
price = str(self.price) + "0"
else: price= str(self.price)
else:
price = str(self.price)
if len(str(self.tax).split(".")[1]) < 2:
tax = str(self.tax) + "0"
else: tax = str(self.tax)
return { "name": self.name, "description":self. description, "quantity": self.quantity, "price": price, "tax": tax }
else:
tax = str(self.tax)
return {"name": self.name, "description": self.description,
"quantity": self.quantity, "price": price, "tax": tax}


class Payments():
def __init__(self, merchant_uuid, description_payment, currency, shipping, discount, tip, lst_products, merchant_op_id, invoice_number,
def __init__(self, merchant_uuid, description_payment, currency, shipping,
discount, tip, lst_products, merchant_op_id, invoice_number,
return_url, cancel_url, terminal_id):

shipping = float(shipping)
Expand All @@ -196,23 +223,29 @@ def __init__(self, merchant_uuid, description_payment, currency, shipping, disco
for product in lst_products:
total_tax += float(product["tax"])

total_pay = str( round( (shipping + total_tax + total_price + (tip - discount) ) *100 ) / 100)
total_pay = str(round((shipping + total_tax + total_price + (
tip - discount)) * 100) / 100)

if len(str(total_pay).split(".")[1]) < 2:
total_pay = str(total_pay) + "0"
else: total_pay = str(total_pay)
else:
total_pay = str(total_pay)
if len(str(total_tax).split(".")[1]) < 2:
total_tax = str(total_tax) + "0"
else: total_tax = str(total_tax)
else:
total_tax = str(total_tax)
if len(str(shipping).split(".")[1]) < 2:
shipping = str(shipping) + "0"
else: shipping = str(shipping)
else:
shipping = str(shipping)
if len(str(discount).split(".")[1]) < 2:
discount = str(discount) + "0"
else: discount = str(discount)
else:
discount = str(discount)
if len(str(tip).split(".")[1]) < 2:
tip = str(tip) + "0"
else: tip = str(tip)
else:
tip = str(tip)

self.payment_data = {
"merchant_uuid": merchant_uuid,
Expand All @@ -237,4 +270,4 @@ def __init__(self, merchant_uuid, description_payment, currency, shipping, disco
}

def get_payment(self):
return self.payment_data
return self.payment_data
Loading

0 comments on commit b1ded5f

Please sign in to comment.