Skip to main content

MagicPay Python SDK

Zero-dependency Python (3.8+) client for the MagicPay API.

pip install magicpay        # or: pip install ./python

Quick start

from magicpay import PRODUCTION_URL, MagicPay, MagicPayAPIError

mp = MagicPay(api_key="YOUR_API_KEY", secret_key="YOUR_SECRET_KEY")  # trdev, auth V2
# production: MagicPay(..., base_url=PRODUCTION_URL)

# 1) Initialize a 3D Secure payment
init = mp.payments.init_3ds_payment({
    "price": 100.0,
    "paidPrice": 100.0,
    "installment": 1,
    "currency": "TRY",
    "paymentGroup": "PRODUCT",
    "paymentChannel": "Online",
    "clientIp": "192.168.1.1",
    "redirectUrl": "https://shop.example.com/magicpay/return",
    "callbackUrl": "https://shop.example.com/magicpay/callback",
    "bankOrderId": "ORDER-1001",
    "card": {
        "cardHolderName": "Jane Doe",
        "cardNumber": "5406675406675403",
        "expireMonth": "12",
        "expireYear": "2030",
        "cvc": "000",
    },
    "items": [{"name": "Item1", "price": 100.0}],
})

# 2) After the bank redirects back, complete it
done = mp.payments.complete_3ds_payment({"paymentId": 123})

# Query / refund
payment = mp.payments.retrieve_payment(123)
mp.payments.refund_payment({"paymentId": 123, "conversationId": "r-1", "refundDestinationType": "PROVIDER"})

# Installments
mp.installments.list_checkout_installments(query={"amount": 1250.5, "currency": "TRY"})
mp.installments.retrieve_bin(query={"binNumber": "540667"})

# Bearer (merchant-panel) endpoints: log in once, the token is kept on the client
mp.login("panel-user@example.com", "secret-word")
mp.pos.list_pos(query={"isActivePos": "ACTIVE"})
mp.members.search_members(query={"isBuyer": True, "page": 0, "size": 20})  # None skipped, lists repeated

# Plugin POS management (V2 only)
mp.plugin.list_banks()

Errors

try:
    mp.login("panel-user@example.com", "wrong")
except MagicPayAPIError as e:
    print(e.status, e.error_code, e.body)   # 200 7005 {...}: errors body on HTTP 200

MagicPayAPIError is raised for HTTP ≥ 300 (redirects are never followed, so the signed headers cannot be forwarded) and for a 2xx body with an errors object. A login access token is masked (***) in error bodies and messages. Path parameters "", . and .. raise ValueError. MagicPayConnectionError is raised for network problems; both inherit from MagicPayError.

Options

Argument Default
base_url SANDBOX_URL = https://trdev.magicpay.ai (test) PRODUCTION_URL = https://tr.magicpay.ai with live keys; must be https
allow_insecure False allow an http:// base URL for non-loopback hosts (tests/proxies only; loopback is always allowed)
auth_version "V2" or "V1" (rejected by plugin.*)
access_token None set by login(); can be set/cleared directly. Shared by every request on this client: login() switches concurrent requests to the new token, so use one client per panel user
timeout 30 seconds
signature_encoding "hex" "base64" only with V1
transport urllib, redirects not followed callable (method, url, headers, body, timeout) -> (status, text) — plug in requests/httpx or a test double; send body unchanged and do not follow redirects

Undocumented endpoint? mp.request("GET", "/some/path", body=None, query={...}) is signed the same way. Signing helpers: compute_signature_v2(...), compute_signature(...) (V1).

All methods: ../ENDPOINTS.md. Tests: python3 -m unittest discover -s tests.

Metadata

Release files for magicpay 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for magicpay 0.1.0
File Size Uploaded Provenance Actions
magicpay-0.1.0.tar.gz 17.8 kB Without provenance Details for magicpay-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for magicpay 0.1.0
File Interpreter ABI Platform Actions
magicpay-0.1.0-py3-none-any.whl Python 3 none any Details for magicpay-0.1.0-py3-none-any.whl

Total release size: 32.0 kB

Release files / magicpay-0.1.0.tar.gz

Download URL magicpay-0.1.0.tar.gz
Size 17.8 kB
Tags Source
SHA-256 checksum
How to use checksums
d1f5cf726863139b65c74768e6ee8b78691808c0db69618ce5275b3c88f5f538
BLAKE2b-256 checksum
How to use checksums
181dc1deff1d9002dd9a514271d4da0336616de4cf19eca52a62943abbd9fffb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.2

Release files / magicpay-0.1.0-py3-none-any.whl

Download URL magicpay-0.1.0-py3-none-any.whl
Size 14.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a85a888e6e734bb1a1fec08003d778bf0a2af4590d9100a1ff9e0684081aaa6b
BLAKE2b-256 checksum
How to use checksums
c4d4423571849d9070ccca01d1b9b3cda331334c28a089514746d91e2bea6473
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.2

Security for magicpay 0.1.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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page