moncashconnect
Official Python SDK for MonCashConnect — the easiest way to integrate MonCash payments in your Python application.
Zero dependencies — uses only the Python standard library.
Note: MonCashConnect is not affiliated with Digicel or the official MonCash service.
Requirements
- Python 3.9+
Installation
pip install moncashconnect
Quick Start
import os
from moncashconnect import MonCashClient
client = MonCashClient(os.environ["MCC_SECRET_KEY"])
payment = client.create_payment(
1500,
"order-001",
return_url="https://yoursite.com/payment/success",
customer_name="Jean Dupont",
)
# Redirect the customer
print(payment["paymentUrl"])
Your secret key starts with sk_proj_ — get it from Developer → Projects in your dashboard.
Check Payment Status
tx = client.get_payment_status("order-001")
print(tx["status"]) # "pending" | "completed" | "failed"
print(tx["netAmount"]) # Amount after commission deduction
Get Account Balance
balance = client.get_balance()
print(balance["balanceHtg"]) # Total available
print(balance["withdrawableHtg"]) # Can withdraw now
Webhooks
Configure a webhook URL in your project. MonCashConnect sends a signed POST when a payment is finalized.
Always read the raw body before any json.loads().
from moncashconnect import construct_event, MonCashError
# Django
def webhook(request):
raw_body = request.body # bytes — read before any parsing
signature = request.META.get("HTTP_X_MCC_SIGNATURE", "")
timestamp = request.META.get("HTTP_X_MCC_TIMESTAMP", "")
try:
event = construct_event(
raw_body, signature, timestamp,
os.environ["MCC_WEBHOOK_SECRET"],
)
except MonCashError as exc:
return HttpResponse(str(exc), status=exc.status_code)
if event["event"] == "payment.completed":
Order.objects.filter(reference=event["reference"]).update(status="paid")
elif event["event"] == "payment.failed":
Order.objects.filter(reference=event["reference"]).update(status="failed")
return HttpResponse("OK")
Flask
from flask import Flask, request, abort
from moncashconnect import construct_event, MonCashError
app = Flask(__name__)
@app.route("/webhooks/moncash", methods=["POST"])
def moncash_webhook():
raw_body = request.get_data() # bytes
signature = request.headers.get("X-MCC-Signature", "")
timestamp = request.headers.get("X-MCC-Timestamp", "")
try:
event = construct_event(
raw_body, signature, timestamp,
os.environ["MCC_WEBHOOK_SECRET"],
)
except MonCashError as exc:
abort(exc.status_code, description=str(exc))
if event["event"] == "payment.completed":
mark_order_paid(event["reference"])
return "OK", 200
FastAPI
from fastapi import FastAPI, Header, HTTPException, Request
from moncashconnect import construct_event, MonCashError
app = FastAPI()
@app.post("/webhooks/moncash")
async def moncash_webhook(
request: Request,
x_mcc_signature: str = Header(...),
x_mcc_timestamp: str = Header(...),
):
raw_body = await request.body()
try:
event = construct_event(
raw_body, x_mcc_signature, x_mcc_timestamp,
os.environ["MCC_WEBHOOK_SECRET"],
)
except MonCashError as exc:
raise HTTPException(status_code=exc.status_code, detail=str(exc))
if event["event"] == "payment.completed":
await mark_order_paid(event["reference"])
return {"ok": True}
Error Handling
from moncashconnect import MonCashClient, MonCashError
try:
payment = client.create_payment(500, "order-42")
except MonCashError as exc:
print(exc) # "referenceId already exists for this project"
print(exc.status_code) # 409
print(exc.context) # Full API response dict, or None
License
MIT
Metadata
Release files for moncashconnect 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| moncashconnect-1.0.0.tar.gz | 5.3 kB | Without provenance | Details for moncashconnect-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| moncashconnect-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for moncashconnect-1.0.0-py3-none-any.whl |
Total release size: 11.5 kB
Release files / moncashconnect-1.0.0.tar.gz
| Download URL | moncashconnect-1.0.0.tar.gz |
|---|---|
| Size | 5.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d63dd5da0ab9234c20f506b546d1b5bb3320a04c6447761898009c4f87f8c5a8
|
|
BLAKE2b-256 checksum How to use checksums |
0b21e728698d911418ca5c7f04bc36906629e08ccf00d3351c3855d822e26c21
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|
Release files / moncashconnect-1.0.0-py3-none-any.whl
| Download URL | moncashconnect-1.0.0-py3-none-any.whl |
|---|---|
| Size | 6.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e49b811edfe450a4e0b5149dcb9d8bfaffa04df29cf190ffbb8a97dfe0196719
|
|
BLAKE2b-256 checksum How to use checksums |
bbcfa71af9a37f45e546dafdf801509c314d492dba55e50dccbf61ec7205034d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|
Security for moncashconnect 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.