Official Sunbay Nexus Python SDK
Project description
Sunbay Nexus Python SDK
Official Python SDK for the Sunbay Nexus payment platform.
This SDK provides a simple and professional way to integrate with Sunbay Nexus from Python applications, following the same semantics as the official Java SDK.
Features
- Simple and intuitive API
- Thread-safe client with connection pooling
- Clear separation between network errors and business errors
- Automatic authentication via API key
- Configurable timeouts and retries for GET requests
- Python 3.7+ support
Installation
Once published to PyPI:
pip install sunbay-nexus-sdk
Supported Python versions
- Officially supported: Python 3.7 and above
- Python 2 is not supported.
Quick Start
1. Initialize client
from sunbay_nexus_sdk import NexusClient
# Option 1: pass api_key explicitly
client = NexusClient(api_key="sk_test_xxx")
# Option 2: read api_key from environment variable SUNBAY_API_KEY
# client = NexusClient()
The NexusClient is thread-safe and can be reused across multiple threads.
Create it once and reuse it in your application.
2. Sale transaction
from sunbay_nexus_sdk import NexusClient, SunbayBusinessError, SunbayNetworkError
from sunbay_nexus_sdk.model.common import SaleAmount
from sunbay_nexus_sdk.model.request import SaleRequest
client = NexusClient(api_key="sk_test_xxx")
amount = SaleAmount(order_amount=100.0, pricing_currency="USD")
request = SaleRequest(
app_id="app_123456",
merchant_id="mch_789012",
reference_order_id="ORDER20231119001",
transaction_request_id="PAY_REQ_1234567890",
amount=amount,
description="Product purchase",
terminal_sn="T1234567890",
)
try:
response = client.sale(request)
if response.is_success():
print("Transaction ID:", response.transaction_id)
else:
print("Error:", response.code, response.msg)
except SunbayNetworkError as e:
print("Network Error:", e)
except SunbayBusinessError as e:
print("API Error:", e.code, "-", e)
3. Query transaction
from sunbay_nexus_sdk import NexusClient
from sunbay_nexus_sdk.model.request import QueryRequest
client = NexusClient(api_key="sk_test_xxx")
request = QueryRequest(
app_id="app_123456",
merchant_id="mch_789012",
transaction_id="TXN20231119001",
)
response = client.query(request)
if response.is_success():
print("Status:", response.transaction_status)
else:
print("Error:", response.code, response.msg)
API Overview
The Python SDK exposes a NexusClient with methods that correspond to the Java SDK:
- Transaction APIs:
sale(request: SaleRequest) -> SaleResponseauth(request: AuthRequest) -> AuthResponseforced_auth(request: ForcedAuthRequest) -> ForcedAuthResponseincremental_auth(request: IncrementalAuthRequest) -> IncrementalAuthResponsepost_auth(request: PostAuthRequest) -> PostAuthResponserefund(request: RefundRequest) -> RefundResponsevoid_transaction(request: VoidRequest) -> VoidResponseabort(request: AbortRequest) -> AbortResponsetip_adjust(request: TipAdjustRequest) -> TipAdjustResponse
- Query APIs:
query(request: QueryRequest) -> QueryResponse
- Settlement APIs:
batch_close(request: BatchCloseRequest) -> BatchCloseResponse
Exceptions
The SDK differentiates between network-level and business-level errors:
SunbayNetworkError- Thrown for network errors, timeouts, or HTTP non-2xx responses.
- Has a
retryableflag to indicate whether the request may be retried safely.
SunbayBusinessError- Thrown for API business errors (e.g.
code != "0") and local parameter validation failures. - Contains
codeandtrace_idfields when available.
- Thrown for API business errors (e.g.
Always catch SunbayNetworkError before SunbayBusinessError if you need to
distinguish between them.
Configuration
You can configure the client using constructor arguments:
from sunbay_nexus_sdk import NexusClient
client = NexusClient(
api_key="sk_test_xxx",
base_url="https://open.sunbay.us", # default
connect_timeout=30.0, # seconds, default 30.0
read_timeout=60.0, # seconds, default 60.0
max_retries=3, # default 3 for GET requests
max_connections=200, # default 200
)
Using enums
For some fields (such as transaction status and card network type), the SDK provides enums to make the code more self-documenting:
from sunbay_nexus_sdk import TransactionStatus
if response.is_success() and response.transaction_status == TransactionStatus.SUCCESS:
print("Transaction succeeded")
Integration in web frameworks
In web frameworks (such as FastAPI or Django), it is recommended to create a
single NexusClient instance at startup and reuse it:
from sunbay_nexus_sdk import NexusClient
client = NexusClient(api_key="sk_live_xxx")
def process_payment(request_data):
# build SaleRequest here...
response = client.sale(request_data)
...
License
MIT License
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 Distribution
Built Distribution
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 sunbay_nexus_sdk-1.0.0.tar.gz.
File metadata
- Download URL: sunbay_nexus_sdk-1.0.0.tar.gz
- Upload date:
- Size: 15.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3e0ec582476bcc601c3971fdb7abf6a0dc67108e78d77699eddc8e8cff4ce1d7
|
|
| MD5 |
4eb72a84873f13b9d524101ae8b2f803
|
|
| BLAKE2b-256 |
fc8d40695ab9ee7dd1e07162cb4cef3bcd09a2e71ff4989378e5483be4010868
|
File details
Details for the file sunbay_nexus_sdk-1.0.0-py3-none-any.whl.
File metadata
- Download URL: sunbay_nexus_sdk-1.0.0-py3-none-any.whl
- Upload date:
- Size: 15.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f8e55e44b39258704e38f8e6aabe2dba0a33542774b0add6b7091d6382f98e6b
|
|
| MD5 |
c40b32215bcd4d501d9f22993f240ddb
|
|
| BLAKE2b-256 |
0624c671851c4569829baffdd5f1b839fdd85e9c899765ec1e2f93b01df892e8
|