mpac-pgw Python SDK
Python client library for the MPAC Payment Gateway. Provides HMAC-SHA256 authenticated access to all PGW API endpoints for server-to-server integration.
Installation
The SDK is distributed via GitHub Packages (private, org-scoped). Install directly from the GitHub repository.
Option A: Install from git tag (recommended)
bash
# Using uv (preferred)
uv pip install "mpac-pgw-sdk @ git+https://github.com/mp-solution-inc/mpac-pgw.git@sdks/sdk-python/v1.0.0#subdirectory=sdks/sdk-python"
# Using pip
pip install "mpac-pgw-sdk @ git+https://github.com/mp-solution-inc/mpac-pgw.git@sdks/sdk-python/v1.0.0#subdirectory=sdks/sdk-python"Option B: Add to pyproject.toml
toml
[project]
dependencies = [
"mpac-pgw-sdk @ git+https://github.com/mp-solution-inc/mpac-pgw.git@sdks/sdk-python/v1.0.0#subdirectory=sdks/sdk-python",
]Option C: Install from GitHub Releases wheel
bash
uv pip install https://github.com/mp-solution-inc/mpac-pgw/releases/download/sdks-sdk-python-v1.0.0/mpac_pgw_sdk-1.0.0-py3-none-any.whlAuthentication: GitHub access requires a PAT with read:packages scope configured:
bash
git config --global url."https://ghp_YOUR_TOKEN@github.com/".insteadOf "https://github.com/"See the developer onboarding guide for full setup instructions.
Quick Start
python
from mpac_pgw import Client, ClientConfig, CreatePaymentIntentRequest
client = Client(ClientConfig(
base_url="https://pgw.example.com",
api_key="ak_01JXXXXXXXXXXXXXXXXXXXXXX",
secret_key="sk_live_xxxxxxxxxxxxxxxxxxxxxxxx",
))
# Create a PaymentIntent
intent = client.create_payment_intent(CreatePaymentIntentRequest(
amount=1000,
currency="JPY",
payment_method_types=["qr_mpm"],
merchant_ref_id="order_12345",
merchant_store_id="store_001",
))
print(f"PaymentIntent created: {intent.id}")
print(f"Payment token: {intent.payment_token}")
# Pass intent.payment_token to the frontend SDK for payment confirmationAuthentication
All requests are authenticated using HMAC-SHA256. The SDK handles signature generation automatically.
Signature scheme:
Message = METHOD + "\n" + PATH + "\n" + TIMESTAMP + "\n" + HEX(SHA256(BODY))
Key = bytes(HEX(SHA256(secret_key)))
Signature = HEX(HMAC-SHA256(Key, Message))
Header = "HMAC-SHA256 <api_key>:<timestamp>:<signature>"Context Manager
The client supports the context manager protocol for automatic cleanup:
python
with Client(config) as client:
intent = client.create_payment_intent(request)API Reference
| Method | Description |
|---|---|
create_payment_intent | Create a new PaymentIntent |
get_payment_intent | Retrieve a PaymentIntent by ID |
list_payment_intents | List PaymentIntents with optional filters |
capture_payment_intent | Capture a PaymentIntent (manual mode) |
sync_merchants | Sync merchant/store data from upstream |
Testing
bash
uv run pytest tests/ -vRequirements
- Python 3.11+
- httpx (for HTTP transport)
License
MIT