Skip to main content

Python client for Khipu payment API

Project description

Khipu Python Client

A Python client library for the Khipu payment API. Khipu is a popular payment platform in Latin America that enables businesses to accept payments easily.

Features

  • 🔐 Secure authentication using HMAC-SHA256
  • 💳 Create payment requests
  • 🏢 Create receiver accounts
  • 📦 Simple, intuitive API
  • 🐍 Type hints for better IDE support
  • ✅ Dataclass-based request/response models

Installation

pip install khipu

Quick Start

from khipu import Client
from khipu.data_classes import PaymentRequest

# Initialize the client
client = Client(
    receiver_id=12345,
    secret="your-secret-key"
)

# Create a payment
payment_request = PaymentRequest(
    amount=1000,
    currency="CLP",
    subject="Test Payment",
    transaction_id="ORDER-123",
    return_url="https://yoursite.com/success",
    cancel_url="https://yoursite.com/cancel",
    notify_url="https://yoursite.com/webhook"
)

payment_response = client.create_payment(payment_request)
print(f"Payment URL: {payment_response.payment_url}")

Usage

Creating a Client

from khipu import Client

client = Client(
    receiver_id=12345,
    secret="your-secret-key",
    base_url="https://khipu.com/api",  # Optional, default value
    api_version="2.0"  # Optional, default value
)

Creating a Payment

from khipu.data_classes import PaymentRequest

payment_request = PaymentRequest(
    amount=5000,
    currency="CLP",
    subject="Product Purchase",
    body="Detailed description of the purchase",
    transaction_id="UNIQUE-ORDER-ID",
    payer_email="customer@example.com",
    return_url="https://yoursite.com/success",
    cancel_url="https://yoursite.com/cancel",
    notify_url="https://yoursite.com/webhook",
    expires_date="2024-12-31T23:59:59"
)

response = client.create_payment(payment_request)

# Redirect user to payment_url
print(response.payment_url)

Creating a Receiver

from khipu.data_classes import ReceiverRequest

receiver_request = ReceiverRequest(
    admin_first_name="John",
    admin_last_name="Doe",
    admin_email="admin@example.com",
    country_code="CL",
    business_identifier="12345678-9",
    business_category="services",
    business_name="My Business",
    business_phone="+56912345678",
    business_address_line_1="Address Line 1",
    business_address_line_2="Address Line 2",
    business_address_line_3="City, Region",
    contact_full_name="Jane Doe",
    contact_job_title="Manager",
    contact_email="contact@example.com",
    contact_phone="+56987654321"
)

receiver_response = client.create_receiver(receiver_request)
print(f"Receiver ID: {receiver_response.receiver_id}")

API Reference

PaymentRequest

Required fields:

  • amount (int): Amount in the smallest currency unit (e.g., cents)
  • currency (str): Currency code (e.g., "CLP", "USD")
  • subject (str): Payment subject/title

Optional fields:

  • transaction_id (str): Unique transaction identifier
  • custom (str): Custom data
  • body (str): Payment description
  • bank_id (str): Specific bank ID
  • return_url (str): URL to redirect after successful payment
  • cancel_url (str): URL to redirect after cancelled payment
  • picture_url (str): URL of product/service image
  • notify_url (str): Webhook URL for payment notifications
  • payer_email (str): Payer's email address
  • And more...

PaymentResponse

  • payment_id (str): Unique payment identifier
  • payment_url (str): URL to redirect user for payment
  • simplified_transfer_url (str): Simplified transfer URL
  • transfer_url (str): Transfer URL
  • app_url (str): Mobile app URL
  • ready_for_terminal (bool): Whether payment is ready for terminal

Development

Setup

# Clone the repository
git clone https://github.com/MarioPayan/Zaku.git
cd Zaku/khipu

# Install dependencies
pip install -e ".[dev]"

Running Tests

# Format code
black .

# Lint code
flake8 .

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Links

Support

For issues and questions:

  • Open an issue on GitHub
  • Contact Khipu support for API-related questions

Disclaimer

This is an unofficial client library. For official support and documentation, please refer to Khipu's official documentation.

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

py_khipu_client-0.1.3.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

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

py_khipu_client-0.1.3-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file py_khipu_client-0.1.3.tar.gz.

File metadata

  • Download URL: py_khipu_client-0.1.3.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for py_khipu_client-0.1.3.tar.gz
Algorithm Hash digest
SHA256 f007dbebfb83a6eb181ad11b60d52a90d5a1fa8e5e7b7a9721cd225d1168d152
MD5 4c388f25f4ad81f73c5b702d738fdabc
BLAKE2b-256 a614376cb0b4ebe21cecf4f116125ab9f101ed2e3c2ae5d25bd5b2ab43039c40

See more details on using hashes here.

File details

Details for the file py_khipu_client-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for py_khipu_client-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 06aa5d90db2fc5c106bf0f53c9644536da022adf3240afe4cecf8e4ae21bdd72
MD5 72a12900ac91823f441da91e145014e4
BLAKE2b-256 cf461a08cd17e4c841283be2bd602b2fb8d13fdc59f1f66c3b6f8e3c2d5c01dd

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