Skip to main content

Nellika SCB Payment Integration - Hardened C Module

Project description

nell-scb-lib

Python C extension for SCB (Siam Commercial Bank) payment integration with PromptPay QR code generation.

Overview

nell-scb-lib is a high-performance C extension module providing SCB payment integration for Python applications. It handles OAuth token management, QR code generation, and payment status checking through SCB's official API.

Installation

pip install nell-scb-lib

Supported Platforms:

  • Linux x86_64 (manylinux)
  • macOS ARM64 (Apple Silicon M1/M2/M3)
  • Python 3.8+

Quick Start

import nell_scb_lib

# Create QR payment (database-driven, recommended)
result = nell_scb_lib.create_qr_by_bank_account(
    bank_account_id=1,
    amount=250.75,
    ref1="P00001",      # Invoice number (max 20 chars)
    ref2="CUST001",     # Customer code (max 12 chars)
    ref3="SCB"          # Optional reference
)

if result['status']['code'] == 1000:
    qr_image = result['data']['qrImage']  # Base64 PNG
    qr_raw = result['data']['qrRawData']  # PromptPay string
    print(f"QR created: {result['data']['transactionId']}")

Environment Variables

Required for database-driven methods:

export PGDATABASE=your_database
export PGHOST=localhost
export PGPORT=5432
export PGUSER=odoo
export PGPASSWORD=your_password  # optional

API Reference

High-Level API (Recommended)

create_qr_by_bank_account(bank_account_id, amount, ref1, ref2, ref3="SCB")

Create SCB QR payment code using bank account ID. Automatically fetches configuration from database and manages token refresh.

Parameters:

  • bank_account_id (str/int): Bank account ID from res.partner.bank
  • amount (float): Payment amount in THB
  • ref1 (str): Reference 1, max 20 characters
  • ref2 (str): Reference 2, max 12 characters
  • ref3 (str, optional): Reference 3, defaults to "SCB"

Returns: dict - SCB API response

{
    "status": {"code": 1000, "description": "Success"},
    "data": {
        "qrRawData": "00020101021230...",
        "qrImage": "iVBORw0KGgoAAAANSUhEUgAA...",
        "transactionId": "..."
    }
}

Example:

result = nell_scb_lib.create_qr_by_bank_account(
    bank_account_id=1,
    amount=250.75,
    ref1="P00001",
    ref2="CUST001"
)

Mid-Level API

create_qr_full(api_key, access_token, qr_create_url, biller_id, amount, ref1, ref2, ref3="SCB")

Create SCB QR code with explicit parameters (requires manual token management).

Parameters:

  • api_key (str): SCB API key
  • access_token (str): Valid OAuth token
  • qr_create_url (str): SCB QR endpoint URL
  • biller_id (str): PromptPay biller ID
  • amount (float): Payment amount in THB
  • ref1 (str): Reference 1, max 20 characters
  • ref2 (str): Reference 2, max 12 characters
  • ref3 (str, optional): Reference 3, defaults to "SCB"

Returns: dict - SCB API response

Example:

# Step 1: Get access token
token_resp = nell_scb_lib.refresh_token(api_key, api_secret, token_url)
access_token = token_resp['data']['accessToken']

# Step 2: Create QR
result = nell_scb_lib.create_qr_full(
    api_key="your_api_key",
    access_token=access_token,
    qr_create_url="https://api.scb/...",
    biller_id="894547854396914",
    amount=100.50,
    ref1="P00001",
    ref2="TEST"
)

refresh_token(api_key, api_secret, token_url)

Refresh SCB OAuth access token.

Parameters:

  • api_key (str): SCB API key
  • api_secret (str): SCB API secret
  • token_url (str): Token endpoint URL

Returns: dict - Token response

{
    "status": {"code": 1000, "description": "Success"},
    "data": {
        "accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
        "expiresIn": 1800,
        "tokenType": "Bearer"
    }
}

Low-Level API

create_qr(config_id, amount, reference, channel="ecomm")

Create QR code using config ID from database (legacy method).

Parameters:

  • config_id (str): SCB API configuration ID
  • amount (float): Payment amount
  • reference (str): Payment reference
  • channel (str, optional): Payment channel, defaults to "ecomm"

Returns: dict - SCB API response


check_payment(reference)

Check SCB payment status by reference.

Parameters:

  • reference (str): Payment reference to check

Returns: dict - Payment status

{
    "status": {"code": 1000, "description": "Success"},
    "data": {
        "paymentStatus": "SUCCESS",
        "transactionId": "...",
        "amount": 100.50
    }
}

version()

Get module version string.

Returns: str - Version (e.g., "1.0.1")


Database Schema Requirements

For database-driven methods, these tables are required:

res_partner_bank:

  • Column: scb_biller_id (VARCHAR) - PromptPay biller ID

scb_api_config:

  • Columns: api_key, api_secret, environment, token_url, qr_create_url, payment_inquiry_url
  • Must have active configuration record

Error Handling

All functions raise RuntimeError for failures:

try:
    result = nell_scb_lib.create_qr_by_bank_account(
        bank_account_id=1,
        amount=250.75,
        ref1="P00001",
        ref2="CUST001"
    )
    
    if result['status']['code'] == 1000:
        # Success
        qr_data = result['data']
    else:
        # API error
        print(f"Error: {result['status']['description']}")
        
except RuntimeError as e:
    # System error
    print(f"Failed: {e}")

Response Status Codes

  • 1000: Success
  • 1001: Invalid request
  • 1002: Authentication failed
  • 1003: Insufficient balance
  • 1004: Transaction not found
  • 1005: System error

Always check the status code:

if result['status']['code'] == 1000:
    # Process successful response
    pass
else:
    # Handle error
    error_msg = result['status']['description']

Best Practices

  1. Use High-Level API: Prefer create_qr_by_bank_account() for automatic configuration management
  2. Validate References: Keep ref1 ≤ 20 chars, ref2 ≤ 12 chars
  3. Check Status Codes: Always verify status.code == 1000 before using data
  4. Handle Errors: Wrap API calls in try-except blocks
  5. Environment Setup: Configure PostgreSQL environment variables before use

Features

  • ✅ Native C implementation for high performance
  • ✅ Automatic OAuth token management
  • ✅ Database-driven configuration
  • ✅ PromptPay QR code generation
  • ✅ Payment status checking
  • ✅ Thread-safe operations
  • ✅ Secure API communication (libcurl)

License

Proprietary - Nellika Consulting Services

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

nell_scb_lib-1.1.0-cp314-cp314-macosx_14_0_arm64.whl (4.5 MB view details)

Uploaded CPython 3.14macOS 14.0+ ARM64

nell_scb_lib-1.1.0-cp313-cp313-macosx_14_0_arm64.whl (4.5 MB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

nell_scb_lib-1.1.0-cp312-cp312-manylinux_2_38_x86_64.whl (7.2 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.38+ x86-64

nell_scb_lib-1.1.0-cp312-cp312-macosx_14_0_arm64.whl (4.5 MB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

nell_scb_lib-1.1.0-cp311-cp311-macosx_14_0_arm64.whl (4.5 MB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

nell_scb_lib-1.1.0-cp310-cp310-manylinux_2_34_x86_64.whl (6.9 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64

nell_scb_lib-1.1.0-cp310-cp310-macosx_14_0_arm64.whl (4.5 MB view details)

Uploaded CPython 3.10macOS 14.0+ ARM64

nell_scb_lib-1.1.0-cp39-cp39-macosx_14_0_arm64.whl (4.5 MB view details)

Uploaded CPython 3.9macOS 14.0+ ARM64

File details

Details for the file nell_scb_lib-1.1.0-cp314-cp314-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for nell_scb_lib-1.1.0-cp314-cp314-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 55e628e04208357c6965f678ff4193252520e873fd17e6b70a816fdc0e3729d3
MD5 3aaea3fcb33af9495b256a2caaf87edb
BLAKE2b-256 239152d3486a8285678fa2f68a38d8777015c1ef1d07c2b2614eaeac060eccd9

See more details on using hashes here.

File details

Details for the file nell_scb_lib-1.1.0-cp313-cp313-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for nell_scb_lib-1.1.0-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 45330a95bcc34206e8396863e7d0b8e67da5975633a12d8312d32f617ecc6edc
MD5 e5e97f9fa8a9d676fe48a8875d42fa0c
BLAKE2b-256 7044cbaccf62709126ab8bea2d476a67f78e6bd6b1b0c644e482c17f136b509f

See more details on using hashes here.

File details

Details for the file nell_scb_lib-1.1.0-cp312-cp312-manylinux_2_38_x86_64.whl.

File metadata

File hashes

Hashes for nell_scb_lib-1.1.0-cp312-cp312-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 3487874b2667e38d90e49214374cabfb595e84415da01293fb62b1b1be8328f7
MD5 3a7abd71e0a1b1ab3562c643aa3acf96
BLAKE2b-256 5be16bdd4e735c50945b930c4b2e1edf1b4192f412a9cc96fbf183201bee63c0

See more details on using hashes here.

File details

Details for the file nell_scb_lib-1.1.0-cp312-cp312-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for nell_scb_lib-1.1.0-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 63aa4cc139b515d49a8f21e74157e0ca567b2950269587003968ea8102e0d0bf
MD5 8df66d7e70b8c0e44fd4e27810d6f8ab
BLAKE2b-256 8a6506505369fce43c74d7f9f5e200906656b8b037e21c3fbc5143d225c3ebe6

See more details on using hashes here.

File details

Details for the file nell_scb_lib-1.1.0-cp311-cp311-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for nell_scb_lib-1.1.0-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 ee7a338c8ceb1d767f403a61077b4a551ef026990f695de3e1f19998d8c622d3
MD5 3155d51a102bad76254851bbe58f5654
BLAKE2b-256 2868999b73e38e496968660a17be9ae9118f8e6f28d3de1c83ba35dd45b8630e

See more details on using hashes here.

File details

Details for the file nell_scb_lib-1.1.0-cp310-cp310-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for nell_scb_lib-1.1.0-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 cd5d5a901ec6c89322498bdd45421b617d61dc6a6e50958a50d95014d88b821f
MD5 4f3240f9a4c02439f50f38447407e223
BLAKE2b-256 c3c0306c5d88d18eb29ae58b5396321313c9b306129476436f062605377b56a7

See more details on using hashes here.

File details

Details for the file nell_scb_lib-1.1.0-cp310-cp310-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for nell_scb_lib-1.1.0-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 c2c1677c935b13e005e7f613723551ead6f21df5ec0ccf0def17efdb48dd3838
MD5 7b456be94cdd72225d3a9e65842370e9
BLAKE2b-256 8c006c64baf88348621aba54eaa85ab5245e83ba438da5a436d2aea5ee23fc78

See more details on using hashes here.

File details

Details for the file nell_scb_lib-1.1.0-cp39-cp39-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for nell_scb_lib-1.1.0-cp39-cp39-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 023b6046f66c9fee63c3662243fe9a2ff59e8605fd80188f9ec86cc240246ad2
MD5 02ac594eeda44d94f4c6e10d1e8e5074
BLAKE2b-256 2a05ce56f9bb2e520bb64307ba69e3fef27633f4eef2b6aba5561f2dd9c6d5de

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