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

Uploaded CPython 3.14macOS 14.0+ ARM64

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

Uploaded CPython 3.13macOS 14.0+ ARM64

nell_scb_lib-1.0.3-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.0.3-cp312-cp312-macosx_14_0_arm64.whl (4.5 MB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

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

Uploaded CPython 3.11macOS 14.0+ ARM64

nell_scb_lib-1.0.3-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.0.3-cp310-cp310-macosx_14_0_arm64.whl (4.5 MB view details)

Uploaded CPython 3.10macOS 14.0+ ARM64

File details

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

File metadata

File hashes

Hashes for nell_scb_lib-1.0.3-cp314-cp314-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 92130234ac7101a3b0a4c6d99f022a1a2cb441b80aa3c2ab865a0c7e9d4752e5
MD5 8d0725da6362618596b3fbb8ca565fb5
BLAKE2b-256 ac62fdb1bb1f699d3da2d83fbfe590fea69b4f34f8145ad73655c38d1cadb7f6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for nell_scb_lib-1.0.3-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 1f4ed59d82a04344197aa3407a6d2d915d3a14ef1b5d54e9492e1ef155b648ff
MD5 75c0f345a63cf04d918107a3313c6d22
BLAKE2b-256 b80ae5eb63ea3f082ffd9668aea0e1e097ca1f8904e63e1a4ead8e8a0da90337

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for nell_scb_lib-1.0.3-cp312-cp312-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 1327b13f77832d682f528a5888bb342b406f41dc62b767c893777585ee587e5a
MD5 21b29250ed9326aa8416927fbea1373e
BLAKE2b-256 9f153fdf1c3c5ce9f39f8d5900620728f2c3fd655dd9c32f15b73864f9c2bcc0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for nell_scb_lib-1.0.3-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 7a17a3edc84c828e2becf52fff0af771c71262f6da7f4ae5a22cbacb79295cd4
MD5 c839397d9ee905a63ce776e5aa28d92e
BLAKE2b-256 866bafffb5e30b7be2470755522b9e289001ea64ca8c34fc6dba34d7d79333b0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for nell_scb_lib-1.0.3-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 585466e9bbb3c38692dd67e988011b91b3a4a355752b9ed96b059ec9e347c3b8
MD5 636dd5493bf553875685f27ae8fab063
BLAKE2b-256 6ad58d52db78672d83a6af43c274cc944ddab92141402fef1292948e0fa579eb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for nell_scb_lib-1.0.3-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 5be09b23fd110175e6b3f874cafcb5c1d3da346c53c9d90b578404404cefa993
MD5 a2940329f274a608290f312c02f614ad
BLAKE2b-256 94e4cb22fadd18ecdca509cb764eb3877e7ba34af372393e0f59a4f9848eec35

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for nell_scb_lib-1.0.3-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 111e0661e08a176cee97113f675b53afd2d3146ca89bb6019bcdf5e6e701cee2
MD5 db19410d3ec540badf68d76fc284c2fe
BLAKE2b-256 05026fba5220c389a31fba20bad0d2b74d052cd6a9cf8f1ac01ff44cabcb73ec

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