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 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.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: Success1001: Invalid request1002: Authentication failed1003: Insufficient balance1004: Transaction not found1005: 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
- 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)
License
Proprietary - Nellika Consulting Services
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.1.0-cp314-cp314-macosx_14_0_arm64.whl.
File metadata
- Download URL: nell_scb_lib-1.1.0-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 |
55e628e04208357c6965f678ff4193252520e873fd17e6b70a816fdc0e3729d3
|
|
| MD5 |
3aaea3fcb33af9495b256a2caaf87edb
|
|
| BLAKE2b-256 |
239152d3486a8285678fa2f68a38d8777015c1ef1d07c2b2614eaeac060eccd9
|
File details
Details for the file nell_scb_lib-1.1.0-cp313-cp313-macosx_14_0_arm64.whl.
File metadata
- Download URL: nell_scb_lib-1.1.0-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 |
45330a95bcc34206e8396863e7d0b8e67da5975633a12d8312d32f617ecc6edc
|
|
| MD5 |
e5e97f9fa8a9d676fe48a8875d42fa0c
|
|
| BLAKE2b-256 |
7044cbaccf62709126ab8bea2d476a67f78e6bd6b1b0c644e482c17f136b509f
|
File details
Details for the file nell_scb_lib-1.1.0-cp312-cp312-manylinux_2_38_x86_64.whl.
File metadata
- Download URL: nell_scb_lib-1.1.0-cp312-cp312-manylinux_2_38_x86_64.whl
- Upload date:
- Size: 7.2 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 |
3487874b2667e38d90e49214374cabfb595e84415da01293fb62b1b1be8328f7
|
|
| MD5 |
3a7abd71e0a1b1ab3562c643aa3acf96
|
|
| BLAKE2b-256 |
5be16bdd4e735c50945b930c4b2e1edf1b4192f412a9cc96fbf183201bee63c0
|
File details
Details for the file nell_scb_lib-1.1.0-cp312-cp312-macosx_14_0_arm64.whl.
File metadata
- Download URL: nell_scb_lib-1.1.0-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 |
63aa4cc139b515d49a8f21e74157e0ca567b2950269587003968ea8102e0d0bf
|
|
| MD5 |
8df66d7e70b8c0e44fd4e27810d6f8ab
|
|
| BLAKE2b-256 |
8a6506505369fce43c74d7f9f5e200906656b8b037e21c3fbc5143d225c3ebe6
|
File details
Details for the file nell_scb_lib-1.1.0-cp311-cp311-macosx_14_0_arm64.whl.
File metadata
- Download URL: nell_scb_lib-1.1.0-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 |
ee7a338c8ceb1d767f403a61077b4a551ef026990f695de3e1f19998d8c622d3
|
|
| MD5 |
3155d51a102bad76254851bbe58f5654
|
|
| BLAKE2b-256 |
2868999b73e38e496968660a17be9ae9118f8e6f28d3de1c83ba35dd45b8630e
|
File details
Details for the file nell_scb_lib-1.1.0-cp310-cp310-manylinux_2_34_x86_64.whl.
File metadata
- Download URL: nell_scb_lib-1.1.0-cp310-cp310-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 6.9 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 |
cd5d5a901ec6c89322498bdd45421b617d61dc6a6e50958a50d95014d88b821f
|
|
| MD5 |
4f3240f9a4c02439f50f38447407e223
|
|
| BLAKE2b-256 |
c3c0306c5d88d18eb29ae58b5396321313c9b306129476436f062605377b56a7
|
File details
Details for the file nell_scb_lib-1.1.0-cp310-cp310-macosx_14_0_arm64.whl.
File metadata
- Download URL: nell_scb_lib-1.1.0-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 |
c2c1677c935b13e005e7f613723551ead6f21df5ec0ccf0def17efdb48dd3838
|
|
| MD5 |
7b456be94cdd72225d3a9e65842370e9
|
|
| BLAKE2b-256 |
8c006c64baf88348621aba54eaa85ab5245e83ba438da5a436d2aea5ee23fc78
|
File details
Details for the file nell_scb_lib-1.1.0-cp39-cp39-macosx_14_0_arm64.whl.
File metadata
- Download URL: nell_scb_lib-1.1.0-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 |
023b6046f66c9fee63c3662243fe9a2ff59e8605fd80188f9ec86cc240246ad2
|
|
| MD5 |
02ac594eeda44d94f4c6e10d1e8e5074
|
|
| BLAKE2b-256 |
2a05ce56f9bb2e520bb64307ba69e3fef27633f4eef2b6aba5561f2dd9c6d5de
|