From b8bf10275fc61473a879ab702535a50b98d6c708 Mon Sep 17 00:00:00 2001 From: CARLOS-GALVAN Date: Mon, 28 Oct 2024 08:57:17 -0600 Subject: [PATCH] Se agrega nuevo parametro public_ip para el envio de direccion ip del cliente --- README.md | 12 ++++++++---- VERSION | 2 +- examples/bank_accounts.py | 1 + examples/card_example.py | 5 +++-- examples/charges_example.py | 5 +++-- examples/customer_example.py | 1 + examples/fees.py | 2 +- examples/payouts.py | 1 + examples/plans_example.py | 3 ++- examples/test_create_customer.py | 1 + examples/test_customer_charge_bank.py | 1 + examples/test_list_customer.py | 1 + examples/test_merchant_charge_bank.py | 1 + examples/test_merchant_charge_card.py | 2 +- examples/transfers.py | 2 +- openpay/__init__.py | 2 ++ openpay/api.py | 12 +++++++++++- openpay/test/helper.py | 1 + openpay/test/test_integration.py | 11 ++++++----- openpay/testCo/helperco.py | 5 +++-- openpay/testPe/helperpe.py | 3 ++- openpay/util.py | 9 +++++---- openpay/version.py | 2 +- 23 files changed, 58 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index 5ee32e3..078be4c 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,7 @@ openpay.verify_ssl_certs = False openpay.merchant_id = "mynvbjhtzxdyfewlzmdo" openpay.production = True # By default this works in sandbox mode openpay.country = 'mx' # 'mx' is default value, to use for Colombia set country='co' +openpay.public_ip = '138.84.62.226' #Public IP address of the client, (this is not the server IP) ``` Once configured the library, you can use it to interact with Openpay API services. @@ -52,7 +53,7 @@ Creating a token: openpay.Token.create( card_number="4111111111111111", holder_name="Juan Perez Ramirez", - expiration_year="20", + expiration_year="29", expiration_month="12", cvv2="110", address={ @@ -105,7 +106,7 @@ want to add a new card you will be able to do it as follows: card = customer.cards.create( card_number="4111111111111111", holder_name="Juan Perez Ramirez", - expiration_year="20", + expiration_year="29", expiration_month="12", cvv2="110", address={ @@ -336,6 +337,8 @@ openpay.verify_ssl_certs = False openpay.merchant_id = "mynvbjhtzxdyfewlzmdo" openpay.production = True # By default this works in sandbox mode openpay.country = 'pe' # 'mx' is default value, to use for Peru set country='pe' +openpay.public_ip = '138.84.62.226' #Public IP address of the client, (this is not the server IP) + ``` Once configured the library, you can use it to interact with Openpay API services. @@ -347,7 +350,7 @@ Creating a token: openpay.Token.create( card_number="4111111111111111", holder_name="Juan Perez Ramirez", - expiration_year="20", + expiration_year="29", expiration_month="12", cvv2="110", address={ @@ -400,7 +403,7 @@ want to add a new card you will be able to do it as follows: card = customer.cards.create( card_number="4111111111111111", holder_name="Juan Perez Ramirez", - expiration_year="20", + expiration_year="29", expiration_month="12", cvv2="110", address={ @@ -612,6 +615,7 @@ openpay.verify_ssl_certs = False openpay.merchant_id = "mynvbjhtzxdyfewlzmdo" openpay.production = True # By default this works in sandbox mode openpay.country = 'co' # 'mx' is default value, to use for Colombia set country='co' +openpay.public_ip = '138.84.62.226' #Public IP address of the client, (this is not the server IP) ``` Once configured the library, you can use it to interact with Openpay API services for Colombia. diff --git a/VERSION b/VERSION index 96aeaa6..caea8fb 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.01 \ No newline at end of file +1.02 \ No newline at end of file diff --git a/examples/bank_accounts.py b/examples/bank_accounts.py index 79a1335..93cbca3 100644 --- a/examples/bank_accounts.py +++ b/examples/bank_accounts.py @@ -8,6 +8,7 @@ openpay.api_key = "sk_10d37cc4da8e4ffd902cdf62e37abd1b" openpay.verify_ssl_certs = False openpay.merchant_id = "mynvbjhtzxdyfewlzmdo" +openpay.public_ip = '138.84.62.226' customer = openpay.Customer.retrieve('amce5ycvwycfzyarjf8l') diff --git a/examples/card_example.py b/examples/card_example.py index 4486e39..6dcb0d1 100644 --- a/examples/card_example.py +++ b/examples/card_example.py @@ -9,6 +9,7 @@ openpay.api_key = "sk_10d37cc4da8e4ffd902cdf62e37abd1b" openpay.verify_ssl_certs = False openpay.merchant_id = "mynvbjhtzxdyfewlzmdo" +openpay.public_ip = '138.84.62.226' customer = openpay.Customer.retrieve('amce5ycvwycfzyarjf8l') @@ -17,7 +18,7 @@ card = customer.cards.create( card_number="4111111111111111", holder_name="Juan Perez", - expiration_year="20", + expiration_year="29", expiration_month="12", cvv2="110", address={ @@ -44,7 +45,7 @@ card = openpay.Card.create( card_number="4111111111111111", holder_name="Juan Perez", - expiration_year="20", + expiration_year="29", expiration_month="12", cvv2="110", address={ diff --git a/examples/charges_example.py b/examples/charges_example.py index 33a618a..58ecace 100644 --- a/examples/charges_example.py +++ b/examples/charges_example.py @@ -9,6 +9,7 @@ openpay.api_key = "sk_10d37cc4da8e4ffd902cdf62e37abd1b" openpay.verify_ssl_certs = False openpay.merchant_id = "mynvbjhtzxdyfewlzmdo" +openpay.public_ip = '138.84.62.226' customer = openpay.Customer.retrieve('amce5ycvwycfzyarjf8l') print "customer: ", customer @@ -16,7 +17,7 @@ card = customer.cards.create( card_number="4111111111111111", holder_name="Juan Perez Ramirez", - expiration_year="20", + expiration_year="29", expiration_month="12", cvv2="110", address={ @@ -43,7 +44,7 @@ card = openpay.Card.create( card_number="4111111111111111", holder_name="Juan Perez", - expiration_year="20", + expiration_year="29", expiration_month="12", cvv2="110", address={ diff --git a/examples/customer_example.py b/examples/customer_example.py index b3a811a..ce51900 100644 --- a/examples/customer_example.py +++ b/examples/customer_example.py @@ -7,6 +7,7 @@ openpay.api_key = "sk_10d37cc4da8e4ffd902cdf62e37abd1b" openpay.verify_ssl_certs = False openpay.merchant_id = "mynvbjhtzxdyfewlzmdo" +openpay.public_ip = '138.84.62.226' # cus = openpay.Customer.all() # print cus diff --git a/examples/fees.py b/examples/fees.py index 1775d30..68bba34 100644 --- a/examples/fees.py +++ b/examples/fees.py @@ -8,7 +8,7 @@ openpay.api_key = "sk_10d37cc4da8e4ffd902cdf62e37abd1b" openpay.verify_ssl_certs = False openpay.merchant_id = "mynvbjhtzxdyfewlzmdo" - +openpay.public_ip = '138.84.62.226' fee = openpay.Fee.create( customer_id="amce5ycvwycfzyarjf8l", amount=12.50, diff --git a/examples/payouts.py b/examples/payouts.py index 5b01876..4fbb83f 100644 --- a/examples/payouts.py +++ b/examples/payouts.py @@ -8,6 +8,7 @@ openpay.api_key = "sk_10d37cc4da8e4ffd902cdf62e37abd1b" openpay.verify_ssl_certs = False openpay.merchant_id = "mynvbjhtzxdyfewlzmdo" +openpay.public_ip = '138.84.62.226' customer = openpay.Customer.retrieve('amce5ycvwycfzyarjf8l') diff --git a/examples/plans_example.py b/examples/plans_example.py index 2245e66..b8123a9 100644 --- a/examples/plans_example.py +++ b/examples/plans_example.py @@ -8,6 +8,7 @@ openpay.api_key = "sk_10d37cc4da8e4ffd902cdf62e37abd1b" openpay.verify_ssl_certs = False openpay.merchant_id = "mynvbjhtzxdyfewlzmdo" +openpay.public_ip = '138.84.62.226' # Creating a plan #plan = openpay.Plan.create(amount=150.00, status_after_retry="cancelled", retry_times=2, # name="Curso de Ingles", repeat_unit="month", trial_days=30, repeat_every=1) @@ -26,7 +27,7 @@ # print customer.cards.create( # card_number="4111111111111111", # holder_name="Juan Perez Ramirez", -# expiration_year="20", +# expiration_year="29", # expiration_month="12", # cvv2="110", # address={ diff --git a/examples/test_create_customer.py b/examples/test_create_customer.py index d7bc3c3..8c4dd2a 100644 --- a/examples/test_create_customer.py +++ b/examples/test_create_customer.py @@ -8,6 +8,7 @@ openpay.api_key = "sk_10d37cc4da8e4ffd902cdf62e37abd1b" openpay.verify_ssl_certs = False openpay.merchant_id = "mynvbjhtzxdyfewlzmdo" +openpay.public_ip = '138.84.62.226' newCustomer = openpay.Customer.create( external_id="AA_00003", diff --git a/examples/test_customer_charge_bank.py b/examples/test_customer_charge_bank.py index e837d1e..d1d25d7 100644 --- a/examples/test_customer_charge_bank.py +++ b/examples/test_customer_charge_bank.py @@ -8,6 +8,7 @@ openpay.api_key = "sk_10d37cc4da8e4ffd902cdf62e37abd1b" openpay.verify_ssl_certs = False openpay.merchant_id = "mynvbjhtzxdyfewlzmdo" +openpay.public_ip = '138.84.62.226' charge = openpay.Charge.create( customer="atun9ze7n1dvsdraj3fw", diff --git a/examples/test_list_customer.py b/examples/test_list_customer.py index 309facb..dd6eb15 100644 --- a/examples/test_list_customer.py +++ b/examples/test_list_customer.py @@ -10,6 +10,7 @@ openpay.api_key = "sk_10d37cc4da8e4ffd902cdf62e37abd1b" openpay.verify_ssl_certs = False openpay.merchant_id = "mynvbjhtzxdyfewlzmdo" +openpay.public_ip = '138.84.62.226' customers = openpay.Customer.all( external_id="AA_00002", diff --git a/examples/test_merchant_charge_bank.py b/examples/test_merchant_charge_bank.py index 35b6826..e3fe6f0 100644 --- a/examples/test_merchant_charge_bank.py +++ b/examples/test_merchant_charge_bank.py @@ -8,6 +8,7 @@ openpay.api_key = "sk_10d37cc4da8e4ffd902cdf62e37abd1b" openpay.verify_ssl_certs = False openpay.merchant_id = "mynvbjhtzxdyfewlzmdo" +openpay.public_ip = '138.84.62.226' charge = openpay.Charge.create_as_merchant( method="bank_account", diff --git a/examples/test_merchant_charge_card.py b/examples/test_merchant_charge_card.py index d6a0e4f..7245a04 100644 --- a/examples/test_merchant_charge_card.py +++ b/examples/test_merchant_charge_card.py @@ -8,7 +8,7 @@ openpay.api_key = "sk_10d37cc4da8e4ffd902cdf62e37abd1b" openpay.verify_ssl_certs = False openpay.merchant_id = "mynvbjhtzxdyfewlzmdo" - +openpay.public_ip = '138.84.62.226' charge = openpay.Charge.create_as_merchant( method="card", diff --git a/examples/transfers.py b/examples/transfers.py index f99163e..b27b341 100644 --- a/examples/transfers.py +++ b/examples/transfers.py @@ -8,7 +8,7 @@ openpay.api_key = "sk_10d37cc4da8e4ffd902cdf62e37abd1b" openpay.verify_ssl_certs = False openpay.merchant_id = "mynvbjhtzxdyfewlzmdo" - +openpay.public_ip = '138.84.62.226' customer = openpay.Customer.retrieve('amce5ycvwycfzyarjf8l') print customer.transfers.create(customer_id="acuqxruyv0hi1wfdwmym", amount=100, description="Test transfer", order_id="oid-00059") diff --git a/openpay/__init__.py b/openpay/__init__.py index bd8d7ff..7902e8b 100644 --- a/openpay/__init__.py +++ b/openpay/__init__.py @@ -7,6 +7,7 @@ api_version = None verify_ssl_certs = True country = "mx" +public_ip= None # Resource from openpay.resource import ( # noqa @@ -37,6 +38,7 @@ 'api_version', 'verify_ssl_certs', 'TEST_MODE', + 'public_ip' ) _original_module = _sys.modules[__name__] diff --git a/openpay/api.py b/openpay/api.py index ae97332..5e172ab 100644 --- a/openpay/api.py +++ b/openpay/api.py @@ -1,5 +1,6 @@ import datetime import calendar +import ipaddress import time # import warnings import platform @@ -62,7 +63,6 @@ class APIClient(object): def __init__(self, key=None, client=None, test_mode=False): self.api_key = key - from openpay import verify_ssl_certs openpay.test_mode = test_mode @@ -115,6 +115,14 @@ def request_raw(self, method, url, params=None): 'from the Openpay Dashboard. See http://docs.openpay.mx ' 'for details, or email soporte@openpay.mx if you have any ' 'questions.') + if openpay.public_ip is None or not openpay.public_ip.strip(): + raise error.APIError( + 'Public Ip can not be null or empty') + + try: + ipaddress.ip_address(openpay.public_ip) + except ValueError: + raise error.APIError('Public Ip is not valid') abs_url = "{0}{1}".format(openpay.get_api_base(), url) @@ -153,6 +161,8 @@ def request_raw(self, method, url, params=None): if api_version is not None: headers['Openpay-Version'] = api_version + if openpay.public_ip is not None: + headers['X-Forwarded-For'] = openpay.public_ip rbody, rcode = self._client.request( method, abs_url, headers, post_data, user=my_api_key) diff --git a/openpay/test/helper.py b/openpay/test/helper.py index 4abfafb..0ad2ac6 100644 --- a/openpay/test/helper.py +++ b/openpay/test/helper.py @@ -100,6 +100,7 @@ def setUp(self): 'OPENPAY_API_KEY', 'sk_10d37cc4da8e4ffd902cdf62e37abd1b') openpay.merchant_id = "mynvbjhtzxdyfewlzmdo" openpay.country = "mx" + openpay.public_ip = '::1234:5678 ' # Dev # openpay.api_key = os.environ.get( # 'OPENPAY_API_KEY', '68df281c16184d47bb773d70abd4191b') diff --git a/openpay/test/test_integration.py b/openpay/test/test_integration.py index 2240431..e60df7c 100644 --- a/openpay/test/test_integration.py +++ b/openpay/test/test_integration.py @@ -213,8 +213,9 @@ def test_charge_store_as_customer(self): self.assertTrue(hasattr(charge, 'payment_method')) self.assertTrue(hasattr(charge.payment_method, 'reference')) self.assertTrue(hasattr(charge.payment_method, 'barcode_url')) + chargeStatus=customer.charges.retrieve(charge.id) self.assertEqual( - customer.charges.retrieve(charge.id).status, + chargeStatus.status, 'in_progress') def test_charge_store_as_merchant(self): @@ -420,7 +421,7 @@ def setUp(self): self.card = self.customer.cards.create( card_number="4111111111111111", holder_name="Juan Perez", - expiration_year="20", + expiration_year="29", expiration_month="12", cvv2="110", address={ @@ -465,7 +466,7 @@ def setUp(self): self.card = self.customer.cards.create( card_number="4111111111111111", holder_name="Juan Perez", - expiration_year="20", + expiration_year="29", expiration_month="12", cvv2="110", address={ @@ -514,7 +515,7 @@ def setUp(self): self.card = self.customer.cards.create( card_number="4111111111111111", holder_name="Juan Perez", - expiration_year="20", + expiration_year="29", expiration_month="12", cvv2="110", address={ @@ -562,7 +563,7 @@ def setUp(self): self.card = self.customer.cards.create( card_number="4111111111111111", holder_name="Juan Perez", - expiration_year="20", + expiration_year="29", expiration_month="12", cvv2="110", address={ diff --git a/openpay/testCo/helperco.py b/openpay/testCo/helperco.py index 4b01066..08b7c56 100644 --- a/openpay/testCo/helperco.py +++ b/openpay/testCo/helperco.py @@ -85,8 +85,8 @@ def generate_order_id(): 'repeat_unit': 'month', 'retry_times': 2, 'status_after_retry': 'cancelled', - 'trial_days': 0 - + 'trial_days': 0, +'currency': 'COP', } DUMMY_TRANSFER = { @@ -147,6 +147,7 @@ def setUp(self): 'OPENPAY_API_KEY', 'sk_94a89308b4d7469cbda762c4b392152a') openpay.merchant_id = "mwf7x79goz7afkdbuyqd" openpay.country = "co" + openpay.public_ip = '138.84.62.226' # Dev # openpay.api_key = os.environ.get( # 'OPENPAY_API_KEY', '68df281c16184d47bb773d70abd4191b') diff --git a/openpay/testPe/helperpe.py b/openpay/testPe/helperpe.py index e252f33..84348a2 100644 --- a/openpay/testPe/helperpe.py +++ b/openpay/testPe/helperpe.py @@ -139,7 +139,7 @@ def generate_order_id(): DUMMY_TOKEN = { "card_number": "4111111111111111", "holder_name": "Juan Perez Ramirez", - "expiration_year": "21", + "expiration_year": "29", "expiration_month": "12", "cvv2": "110", "address": { @@ -172,6 +172,7 @@ def setUp(self): 'OPENPAY_API_KEY', 'sk_f934dfe51645483e82106301d985a4f6') openpay.merchant_id = "m3cji4ughukthjcsglv0" openpay.country = "pe" + openpay.public_ip = '138.84.62.226' # Dev # openpay.api_key = os.environ.get( # 'OPENPAY_API_KEY', '68df281c16184d47bb773d70abd4191b') diff --git a/openpay/util.py b/openpay/util.py index 40de5d8..ea2df3f 100644 --- a/openpay/util.py +++ b/openpay/util.py @@ -2,13 +2,14 @@ import logging import sys + logger = logging.getLogger('stripe') __all__ = ['utf8'] def utf8(value): - if isinstance(value, unicode) and sys.version_info < (3, 0): - return value.encode('utf-8') - else: - return value + if sys.version_info[0] < 3: + if isinstance(value, unicode): + return value.encode('utf-8') + return value diff --git a/openpay/version.py b/openpay/version.py index 5388e27..f9827f2 100644 --- a/openpay/version.py +++ b/openpay/version.py @@ -1 +1 @@ -VERSION = '1.01' +VERSION = '1.02'