Skip to main content

Python SDK for PeyemAPI - Haitian payment gateway

Project description

PeyemAPI Python SDK

A modern, typed Python SDK for integrating PeyemAPI payments into any Python project — works with Django, Flask, FastAPI, or plain scripts.

Installation

pip install peyemapi-sdk

Requirements: Python ≥ 3.9

Quick Start

from peyemapi import PeyemClient

# Credentials are loaded automatically from environment variables
client = PeyemClient()

# Or pass them directly
client = PeyemClient(secret_key="sk_user_...")

Usage

Create a Payment

response = client.create_payment(
    amount=500,                          # HTG
    reference_id="ORDER-123",
    return_url="https://example.com/return",
    description="Optional description",
)

if "payment_url" in response:
    # Redirect your user to MonCash
    redirect_url = response["payment_url"]

Check Payment Status

status = client.check_status("ORDER-123")
print(status["status"])  # "completed", "pending", etc.

Get Account Balance

balance = client.get_balance()
print(f"{balance['balance']} {balance['currency']}")  # "12500 HTG"

Webhook Verification

import os
from peyemapi import PeyemClient

# Example using Flask
from flask import Flask, request, abort

app = Flask(__name__)

@app.post("/webhook")
def webhook():
    payload = request.get_data()
    signature = request.headers.get("X-Webhook-Signature", "")

    if not PeyemClient.verify_webhook(payload, signature, os.getenv("PEYEM_WEBHOOK_SECRET")):
        abort(401)

    data = request.get_json()
    print("Valid webhook received:", data)
    return "", 200

Environment Variables

Variable Description
PEYEM_API_KEY Your secret API key
PEYEM_API_URL Override the API base URL (optional)
PEYEM_WEBHOOK_SECRET Your webhook signing secret

Copy .env.example.env and fill in your credentials.

Error Handling

from peyemapi import PeyemClient, PeyemException

try:
    result = client.create_payment(amount=500, reference_id="REF", return_url="")
except PeyemException as e:
    print(f"API Error [{e.status_code}]: {e}")

Running Tests

pip install -e ".[dev]"
pytest

License

MIT

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

peyemapi_sdk-1.0.0.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

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

peyemapi_sdk-1.0.0-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for peyemapi_sdk-1.0.0.tar.gz
Algorithm Hash digest
SHA256 b98706ae7e880c7b786f934da19a07f773b9b113602a4821dbe400a5acd12467
MD5 5280342f2e75de6a96d049feac3813aa
BLAKE2b-256 7ae761a215358b8aeb978ebf590bae544103f330dfeedc2547dfeb09a0e6f532

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for peyemapi_sdk-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 781ec53356fb6fb41867d96063a35bde411942112a3c9f9607e269c9783cc3b3
MD5 ae45b11dbfaa3409df03051851dbd9dc
BLAKE2b-256 02bfbc414302a62044a323276041c75686cf577bafc10433fbbf8e2e987ed130

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