Skip to content
Open
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
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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={
Expand Down Expand Up @@ -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={
Expand Down Expand Up @@ -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.

Expand All @@ -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={
Expand Down Expand Up @@ -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={
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.01
1.02
1 change: 1 addition & 0 deletions examples/bank_accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down
5 changes: 3 additions & 2 deletions examples/card_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand All @@ -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={
Expand All @@ -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={
Expand Down
5 changes: 3 additions & 2 deletions examples/charges_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@
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

card = customer.cards.create(
card_number="4111111111111111",
holder_name="Juan Perez Ramirez",
expiration_year="20",
expiration_year="29",
expiration_month="12",
cvv2="110",
address={
Expand All @@ -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={
Expand Down
1 change: 1 addition & 0 deletions examples/customer_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion examples/fees.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions examples/payouts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down
3 changes: 2 additions & 1 deletion examples/plans_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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={
Expand Down
1 change: 1 addition & 0 deletions examples/test_create_customer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions examples/test_customer_charge_bank.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions examples/test_list_customer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions examples/test_merchant_charge_bank.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion examples/test_merchant_charge_card.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion examples/transfers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 2 additions & 0 deletions openpay/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
api_version = None
verify_ssl_certs = True
country = "mx"
public_ip= None
# Resource

from openpay.resource import ( # noqa
Expand Down Expand Up @@ -37,6 +38,7 @@
'api_version',
'verify_ssl_certs',
'TEST_MODE',
'public_ip'
)
_original_module = _sys.modules[__name__]

Expand Down
12 changes: 11 additions & 1 deletion openpay/api.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import datetime
import calendar
import ipaddress
import time
# import warnings
import platform
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions openpay/test/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
11 changes: 6 additions & 5 deletions openpay/test/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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={
Expand Down Expand Up @@ -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={
Expand Down Expand Up @@ -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={
Expand Down Expand Up @@ -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={
Expand Down
5 changes: 3 additions & 2 deletions openpay/testCo/helperco.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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')
Expand Down
3 changes: 2 additions & 1 deletion openpay/testPe/helperpe.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -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')
Expand Down
9 changes: 5 additions & 4 deletions openpay/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion openpay/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION = '1.01'
VERSION = '1.02'