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 fromres.partner.bankamount(float): Payment amount in THBref1(str): Reference 1, max 20 charactersref2(str): Reference 2, max 12 charactersref3(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 keyaccess_token(str): Valid OAuth tokenqr_create_url(str): SCB QR endpoint URLbiller_id(str): PromptPay biller IDamount(float): Payment amount in THBref1(str): Reference 1, max 20 charactersref2(str): Reference 2, max 12 charactersref3(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 keyapi_secret(str): SCB API secrettoken_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 IDamount(float): Payment amountreference(str): Payment referencechannel(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.5.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 configured9002: Failed to connect to database9003: No SCB configuration found for bank account9004: Invalid SCB API configuration (missing required fields)
Network Errors (91xx):
9101: Network error connecting to SCB token endpoint9102: Network error connecting to SCB QR endpoint9103: HTTP error from SCB API (see description for details)
Authentication Errors (93xx):
9301: Failed to refresh SCB access token9302: 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
- Use High-Level API: Prefer
create_qr_by_bank_account()for automatic configuration management - Validate References: Keep ref1 ≤ 20 chars, ref2 ≤ 12 chars
- Check Status Codes: Always verify
status.code == 1000before using data - Handle Errors: Wrap API calls in try-except blocks
- 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)
Support & Contact
- Sales & Licensing: sales@nellika.co.th
- Technical Support: support@nellika.co.th
- Privacy Inquiries: privacy@nellika.co.th
- Website: https://nellika.co.th
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nell_scb_lib-1.5.4-cp314-cp314-macosx_14_0_arm64.whl.
File metadata
- Download URL: nell_scb_lib-1.5.4-cp314-cp314-macosx_14_0_arm64.whl
- Upload date:
- Size: 4.5 MB
- Tags: CPython 3.14, macOS 14.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a556c22ffbb3018ba4421c05ac8729715f9538bd94ee55037d7f81d4b02e86d2
|
|
| MD5 |
14826851c985fbfdc4b0c15198b63f49
|
|
| BLAKE2b-256 |
981007a7e84d26981d27fad49d4ada754ed77924b96e26acae01d22527e288d1
|
File details
Details for the file nell_scb_lib-1.5.4-cp313-cp313-macosx_14_0_arm64.whl.
File metadata
- Download URL: nell_scb_lib-1.5.4-cp313-cp313-macosx_14_0_arm64.whl
- Upload date:
- Size: 4.5 MB
- Tags: CPython 3.13, macOS 14.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8b81af2819d67268bb62b4c54f793f75c3dcbe7f38ff1cb22a5f0ab35b2e8cad
|
|
| MD5 |
037070e096750f7c4270126f8460e5ba
|
|
| BLAKE2b-256 |
759a84af518eb6a0bc4fb5e8ca2463550d1ddc0afdbfc1ce40ae8347af63e088
|
File details
Details for the file nell_scb_lib-1.5.4-cp312-cp312-manylinux_2_38_x86_64.whl.
File metadata
- Download URL: nell_scb_lib-1.5.4-cp312-cp312-manylinux_2_38_x86_64.whl
- Upload date:
- Size: 7.3 MB
- Tags: CPython 3.12, manylinux: glibc 2.38+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
05b78084c8332286ee96c90693b0e8e820244f1963ec9da6c54f78a03e606636
|
|
| MD5 |
c37430834f5618c26f2f6e750abc68f9
|
|
| BLAKE2b-256 |
80c336cd034ed4ed48b2417f7d170622a3f3bca5fffbb6592e797b3ff7140058
|
File details
Details for the file nell_scb_lib-1.5.4-cp312-cp312-manylinux_2_34_x86_64.whl.
File metadata
- Download URL: nell_scb_lib-1.5.4-cp312-cp312-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 7.0 MB
- Tags: CPython 3.12, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0b8b1a13e7701a67be90c408b22bc5a2b974ca2a2a85a2f5621d9b281489ded9
|
|
| MD5 |
f39422c3c5dec3a3444adc4c08b2fe0d
|
|
| BLAKE2b-256 |
ad3f13fc7e5972a4cebd1b4a3341ecc5577b18040a1561d764a972705f2b3b3b
|
File details
Details for the file nell_scb_lib-1.5.4-cp312-cp312-macosx_14_0_arm64.whl.
File metadata
- Download URL: nell_scb_lib-1.5.4-cp312-cp312-macosx_14_0_arm64.whl
- Upload date:
- Size: 4.5 MB
- Tags: CPython 3.12, macOS 14.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
00561f8b546031f7dcb46c5592c15e827cf313cff2b1ea626bb7d130385f76c6
|
|
| MD5 |
17432a5e01917aa2bca917266beb2261
|
|
| BLAKE2b-256 |
673635f1f26f2d8e1b56173a3cfccbd97142c622ede79c1481f845da729653d0
|
File details
Details for the file nell_scb_lib-1.5.4-cp311-cp311-macosx_14_0_arm64.whl.
File metadata
- Download URL: nell_scb_lib-1.5.4-cp311-cp311-macosx_14_0_arm64.whl
- Upload date:
- Size: 4.5 MB
- Tags: CPython 3.11, macOS 14.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f33dc95af18cc22949537739bd47ec02bfd4701a7a736432a667f3725a20afa1
|
|
| MD5 |
162cbe155b79c894f152b3e179af3d93
|
|
| BLAKE2b-256 |
5f97198334edf30a696eb9054e8c38c5eea48ac19f2607400e0f9ffd2edde1cf
|
File details
Details for the file nell_scb_lib-1.5.4-cp310-cp310-manylinux_2_34_x86_64.whl.
File metadata
- Download URL: nell_scb_lib-1.5.4-cp310-cp310-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 7.0 MB
- Tags: CPython 3.10, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
99f1a377307c932e74c8ce877f079379fb3b4d0294e0c6760af7a7101ae443fc
|
|
| MD5 |
6d38f5ef263bc979de522331176a1629
|
|
| BLAKE2b-256 |
1a3f10eabbfea060b69568bccad2c64f7a0c8d363b838dd32c9b94a9b61a9052
|
File details
Details for the file nell_scb_lib-1.5.4-cp310-cp310-macosx_14_0_arm64.whl.
File metadata
- Download URL: nell_scb_lib-1.5.4-cp310-cp310-macosx_14_0_arm64.whl
- Upload date:
- Size: 4.5 MB
- Tags: CPython 3.10, macOS 14.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
66e3615383f79e86011f1811b70b1a3784b2085cce6b43a35627f70e0f2058cc
|
|
| MD5 |
0aef909c267784d67029fcd7aa784200
|
|
| BLAKE2b-256 |
b006d6727d92fde85d985c70f98d181b434bbfc3129cf99b74bb997dadcbbf6c
|
File details
Details for the file nell_scb_lib-1.5.4-cp39-cp39-macosx_14_0_arm64.whl.
File metadata
- Download URL: nell_scb_lib-1.5.4-cp39-cp39-macosx_14_0_arm64.whl
- Upload date:
- Size: 4.5 MB
- Tags: CPython 3.9, macOS 14.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
694d358aaa94f93b8ccd500c308a32a461973639ee2e7d037bb56dc54a5b3c34
|
|
| MD5 |
4551a44d96a1e59e19fb2d033540ca9a
|
|
| BLAKE2b-256 |
c3f1496ff755fc2872cdd163d26eb2f87a0dd238b4335092b530d1d069880aa0
|