diff --git a/README.rst b/README.rst index ee2eae0..8f8bdf8 100644 --- a/README.rst +++ b/README.rst @@ -236,6 +236,12 @@ Pay Subscription PSE #### +List Banks +***** +.. code-block:: python + + banks = objepayco.bank.pseBank() + Create ***** .. code-block:: python @@ -255,6 +261,7 @@ Create "last_name": "PAYCO", "email": "no-responder@payco.co", "country": "CO", + "city": "bogota", "cell_phone": "3010000001", "ip": "190.000.000.000", #This is the client's IP, it is required, "url_response": "https://tudominio.com/respuesta.php", @@ -329,6 +336,8 @@ Create "name": "testing", "last_name": "PAYCO", "email": "test@mailinator.com", + "country": "CO", + "city": "bogota", "cell_phone": "3010000001", "end_date": "2020-12-05", "ip": "190.000.000.000", #This is the client's IP, it is required, @@ -399,7 +408,7 @@ use the following attributes in case you need to do a dispersion with one or mul Payment -***** +#### Create ***** @@ -415,6 +424,8 @@ Create "email": "example@email.com", "bill": "OR-1234", "description": "Test Payment", + "country": "CO", + "city": "bogota", "value": "116000", "tax": "16000", "tax_base": "100000", @@ -479,31 +490,44 @@ use the following attributes in case you need to do a dispersion with one or mul Daviplata -***** +#### Create ***** .. code-block:: python + payment_info = { - doc_type: "CC", - document: "1053814580414720", - name: "Testing", - last_name: "PAYCO", - email: "exmaple@epayco.co", - ind_country: "CO", - phone: "314853222200033", - country: "CO", - city: "bogota", - address: "Calle de prueba", - ip: "189.176.0.1", - currency: "COP", - description: "ejemplo de transaccion con daviplata", - value: "100", - tax: "0", - ico: "0" - tax_base: "0", - method_confirmation: "" + "doc_type": "CC", + "document": "1053814580414720", + "name": "Testing", + "last_name": "PAYCO", + "email": "exmaple@epayco.co", + "ind_country": "57", + "phone": "314853222200033", + "country": "CO", + "city": "bogota", + "address": "Calle de prueba", + "ip": "189.176.0.1", + "currency": "COP", + "description": "ejemplo de transaccion con daviplata", + "value": "100", + "tax": "0", + "ico": "0" + "tax_base": "0", + "method_confirmation": "GET", + "url_response": "https://tudominio.com/respuesta.php", + "url_confirmation": "https://tudominio.com/confirmacion.php", + "extra1": "", + "extra2": "", + "extra3": "", + "extra4": "", + "extra5": "", + "extra6": "", + "extra7": "", + "extra8": "", + "extra9": "", + "extra10": "" } daviplata = objepayco.daviplata.create(payment_info) @@ -512,44 +536,57 @@ confirm transaccion ***** .. code-block:: python + confirm = { - ref_payco: "45508846", // It is obtained from the create response - id_session_token: "45081749", // It is obtained from the create response - otp: "2580" + "ref_payco": "45508846", # It is obtained from the create response + "id_session_token": "45081749", # It is obtained from the create response + "otp": "2580" } daviplata = objepayco.daviplata.confirm(payment_info) Safetypay -***** +#### Create ***** .. code-block:: python + payment_info = { - cash: "1", - expirationDate: "2021-08-05", - docType: "CC", - document: "123456789", - name: "Jhon", - lastName: "doe", - email: "jhon.doe@yopmail.com", - indCountry: "57", - phone: "3003003434", - country: "CO", - invoice: "fac-01", // opcional - city: "N/A", - address: "N/A", - ip: "192.168.100.100", - currency: "COP", - description: "Thu Jun 17 2021 11:37:01 GMT-0400 (hora de Venezuela)", - value: 100000, - tax: 0, - ico: 0, - taxBase: 0, - urlConfirmation: "", - methodConfirmation: "" + "cash": "1", + "end_date": "2021-08-05", + "doc_type": "CC", + "document"": "123456789", + "name": "Jhon", + "last_name": "doe", + "email": "jhon.doe@yopmail.com", + "ind_country": "57", + "phone": "3003003434", + "country": "CO", + "invoice": "fac-01", # opcional + "city": "N/A", + "address": "N/A", + "ip": "192.168.100.100", + "currency": "COP", + "description": "Thu Jun 17 2021 11:37:01 GMT-0400 (hora de Venezuela)", + "value": 100000, + "tax": 0, + "ico": 0, + "tax_base": 0, + "url_confirmation": "https://tudominio.com/respuesta.php", + "url_response": "https://tudominio.com/respuesta.php", + "method_confirmation": "POST", + "extra1": "", + "extra2": "", + "extra3": "", + "extra4": "", + "extra5": "", + "extra6": "", + "extra7": "", + "extra8": "", + "extra9": "", + "extra10": "" } - daviplata = objepayco.daviplata.create(payment_info) \ No newline at end of file + safetypay = objepayco.safetypay.create(payment_info) diff --git a/epaycosdk/client.py b/epaycosdk/client.py index 337cb8e..082d342 100644 --- a/epaycosdk/client.py +++ b/epaycosdk/client.py @@ -3,19 +3,12 @@ import ssl import json import base64 -import hashlib from Crypto.Cipher import AES import requests import epaycosdk.errors as errors -import os -import sys -from requests.exceptions import ConnectionError from pathlib import Path -from dotenv import load_dotenv from requests import Session -load_dotenv() - # No verificar el certifcado para los request ssl._create_default_https_context = ssl._create_unverified_context @@ -104,20 +97,13 @@ def make(self, BASE_URL, BASE_URL_APIFY, apify): bearer_token=json_data['token'] if apify else json_data['bearer_token'] return bearer_token -class NoRebuildAuthSession(Session): - def rebuild_auth(self, prepared_request, response): - """ - No code here means requests will always preserve the Authorization - header when redirected. - Be careful not to leak your credentials to untrusted hosts! - """ class Client: - BASE_URL = os.getenv("BASE_URL_SDK") if os.getenv("BASE_URL_SDK") else "https://api.secure.payco.co" - BASE_URL_SECURE = os.getenv("SECURE_URL_SDK") if os.getenv("SECURE_URL_SDK") else"https://secure.payco.co" - ENTORNO = os.getenv("ENTORNO_SDK") if os.getenv("ENTORNO_SDK") else "/restpagos" - BASE_URL_APIFY = os.getenv("BASE_URL_APIFY") if os.getenv("BASE_URL_APIFY") else "https://apify.epayco.co" + BASE_URL = "https://api.secure.payco.co" + BASE_URL_SECURE = "https://secure.payco.co" + ENTORNO = "/restpagos" + BASE_URL_APIFY = "https://apify.epayco.co" IV = "0000000000000000" LANGUAGE = "python" SWITCH= False @@ -145,10 +131,10 @@ def request(self,method='POST',url="",api_key="",data={}, private_key="",test="" authentication = auth.make(self.BASE_URL,self.BASE_URL_APIFY,apify) token_bearer = 'Bearer ' +authentication util = Util() - if(apify): - data = util.setKeys_apify(data) - elif (hasattr(data, "__len__")): - if(switch): + if(hasattr(data, "__len__")): + if(apify): + data = util.setKeys_apify(data) + elif(switch): data = util.setKeys(data) self.SWITCH=switch @@ -162,7 +148,9 @@ def request(self,method='POST',url="",api_key="",data={}, private_key="",test="" try: if (method == "GET"): - if (switch): + if(apify): + response=requests.get(self.build_url(url), data={},headers=headers) + elif (switch): if test == True or test == "true": test = "TRUE" else: @@ -184,8 +172,7 @@ def request(self,method='POST',url="",api_key="",data={}, private_key="",test="" else: url_params=data payload = {} - session = NoRebuildAuthSession() - response = session.get(self.build_url(url), headers=headers, data = payload, params=url_params) + response = requests.get(self.build_url(url), headers=headers, data = payload, params=url_params) elif (method == "POST"): diff --git a/epaycosdk/resources.py b/epaycosdk/resources.py index 0c736f3..aa67038 100644 --- a/epaycosdk/resources.py +++ b/epaycosdk/resources.py @@ -73,7 +73,7 @@ def create(self, options=None): def get(self, uid): return self.request( "GET", - "payment/v1/customer/" + self.epayco.api_key + "/" + uid + "/", + "payment/v1/customer/" + self.epayco.api_key + "/" + uid, self.epayco.api_key, None, self.epayco.private_key, @@ -91,7 +91,7 @@ def get(self, uid): def getlist(self): return self.request( "GET", - "payment/v1/customers/" + self.epayco.api_key + "/", + "payment/v1/customers/" + self.epayco.api_key, self.epayco.api_key, None, self.epayco.private_key, @@ -105,7 +105,7 @@ def update(self,uid,options): return self.request( "POST", - "payment/v1/customer/edit/" + self.epayco.api_key + "/" + uid + "/", + "payment/v1/customer/edit/" + self.epayco.api_key + "/" + uid, self.epayco.api_key, options, self.epayco.private_key, @@ -272,7 +272,7 @@ def getlist(self): def update(self, uid, options=None): return self.request( "POST", - "recurring/v1/plan/edit/" + self.epayco.api_key + "/" + uid + "/", + "recurring/v1/plan/edit/" + self.epayco.api_key + "/" + uid, self.epayco.api_key, options, self.epayco.private_key, @@ -351,7 +351,7 @@ def getlist(self): return self.request( "GET", - "recurring/v1/subscriptions/" + self.epayco.api_key + "/", + "recurring/v1/subscriptions/" + self.epayco.api_key, self.epayco.api_key, options, self.epayco.private_key, @@ -487,25 +487,32 @@ class Cash(Resource): def create(self, type=None, options=None): - url = None - if (type == "efecty"): - url = "/v2/efectivo/efecty" - elif (type == "baloto"): - url = "/v2/efectivo/baloto" - elif (type == "gana"): - url = "/v2/efectivo/gana" - elif (type == "redservi"): - url = "/v2/efectivo/redservi" - elif (type == "puntored"): - url = "/v2/efectivo/puntored" - elif (type == "sured"): - url = "/v2/efectivo/sured" - else: + methods_payment = self.request( + "GET", + "/payment/cash/entities", + self.epayco.api_key, + None, + self.epayco.private_key, + self.epayco.test, + False, + self.epayco.lang, + False, + False, + True + ) + medio = type.lower() + if(medio == "baloto"): + raise errors.ErrorException(self.epayco.lang, 109) + if(not methods_payment.get("data") or not isinstance(methods_payment["data"], list) or len(methods_payment["data"]) == 0): + raise errors.ErrorException(self.epayco.lang, 106) + + entities = list(map(lambda item: item["name"].lower().replace(" ", ""), methods_payment["data"])) + if((medio not in entities)): raise errors.ErrorException(self.epayco.lang, 109) return self.request( "POST", - url, + "/v2/efectivo/{type}".format(type=medio), self.epayco.api_key, options, self.epayco.private_key, diff --git a/setup.py b/setup.py index 08dbaef..d55e00a 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setup( name="epaycosdk", - version="3.1.1", + version="3.1.2", include_package_data=True, author="ePayco Development Team", author_email="ricardo.saldarriaga@epayco.co", @@ -18,6 +18,5 @@ install_requires=[ "requests >= 2.4.3", "pycryptodome >= 2.6.1" if platform.system() == "Windows" else "pycrypto >= 2.6.1", - "python-dotenv >= 0.19.2" ], ) \ No newline at end of file