Skip to main content

Nellika SCB Payment Integration - Hardened C Module (Commercial License Required)

Project description

nell-scb-lib

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

⚠️ IMPORTANT LICENSING INFORMATION

This software is subject to commercial licensing terms and usage fees.

  • This library requires a valid commercial license for production use
  • Usage telemetry data is collected and transmitted to Nellika Consulting Services Ltd.
  • By installing and using this library, you agree to the collection and transmission of usage telemetry
  • For licensing inquiries and pricing information, please contact: sales@nellika.co.th

Copyright © 2024 Nellika Consulting Services Ltd. All rights reserved.


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_2_31+)
  • macOS ARM64 (Apple Silicon M1/M2/M3/M4)
  • Python 3.9 through 3.14

Telemetry & Privacy

This library collects the following telemetry data:

  • License key usage and validation events
  • API operation counts (QR creation, token refresh, payment checks)
  • Error rates and types
  • Library version and platform information
  • No sensitive data (API keys, secrets, transaction details, or customer information) is collected

Telemetry helps us:

  • Monitor license compliance
  • Improve library stability and performance
  • Provide better support to our customers

By using this library, you consent to this data collection.

For questions about data collection or to request data deletion, contact: privacy@nellika.co.th


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.2.4")


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 (v1.2.0+)

All functions return dicts with status and data keys. Check status.code to determine success/failure.

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 - use the data
    qr_image = result['data']['qrImage']
    transaction_id = result['data']['transactionId']
    print(f"QR created: {transaction_id}")
else:
    # Error - check the code and description
    error_code = result['status']['code']
    error_msg = result['status']['description']
    print(f"Error {error_code}: {error_msg}")
    
    # Handle specific errors
    if error_code == 5114:
        print("Incorrect biller ID - check your bank account configuration")
    elif error_code in [9001, 9002]:
        print("Database connection issue - check environment variables")
    elif error_code == 9003:
        print("SCB configuration not found for this bank account")

Response Status Codes

Success Codes (1xxx)

  • 1000: Success

SCB API Errors (5xxx)

These are errors returned directly from SCB's API:

  • 5114: Incorrect biller ID - verify PromptPay biller ID in database
  • Other 5xxx codes: See SCB API documentation

System Errors (9xxx)

Database Errors (90xx):

  • 9001: Database environment variables not configured
  • 9002: Failed to connect to database
  • 9003: No SCB configuration found for bank account
  • 9004: Invalid SCB API configuration (missing required fields)

Network Errors (91xx):

  • 9101: Network error connecting to SCB token endpoint
  • 9102: Network error connecting to SCB QR endpoint
  • 9103: HTTP error from SCB API (see description for details)

Authentication Errors (93xx):

  • 9301: Failed to refresh SCB access token
  • 9302: Token refresh failed with HTTP error

Always check the status code:

if result['status']['code'] == 1000:
    # Process successful response
    qr_data = result['data']
else:
    # Handle error - log or display to user
    error_code = result['status']['code']
    error_msg = result['status']['description']
    
    # Example: Raise user-friendly error in Odoo
    if error_code in [5114, 9003, 9004]:
        # Configuration error - show to admin
        raise UserError(f"SCB Configuration Error: {error_msg}")
    else:
        # System error - log it
        _logger.error(f"SCB API error {error_code}: {error_msg}")

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)
  • ✅ Built-in license management
  • ✅ Usage telemetry for compliance and support

Changelog

See CHANGELOG.md for detailed version history.

Latest Releases

v1.2.4 (2024-12-02)

  • PERFORMANCE: Automatic token caching in database
  • Reduces token refresh API calls by ~95% (~30/day instead of ~100+/day)
  • Token management now completely abstracted in C library
  • Faster QR generation (no auth overhead when token is cached)

v1.2.3 (2024-12-02)

  • 🔴 CRITICAL FIX: Corrected SCB config selection when multiple configs exist
  • Fixed "Incorrect biller Id" errors (SCB 5114)
  • Added detailed logging for Bank ID, Config ID, Biller ID

v1.2.2 (2024-12-01)

  • Added companies data to USAGE telemetry
  • Improved bump-version script with auto-detection

v1.2.1 (2024-12-01)

  • Updated documentation with error codes

v1.2.0 (2024-12-01)

  • BREAKING: API now returns dicts instead of raising exceptions
  • Comprehensive error response framework
  • Error codes: 1xxx (success), 5xxx (SCB API), 9xxx (system)

View Full Changelog →


Support & Contact

Legal

Copyright © 2024 Nellika Consulting Services Ltd. All rights reserved.

This software is proprietary and confidential. Unauthorized copying, distribution, or use of this software, via any medium, is strictly prohibited without prior written permission from Nellika Consulting Services Ltd.

For licensing terms and conditions, please contact sales@nellika.co.th

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.2.4-cp314-cp314-macosx_14_0_arm64.whl (4.5 MB view details)

Uploaded CPython 3.14macOS 14.0+ ARM64

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

Uploaded CPython 3.13macOS 14.0+ ARM64

nell_scb_lib-1.2.4-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.2.4-cp312-cp312-manylinux_2_34_x86_64.whl (7.0 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

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

Uploaded CPython 3.12macOS 14.0+ ARM64

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

Uploaded CPython 3.11macOS 14.0+ ARM64

nell_scb_lib-1.2.4-cp310-cp310-manylinux_2_34_x86_64.whl (7.0 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64

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

Uploaded CPython 3.10macOS 14.0+ ARM64

nell_scb_lib-1.2.4-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.2.4-cp314-cp314-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for nell_scb_lib-1.2.4-cp314-cp314-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 802fafd830efa9e0725f2eb7d328b83d879a06015a5181207054ef4977a7994a
MD5 25914efca9550d460d2e6e7f7ed57902
BLAKE2b-256 6d4dba678056126cf979f65622da14a91a6ff2299480799cf3017a0583f65019

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for nell_scb_lib-1.2.4-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 5629941c9bef43ed701c68d21a77cc1e67e0eb5a93d77b96f29b9ebe9e98ff8d
MD5 a946185a3a086c9185055d293765ec81
BLAKE2b-256 3102a8e823a0d469b10a891e6fda01792c4c0a7e7aaca32a7f33a47540a66b1a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for nell_scb_lib-1.2.4-cp312-cp312-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 b428ca66e484a94767a32b6d738b5ba18534f18e692691045fa4ccfcd5c7c9fc
MD5 bc1ab9be66819ec065c4eef1868146fc
BLAKE2b-256 4ab215b6bd11054100a8da7f55ad395fbfec8dcc70110a29bfe8ab5a2f1eb3e1

See more details on using hashes here.

File details

Details for the file nell_scb_lib-1.2.4-cp312-cp312-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for nell_scb_lib-1.2.4-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 96b3bc26c303af68d5bd784016a2850d015767a151e0e645a78688c46d7b2726
MD5 6745a9b1a4de97bec79ac27b935ac820
BLAKE2b-256 f83a7afe084acc48c4ecdbcf7430849a827be9158e30cbb03d9084ec3ab0c90e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for nell_scb_lib-1.2.4-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 b5a25ba3326b5ff805a629d6690fadae852f615a7276b1f1ab2bdd2dd574a173
MD5 99a4ed1f565a6052cf0c9b5fb3d40e52
BLAKE2b-256 604699aa1349851265964a943bbf5864e51fe096591097328d5d61488c5fe81f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for nell_scb_lib-1.2.4-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 fb7a29b0e6ed77c2f12e86bd0c5ea12d8ac1c4e2d51437673f1fe9ad7a91bb28
MD5 8ab88c8f4fbaca10e62c41312a60c119
BLAKE2b-256 108a516d49daed9d3e89e3e3b8203449682dc67a9bce65edbbf337f2f069d714

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for nell_scb_lib-1.2.4-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 797cf6df534f4138a24f4b4c1d98d58159d09df462968b84598cef50b02b457b
MD5 d35e239e70402ede207c44ec0c5043f1
BLAKE2b-256 1cb23e8c14bc1420cba1d9e4ec68e66044ac700c05633842e5c7738b1824bd9f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for nell_scb_lib-1.2.4-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 6ff23cc1b081850d3dced02d4c49fdc3d36d1138e707b7a72362658e03805769
MD5 7006587a1caafdf4e94e6433d288066f
BLAKE2b-256 77639e14c2a1c5a15c0e60ffc65131ffa492045e9313140af39efc14960576f9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for nell_scb_lib-1.2.4-cp39-cp39-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 4a0a78349366d8aecc547228b2ba94e47da413ac1c456b62090b51fd9d138df4
MD5 f25fb256d3779234057e5e946c3269d5
BLAKE2b-256 59e85e6fbca10b31b02668c689b0caea4fad03992df8f340ca088a24274a0113

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