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.2.tar.gz (5.3 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.2-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: py_khipu_client-0.1.2.tar.gz
  • Upload date:
  • Size: 5.3 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.2.tar.gz
Algorithm Hash digest
SHA256 d47f2bbb725064f275ea33b543d5b8a7decd53e28121ae4aae3711b5b5997f17
MD5 8914b91fd20a5332bf7ea6e403ecbfbf
BLAKE2b-256 00521c2e891cd0bea2f0368fd3ad0e012a4a289e7eab6c9252a4be4c767a6870

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for py_khipu_client-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ded2debb850b2ffc687a88b3066145f6d3ef3f4e79f45b6b5b092f9913345813
MD5 00bca0baafaebbad715972a7eaca1f0e
BLAKE2b-256 36c42885589ac62609f3ae226ab97bbb16277c0e94941ffedfef784f9016465c

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