Skip to main content

Official Money-Pulse Python SDK — Accept payments and process payouts across Africa.

Project description

moneypulse

Official Python SDK for Money-Pulse.

Installation

pip install moneypulse

Quick start

import moneypulse
client = moneypulse.Client("mp_live_xxx")

payment = client.payments.create(
    amount=10000, currency="XOF", country="CI",
    customer={"email": "client@email.com", "phone": "+22507000000"},
    callback_url="https://your-site.com/webhook",
)
print(payment["checkout_url"])

Payouts

payout = client.payouts.create(
    amount=50000, currency="XOF", country="CI",
    recipient={"type": "mobile_money", "phone": "+22507000000", "name": "Jean Kouassi"},
)

Webhook verification (HMAC SHA-256)

Django

import hmac, hashlib, json
from django.http import HttpResponse
from django.views.decorators.csrf import csrf_exempt

@csrf_exempt
def mp_webhook(request):
    signature = request.headers.get("X-MoneyPulse-Signature", "")
    expected = hmac.new(
        settings.MP_WEBHOOK_SECRET.encode(),
        request.body, hashlib.sha256
    ).hexdigest()
    if not hmac.compare_digest(signature, expected):
        return HttpResponse(status=401)

    event = json.loads(request.body)
    if event["type"] == "payment.success":
        # fulfill order
        pass
    return HttpResponse(status=200)

FastAPI

from fastapi import FastAPI, Request, HTTPException
import hmac, hashlib

app = FastAPI()

@app.post("/webhook")
async def webhook(req: Request):
    body = await req.body()
    signature = req.headers.get("x-moneypulse-signature", "")
    expected = hmac.new(SECRET.encode(), body, hashlib.sha256).hexdigest()
    if not hmac.compare_digest(signature, expected):
        raise HTTPException(401)
    return {"received": True}

Simulation mode

result = client.payments.create(
    amount=1000, currency="XOF", country="CI",
    customer={"email": "t@t.com"},
    simulate=True,  # no funds, no webhook, no billing
)

Error handling

from moneypulse.client import MoneyPulseError

try:
    client.payments.create(...)
except MoneyPulseError as e:
    print(e.code, e.status_code, e)

License

MIT © NOCYL-PULSE

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

moneypulse-1.0.0.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

moneypulse-1.0.0-py3-none-any.whl (3.7 kB view details)

Uploaded Python 3

File details

Details for the file moneypulse-1.0.0.tar.gz.

File metadata

  • Download URL: moneypulse-1.0.0.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.1

File hashes

Hashes for moneypulse-1.0.0.tar.gz
Algorithm Hash digest
SHA256 28b27effefa2d15d96a5b6dcd3ac1d64ae543dc89d96fd984d5534894e1de6e9
MD5 2d9c319821210036fedb1ae2a37e9937
BLAKE2b-256 ee9089277ee1679925cef929760018bb2a425f2622a33f0a1a4c1ac9e7e4e424

See more details on using hashes here.

File details

Details for the file moneypulse-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: moneypulse-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 3.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.1

File hashes

Hashes for moneypulse-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b3dbf13f6ec1a7963cc6a01b56737f96e5141ed4c67159d97672efc5aae9c034
MD5 36f373d791aa6197ceda96a25b4f272b
BLAKE2b-256 2f0ff2edecdf8b649cff9aff29be6afed3e9ddcc10189bb2326695cff98d3c11

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