Skip to main content

Official CashPay Payment Gateway SDK for Python

Project description

CashPay Python SDK

Official Python SDK for integrating with CashPay Payment Gateway.

Installation

pip install cashpay

Quick Start

from cashpay import CashPay

client = CashPay(
    api_key='cpk_live_xxx',
    api_secret='cps_live_xxx',
    environment='production'  # or 'sandbox'
)

Usage Examples

Check Balance

# Get unified balance
balance = client.balance.get()
print(f"Total Balance: ₹{balance.total_balance / 100}")

# Get settlement balance
settlement = client.balance.get_settlement()
print(f"Available for withdrawal: ₹{settlement.available_withdrawal_amount / 100}")

# Get payout balance
payout = client.balance.get_payout()
print(f"Payout Balance: ₹{payout.payout_balance / 100}")

Payins (Check Payment Status)

# Get payin by order ID
payin = client.payins.get_by_order_id('ORDER_12345')
print(f"Status: {payin['status']}, UTR: {payin['utr']}")

# Get payin status by payment ID
status = client.payins.get_status('payment-uuid')

Payouts

# Create a payout
payout = client.payouts.create(
    beneficiary_id='ben_xxx',
    amount=10000,  # ₹100 in paise
    reference_id='PAY-001',
    narration='Salary payment',
    mode='IMPS',
    idempotency_key='unique-key'
)
print(f"Payout ID: {payout['id']}, Status: {payout['status']}")

# Create bulk payouts (max 100)
bulk_result = client.payouts.create_bulk([
    {'beneficiaryId': 'ben_1', 'amount': 10000, 'referenceId': 'PAY-001'},
    {'beneficiaryId': 'ben_2', 'amount': 20000, 'referenceId': 'PAY-002'},
], idempotency_key='bulk-key')
print(f"Success: {bulk_result['successCount']}, Failed: {bulk_result['failureCount']}")

# List payouts
payouts = client.payouts.list(page=1, limit=20, status='COMPLETED')

# Get payout by ID
payout_details = client.payouts.get('payout-uuid')

# Get payout by reference ID
payout_by_ref = client.payouts.get_by_reference_id('PAY-001')

# Cancel payout
cancelled = client.payouts.cancel('payout-uuid')

Settlements

# Create settlement with saved bank account
settlement = client.settlements.create(
    amount=100000,  # ₹1000 in paise
    bank_account_id='bank_xxx',
    reference_id='SET-001',
    idempotency_key='unique-key'
)

# Create settlement with direct bank details
direct_settlement = client.settlements.create(
    amount=100000,
    account_number='50100123456789',
    ifsc='HDFC0001234',
    account_holder_name='John Doe',
    reference_id='SET-002'
)

# Create bulk settlements
bulk_settlements = client.settlements.create_bulk([
    {'amount': 50000, 'bankAccountId': 'bank_1', 'referenceId': 'SET-001'},
    {'amount': 75000, 'bankAccountId': 'bank_2', 'referenceId': 'SET-002'},
])

# List settlements
settlements = client.settlements.list(status='COMPLETED')

# Get settlement by ID
settlement_details = client.settlements.get('settlement-uuid')

# Cancel settlement
cancelled_settlement = client.settlements.cancel('settlement-uuid')

Webhook Verification

from flask import Flask, request

app = Flask(__name__)

@app.route('/webhook', methods=['POST'])
def webhook():
    signature = request.headers.get('x-webhook-signature')
    payload = request.get_data(as_text=True)
    
    is_valid = client.verify_webhook(payload, signature, 'your-webhook-secret')
    
    if not is_valid:
        return 'Invalid signature', 401
    
    event = request.get_json()
    
    if event['type'] == 'payin.completed':
        print('Payment completed:', event['data'])
    elif event['type'] == 'payout.completed':
        print('Payout completed:', event['data'])
    elif event['type'] == 'settlement.completed':
        print('Settlement completed:', event['data'])
    
    return 'OK', 200

Error Handling

from cashpay import CashPay, CashPayError

try:
    payout = client.payouts.create(
        beneficiary_id='invalid-id',
        amount=10000
    )
except CashPayError as e:
    print(f"Error: {e.message}")
    print(f"Status: {e.status_code}")
    print(f"Code: {e.code}")
    print(f"Details: {e.details}")

Configuration Options

Option Type Default Description
api_key str required Your API key
api_secret str required Your API secret
environment str 'production' 'sandbox' or 'production'
base_url str auto Custom API base URL
timeout int 30 Request timeout in seconds

Support

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cashpay-1.0.0.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cashpay-1.0.0-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file cashpay-1.0.0.tar.gz.

File metadata

  • Download URL: cashpay-1.0.0.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for cashpay-1.0.0.tar.gz
Algorithm Hash digest
SHA256 e2d4452e0cf5d5fa74611358f02badfe5ad2df5e2fba4916156ba5fa659eadf9
MD5 3cb3562e4b2341971d2c526d13e266bf
BLAKE2b-256 e8379dab854e84f314acec33b1f662d3c207a8cafb6160d1ade93fa94556a89c

See more details on using hashes here.

File details

Details for the file cashpay-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: cashpay-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 6.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for cashpay-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 12f5f41bdee9efd53c35be7ca5960387dcbe38aeb6f232f73831e84656f435b1
MD5 0d3375846554fa3f32945627519ddf16
BLAKE2b-256 f4b447a1bdd33dd2cab2629ae7edecd3db5db9816127e157ec009048601b2396

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page