payu-python is an API wrapper for Payu written in Python. Currently only works for supported credit cards in the supported countries in Latam.
Supported countries:
- Argentina
- Brazil
- Chile
- Colombia
- Mexico
- Panama
- Peru
Read Utils section to find out how to get the supported credit cards for a country.
Read TODO section to find out what's missing in this library.
pip install payu-python
If you are going to use this with your Django application, we recommend you to use our django implementation:
TEST_API_LOGIN = 'pRRXKOl8ikMmt9u'
TEST_API_KEY = '4Vj8eK4rloUd272L48hsrarnUA'
TEST_MERCHANT_ID = 508029
TEST_ACCOUNT_ID = 512321
client = Client(TEST_API_LOGIN, TEST_API_KEY, TEST_MERCHANT_ID, TEST_ACCOUNT_ID, sandbox=True, language='en', debug=True)
BUYER_EXAMPLE = {
"merchantBuyerId": "1",
"fullName": "First name and second buyer name",
"emailAddress": "buyer_test@test.com",
"contactPhone": "7563126",
"dniNumber": "5415668464654",
"shippingAddress": {
"street1": "calle 100",
"street2": "5555487",
"city": "Medellin",
"state": "Antioquia",
"country": "CO",
"postalCode": "000000",
"phone": "7563126"
}
}
PAYER_EXAMPLE = {
"merchantPayerId": "1",
"fullName": "First name and second payer name",
"emailAddress": "payer_test@test.com",
"contactPhone": "7563126",
"dniNumber": "5415668464654",
"billingAddress": {
"street1": "calle 93",
"street2": "125544",
"city": "Bogota",
"state": "Bogota DC",
"country": "CO",
"postalCode": "000000",
"phone": "7563126"
}
}
CREDIT_CARD_EXAMPLE = {
"number": "4097440000000004",
"securityCode": "321",
"expirationDate": "2022/12",
"name": "APPROVED"
}
EXTRA_EXAMPLE = {
"INSTALLMENTS_NUMBER": 1
}
r = client.payments.ping()
r = client.payments.get_payments_methods()
r = client.payments.make_payment(reference_code='TestPayU01', description='Test Payment', tx_value=1000, tx_tax=0,
tx_tax_return_base=0, currency='COP', buyer=BUYER_EXAMPLE, payer=PAYER_EXAMPLE,
credit_card=CREDIT_CARD_EXAMPLE, payment_method='VISA', payment_country='CO',
device_session_id='vghs6tvkcle931686k1900o6e1',
ip_address='127.0.0.1', cookie='pt1t38347bs6jc9ruv2ecpv7o2',
user_agent='Mozilla/5.0 (Windows NT 5.1; rv:18.0) Gecko/20100101 Firefox/18.0',
extra_parameters=EXTRA_EXAMPLE,
notify_url='https://ed60769e.ngrok.io/payu/notification/')
r = client.payments.make_authorization(reference_code='TestPayU02', description='Test Payment', tx_value=1000, tx_tax=0,
tx_tax_return_base=0, currency='COP', buyer=BUYER_EXAMPLE, payer=PAYER_EXAMPLE,
credit_card=CREDIT_CARD_EXAMPLE, payment_method='VISA', payment_country='CO',
device_session_id='vghs6tvkcle931686k1900o6e1',
ip_address='127.0.0.1', cookie='pt1t38347bs6jc9ruv2ecpv7o2',
user_agent='Mozilla/5.0 (Windows NT 5.1; rv:18.0) Gecko/20100101 Firefox/18.0',
extra_parameters=EXTRA_EXAMPLE,
notify_url='https://ed60769e.ngrok.io/payu/notification/')
r = client.payments.make_capture(order_id='844928300', parent_transaction_id='4d7f240d-084a-426f-aa27-42c3b2a2b265')
r = client.payments.refund_payment(order_id='844928300', parent_transaction_id='4d7f240d-084a-426f-aa27-42c3b2a2b265',
reason='Client asked for refund.')
r = client.tokenization.create_single_token(payer_id='1', name='Full name', identification_number='32144457',
payment_method='VISA', number='4111111111111111', expiration_date='2022/01')
r = client.tokenization.make_payment(reference_code='TestPayU03', description='Test Payment', tx_value=1000,
currency='COP', buyer=BUYER_EXAMPLE, payer=PAYER_EXAMPLE, payment_method='VISA',
payment_country='CO', device_session_id='vghs6tvkcle931686k1900o6e1',
ip_address='127.0.0.1', cookie='pt1t38347bs6jc9ruv2ecpv7o2',
user_agent='Mozilla/5.0 (Windows NT 5.1; rv:18.0) Gecko/20100101 Firefox/18.0',
credit_card_token_id='b01877c3-b044-455a-99f5-82aed33795e9')
r = client.tokenization.make_authorization(reference_code='TestPayU03', description='Test Payment', tx_value=1000,
currency='COP', buyer=BUYER_EXAMPLE, payer=PAYER_EXAMPLE, payment_method='VISA',
payment_country='CO', device_session_id='vghs6tvkcle931686k1900o6e1',
ip_address='127.0.0.1', cookie='pt1t38347bs6jc9ruv2ecpv7o2',
user_agent='Mozilla/5.0 (Windows NT 5.1; rv:18.0) Gecko/20100101 Firefox/18.0',
credit_card_token_id='b01877c3-b044-455a-99f5-82aed33795e9')
r = client.tokenization.make_capture(order_id='844928300', parent_transaction_id='4d7f240d-084a-426f-aa27-42c3b2a2b265')
import datetime
r = client.tokenization.get_tokens(payer_id='1', credit_card_token_id='b65c63e9-ec0c-49ac-a67d-1414c3dc3ccc',
start_date=datetime.datetime.now().replace(year=2017),
end_date=datetime.datetime.now()))
r = client.tokenization.remove_token(payer_id='1', credit_card_token_id='d70889d2-0f82-482d-a2ed-3c0a2813d57c')
r = client.recurring.create_plan(plan_code='PLAN_CODE', description='Test Plan', interval='MONTH', interval_count=1,
max_payments_allowed=12, payment_attempts_delay=1, plan_value=1000, plan_tax=0,
plan_tax_return_base=0, currency='COP')
r = client.recurring.get_plan('PLAN_CODE')
r = client.recurring.delete_plan('PLAN_CODE')
r = client.recurring.create_customer(full_name='Full name', email='customer_test@test.com')
r = client.recurring.get_customer('CUSTOMER_ID')
r = client.recurring.delete_customer('CUSTOMER_ID')
r = client.recurring.create_credit_card(customer_id='CUSTOMER_ID', name'Full name', document='32144457',
number='4111111111111111', exp_month='01', exp_year='2022', type='VISA',
address='calle 93 125544 Bogota')
r = client.recurring.get_credit_card('CREDIT_CARD_ID')
r = client.recurring.delete_credit_card(customer_id='CUSTOMER_ID', credit_card_id='CREDIT_CARD_ID')
r = client.recurring.create_subscription(customer_id='CUSTOMER_ID', credit_card_token='CREDIT_CARD_ID',
plan_code='PLAN_CODE')
r = client.recurring.get_subscription('SUBSCRIPTION_ID')
r = client.recurring.update_subscription(subscription_id='SUBSCRIPTION_ID', credit_card_token='CREDIT_CARD_TOKEN')
r = client.recurring.delete_subscription('SUBSCRIPTION_ID')
r = client.recurring.create_additional_charge(subscription_id='SUBSCRIPTION_ID', description='TEST CHARGE',
plan_value=1000, plan_tax=0, plan_tax_return_base=0,
currency='COP')
r = client.recurring.get_additional_charge_by_identifier('RECURRING_BILLING_ID')
r = client.recurring.get_additional_charge_by_description('DESCRIPTION')
r = client.recurring.get_additional_charge_by_subscription('SUBSCRIPTION_ID')
r = client.recurring.update_additional_charge(recurring_billing_id='RECURRING_BILLING_ID', description='TEST CHARGE',
plan_value=1000, plan_tax=0, plan_tax_return_base=0, currency='COP')
r = client.recurring.delete_additional_charge('RECURRING_BILLING_ID')
import datetime
r = client.recurring.get_recurring_bill_by_client(customer_id='CUSTOMER_ID',
date_begin=datetime.datetime.now().replace(year=2017),
date_final=datetime.datetime.now())
r = client.recurring.get_recurring_bill_by_subscription('SUBSCRIPTION_ID')
r = client.queries.get_order_by_identifier('ORDER_ID')
r = client.queries.get_order_by_reference('REFERENCE_CODE')
r = client.queries.get_transaction_response('TRANSACTION_ID')
from payu.utils import get_available_franchise_for_payment
from payu.enumerators import Country, TransactionType
r = get_available_franchise_for_payment(Country.COLOMBIA, TransactionType.AUTHORIZATION)
r = get_available_franchise_for_payment(Country.COLOMBIA, TransactionType.AUTHORIZATION_AND_CAPTURE)
from payu.utils import get_available_franchise_for_tokenization
from payu.enumerators import Country, TransactionType
r = get_available_franchise_for_tokenization(Country.COLOMBIA, TransactionType.AUTHORIZATION)
r = get_available_franchise_for_tokenization(Country.COLOMBIA, TransactionType.AUTHORIZATION_AND_CAPTURE)
from payu.utils import has_franchise_cvv_tokenization
from payu.enumerators import Country, Franchise, TransactionType
r = get_available_franchise_for_tokenization(Franchise.VISA, Country.COLOMBIA, TransactionType.AUTHORIZATION_AND_CAPTURE)
- cancel_payment()
- Support for cash / bank payment methods
- Support for bank transfer methods
- create_multiple_tokens()
- make_multiple_payments()
- update_plan()
- update_customer()
- update_credit_card()
Payment flows:
- Authorization and Capture as two-steps.
- Authorization and Capture in one-step also known as Charge.
Countries that have two-step payment flow available:
- Argentina
- Brazil
- Peru
Countries that does not need CVV for tokenized payments.
- Brazil
- Colombia
- Peru
We are always grateful for any kind of contribution including but not limited to bug reports, code enhancements, bug fixes, and even functionality suggestions.
You can report any bug you find or suggest new functionality with a new issue.
- Fork it ( https://github.com/GearPlug/payu-python )
- Create your feature branch (git checkout -b my-new-feature)
- Commit your changes (git commit -am 'Adds my new feature')
- Push to the branch (git push origin my-new-feature)
- Create a new Pull Request