PayU India payment gateway. PACKAGE NAME CONFUSION: 'payu' on PyPI (1.2.1) is an unrelated HPC workflow tool — NOT PayU payments. Official PayU India Python SDK is 'payu_websdk' (from payu-india/web-sdk-python on GitHub, not on PyPI). 'payu-sdk' (1.2.0 on PyPI) is unofficial/community. Most Python integrations use manual hash generation without any SDK. Core requirement: SHA512 hash must be generated server-side for every transaction. Amount as string in rupees. Test environment: test.payu.in, Live: secure.payu.in.
Install & Compatibility
Where this runs
tested against v? · pip install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.925 runs
build_error
glibcpy 3.10–3.925 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
Hash generation (manual — recommended approach)
✓ import hashlib
def generate_payu_hash(key, txnid, amount, productinfo,
firstname, email, salt,
udf1='', udf2='', udf3='', udf4='', udf5=''):
"""
PayU hash formula:
sha512(key|txnid|amount|productinfo|firstname|email|
udf1|udf2|udf3|udf4|udf5||||||salt)
Amount must be a string. Hash must be lowercase.
"""
hash_str = (
f'{key}|{txnid}|{amount}|{productinfo}|{firstname}|{email}|'
f'{udf1}|{udf2}|{udf3}|{udf4}|{udf5}||||||{salt}'
)
return hashlib.sha512(hash_str.encode('utf-8')).hexdigest().lower()
# Usage
hash_val = generate_payu_hash(
key='your_key',
txnid='unique_txn_001',
amount='500.00', # string, in rupees
productinfo='Widget',
firstname='John',
email='john@example.com',
salt='your_salt'
)
print(hash_val)
✗ # Wrong: amount as int
generate_payu_hash(..., amount=500, ...) # must be string
# Wrong: uppercase hash
return hashlib.sha512(...).hexdigest().upper() # must be lowercase
# Wrong: wrong pipe count between udf5 and salt
hash_str = f'{key}|{txnid}|{amount}|{productinfo}|{firstname}|{email}|{salt}' # missing udf fields
Hash must include udf1-udf5 fields (even if empty) followed by exactly 6 pipe characters before salt. Wrong pipe count causes hash mismatch and payment failure.
payu_websdk Client
✓ import payu_websdk
# ENV: 'TEST' or 'LIVE'
client = payu_websdk.Client('YOUR_KEY', 'YOUR_SALT', 'TEST')
# Verify payment status
result = client.verify_payment('txnid_001')
print(result)
# Refund
refund = client.refund_transaction(
mihpayid='payu_transaction_id',
token='unique_refund_token',
amount='100.00'
)
print(refund)
✗ # Wrong: 'payu' package from PyPI is a HPC workflow tool
import payu
client = payu.something() # completely unrelated package
'import payu' imports an HPC scheduling tool, not PayU payments. payu_websdk is the correct import for PayU India SDK.
PayU India — manual hash generation and payment form data preparation.
import hashlib
import requests
import uuid
# PayU credentials from dashboard.payu.in
KEY = 'your_merchant_key'
SALT = 'your_merchant_salt'
ENV = 'test' # 'test' or 'prod'
BASE_URL = 'https://test.payu.in' if ENV == 'test' else 'https://secure.payu.in'
def generate_hash(key, txnid, amount, productinfo, firstname, email, salt, **udf):
udf1 = udf.get('udf1', '')
udf2 = udf.get('udf2', '')
udf3 = udf.get('udf3', '')
udf4 = udf.get('udf4', '')
udf5 = udf.get('udf5', '')
hash_str = f'{key}|{txnid}|{amount}|{productinfo}|{firstname}|{email}|{udf1}|{udf2}|{udf3}|{udf4}|{udf5}||||||{salt}'
return hashlib.sha512(hash_str.encode()).hexdigest().lower()
# Create payment params
txnid = str(uuid.uuid4())[:20]
amount = '500.00' # string, rupees
hash_val = generate_hash(
KEY, txnid, amount,
'Widget', 'John', 'john@example.com',
SALT
)
payment_data = {
'key': KEY,
'txnid': txnid,
'amount': amount,
'productinfo': 'Widget',
'firstname': 'John',
'email': 'john@example.com',
'phone': '9999999999',
'surl': 'https://yourapp.com/payment/success', # success URL
'furl': 'https://yourapp.com/payment/failure', # failure URL
'hash': hash_val,
}
# POST this form data to BASE_URL/_payment
print('POST to:', f'{BASE_URL}/_payment')
print('Params:', payment_data)
Audit
Dependencies
requestsrequiredRequired for manual API integration and for payu_websdk.