Skip to main content

Official Python SDK for 9PAY Payment Gateway

Project description

9PAY Payment Gateway Python SDK

PyPI version Python versions Downloads License

Official Python SDK for integrating 9PAY Payment Gateway.

English | Tiếng Việt


English

🚀 Quick Start (Recommended)

  1. Install SDK:

    pip install ninepay-sdk python-dotenv
    
  2. Configure Environment: Copy .env.example to .env and fill in your credentials.

    cp .env.example .env
    
    NINEPAY_MERCHANT_ID=your_merchant_id
    NINEPAY_SECRET_KEY=your_secret_key
    NINEPAY_CHECKSUM_KEY=your_checksum_key
    NINEPAY_ENV=SANDBOX
    NINEPAY_ENDPOINT=9pay_endpoint
    
  3. Usage:

    from ninepay import NinePayConfig, NinePayGateway
    
    # Load config automatically from .env
    config = NinePayConfig.from_env()
    gateway = NinePayGateway(config)
    

📦 Features

  • Dynamic Config: Managed via .env files (PHP/Laravel style)
  • Secure: Signature generation and verification (HMAC-SHA256)
  • Comprehensive API:
    • Portal Payment (Redirect)
    • Transaction Inquiry
    • Refunds (Full/Partial)
    • Card Payment Flow (Payer Auth, Authorize, Capture, Reverse)
  • Framework Friendly: Ready for Django, Flask, FastAPI

🛠 Installation

pip install ninepay-sdk

💡 Example: Create Payment

from ninepay import CreatePaymentRequest, PaymentMethod, Currency, Language
import time

request = CreatePaymentRequest(
    invoice_no=f'INV_{int(time.time())}',
    amount='50000',
    description='Order #12345',
    back_url='https://yoursite.com/cancel',
    return_url='https://yoursite.com/success'
).with_method(PaymentMethod.CREDIT_CARD).with_lang(Language.EN)

response = gateway.create_payment(request)
if response.is_success():
    print(f"Redirect URL: {response.get_data()['redirect_url']}")

Tiếng Việt

🚀 Bắt đầu nhanh (Khuyên dùng)

  1. Cài đặt:

    pip install ninepay-sdk python-dotenv
    
  2. Cấu hình môi trường: Copy .env.example thành .env và điền thông tin của bạn.

    cp .env.example .env
    
  3. Sử dụng:

    from ninepay import NinePayConfig, NinePayGateway
    
    # Tự động load cấu hình từ file .env
    config = NinePayConfig.from_env()
    gateway = NinePayGateway(config)
    

✨ Tính năng chính

  • Cấu hình tập trung: Quản lý qua file .env (giống Laravel/PHP)
  • Bảo mật: Tự động tạo và xác thực chữ ký chuẩn HMAC-SHA256
  • Đầy đủ API:
    • Tạo thanh toán Portal (Redirect)
    • Truy vấn đơn hàng (Inquiry)
    • Hoàn tiền (Refund)
    • Luồng thẻ nâng cao (Payer Auth, Authorize, Capture, Reverse)
  • Dễ tích hợp: Tương thích tốt với Django, Flask, FastAPI

💡 Ví dụ: Truy vấn đơn hàng

# Truy vấn đơn hàng theo transaction ID (mã 9Pay) hoặc Invoice No
response = gateway.inquiry("454518005824417")
if response.is_success():
    print(f"Trạng thái đơn hàng: {response.get_data()['status']}")

🖥 Chạy Demo

Bạn có thể chạy script demo để kiểm tra nhanh:

python demo.py

🧪 Chạy Test

python -m unittest discover tests -v

Licensed under MIT.

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

ninepay_sdk-1.3.0.tar.gz (20.5 kB view details)

Uploaded Source

Built Distribution

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

ninepay_sdk-1.3.0-py3-none-any.whl (22.2 kB view details)

Uploaded Python 3

File details

Details for the file ninepay_sdk-1.3.0.tar.gz.

File metadata

  • Download URL: ninepay_sdk-1.3.0.tar.gz
  • Upload date:
  • Size: 20.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for ninepay_sdk-1.3.0.tar.gz
Algorithm Hash digest
SHA256 f291ea8938536effcfce824112d44b9d3c700e6c3d2fa4fa764bb44a7be263e7
MD5 aaacd5826c7f46cf341c43083c9d66f4
BLAKE2b-256 1379505f654231e25cfb56a0ea252ffdd45fc6c95fabc009d62ebfa143564ec1

See more details on using hashes here.

File details

Details for the file ninepay_sdk-1.3.0-py3-none-any.whl.

File metadata

  • Download URL: ninepay_sdk-1.3.0-py3-none-any.whl
  • Upload date:
  • Size: 22.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for ninepay_sdk-1.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9255c69302ad7d814f8383257a8138dba9633eed29a1e4c8085760df25b0634b
MD5 d497e7d3f8628f820863cccaa929bc6d
BLAKE2b-256 7af293897f7bf2a4478f2785bf44859de036249af34a68e19edff71d88a1d9a8

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