Skip to content

Repository files navigation

SerikaPay Python library

CI

The official SerikaPay library for Python 3.9+. Standard library only — no dependencies.

Install

pip install serikapay

Usage

Create a key under Developers → API keys in your wallet. Keep it on the server.

import os
import serikapay

serika = serikapay.SerikaPay(os.environ["SERIKA_SECRET_KEY"])

payment = serika.payments.create(
    amount=4.99,
    description="Sticker pack",
    customer_email="fan@example.com",
    metadata={"orderId": "1042"},
    idempotency_key="order_1042",  # optional — generated if omitted
)
print(payment.status)  # "completed"

Responses are SerikaObjects: dicts that also allow attribute access (payment.id, payment["id"]). Field names match the API, so they're camelCase (payment.customerEmail).

Payments

serika.payments.retrieve("pay_m1x2y3")
page = serika.payments.list(limit=10)       # page.data, page.hasMore
serika.payments.refund("pay_m1x2y3")        # full refund
serika.payments.refund("pay_m1x2y3", amount=2.00)

Balance and transactions

balance = serika.balance.retrieve()         # EUR by default
page = serika.transactions.list(limit=20, type="spend")

Webhooks

from serikapay import Webhook, SignatureVerificationError

@app.post("/webhooks/serika")
def serika_webhook():
    try:
        event = Webhook.construct_event(
            request.get_data(),                       # raw bytes, not request.json
            request.headers.get("Serika-Signature"),
            os.environ["SERIKA_WEBHOOK_SECRET"],
        )
    except SignatureVerificationError:
        return "Invalid signature", 400

    if event.type == "payment.completed":
        fulfil(event.data)
    return "ok"

Errors

from serikapay import SerikaPayError

try:
    serika.payments.create(amount=4.99)
except SerikaPayError as e:
    print(e.type, e.status_code, e.message, e.raw)

Network failures raise SerikaPayError with type == "connection_error" and status_code is None.

Configuration

serika = serikapay.SerikaPay(
    "sk_test_...",
    base_url="https://wallet-api.serika.dev",  # default
    timeout=30.0,     # seconds per attempt
    max_retries=2,    # network errors, 429 and 5xx
)

GET requests and payment creation (which always carries an idempotency key) are retried with exponential backoff; refunds are not.

Development

PYTHONPATH=src python -m unittest discover -s tests

License

MIT

About

Official SerikaPay library for Python

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages