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-2.0.0.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

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

moneypulse-2.0.0-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for moneypulse-2.0.0.tar.gz
Algorithm Hash digest
SHA256 6bf13b9619dbdd2d5e6888c150ae7e44b29b43e03d44bc456c8b2b81663e6c28
MD5 4970206b7c0cea2aa01f6987a8b8bf2a
BLAKE2b-256 bc7ab311adf6a27ce187b4563efc7673be832c6810d2bc48238c40baea3cf3e4

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for moneypulse-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 34d4f174542a02d47c8a643f220cce62bfcab3348a407850eddd9ddd4c59a338
MD5 9b9314811a6fe789c7820a5282e68b88
BLAKE2b-256 1fb3221708f9962533a8872c6ec99f97eec5749f2089ed0af67adc89542571fe

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