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.0.tar.gz (5.8 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.0-py3-none-any.whl (8.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: py_khipu_client-0.1.0.tar.gz
  • Upload date:
  • Size: 5.8 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.0.tar.gz
Algorithm Hash digest
SHA256 b6a0a2335da2bb7de2cf71375a0607245444812639c043007778055ed36c488b
MD5 5dc2fc3abbdfc0d66f8ace2979db9e0a
BLAKE2b-256 e8a4c444ad9d4e1d51a915cf3fdd198dacb946b8e8147ce5a0fee40a75d39779

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for py_khipu_client-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8b5cb4e24d03d9c4297382f85153f6bdecb110df7a66d4cd1393b11735ac68a2
MD5 9f5de230c7b36a1f1f53f6ba617176db
BLAKE2b-256 8efad46139c2b36b044dd2a26abbac64cf6f802f8ac10013ad1f33b13f3a0aba

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