Metadata-Version: 2.4
Name: makepay
Version: 0.1.0
Summary: Official MakePay Python SDK for payment links, settings, and webhook verification.
Project-URL: Homepage, https://www.makepay.io
Project-URL: Documentation, https://www.makecrypto.io/documentation/sdk/python
Project-URL: Repository, https://github.com/makecryptoio/makeswap/tree/main/apps/plugins/python-sdk
Project-URL: Issues, https://github.com/makecryptoio/makeswap/issues
Author-email: MakePay <support@makepay.io>
License-Expression: MIT
License-File: LICENSE
Keywords: crypto-payments,makecrypto,makepay,payment-links,webhooks
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Office/Business :: Financial
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Typing :: Typed
Requires-Python: >=3.9
Description-Content-Type: text/markdown

# MakePay Python SDK

Official Python SDK for MakePay server-side integrations. Use it to create
hosted payment links, read and update links, manage MakePay settings, and
verify signed webhooks.

## Install

```bash
pip install makepay
```

```bash
uv add makepay
```

## Configure

Create a MakePay API key in MakeCrypto and keep the secret on your server only.

```python
import os

from makepay import MakePayClient

makepay = MakePayClient(
    key_id=os.environ["MAKEPAY_KEY_ID"],
    key_secret=os.environ["MAKEPAY_KEY_SECRET"],
    # Optional: override only when MakePay gives you a custom checkout origin.
    checkout_base_url="https://makepay.io",
)
```

## Create A Hosted Checkout Link

```python
response = makepay.create_payment_link(
    {
        "title": "Order #1042",
        "description": "Checkout for order #1042",
        "amount": "129.99",
        "currency": "USDT",
        "orderId": "order_1042",
        "customerEmail": "buyer@example.com",
        "returnUrl": "https://merchant.example/orders/1042",
        "successUrl": "https://merchant.example/orders/1042/success",
        "failureUrl": "https://merchant.example/orders/1042/pay",
        "expirationTime": "12h",
    }
)

print(response["paymentLink"])
```

## Hosted And Embedded Checkout

Use the hosted URL for a full-page redirect, or the embedded URL and HTML
helpers when your frontend keeps the shopper on the merchant site.

```python
from makepay import (
    build_makepay_embed_button_html,
    build_makepay_embedded_checkout_url,
    build_makepay_hosted_checkout_url,
    build_makepay_iframe_html,
)

payment_uid = response["paymentLink"]["uid"]

hosted_url = build_makepay_hosted_checkout_url(payment_uid)
embed_url = build_makepay_embedded_checkout_url(
    payment_uid,
    parent_origin="https://merchant.example",
)

button_html = build_makepay_embed_button_html(payment_uid)
iframe_html = build_makepay_iframe_html(
    payment_uid,
    iframe_title="Secure MakePay checkout",
)
```

## Read And Update Links

```python
makepay.list_payment_links()
makepay.get_payment_link("PAYMENT_LINK_UID")
makepay.update_payment_link("PAYMENT_LINK_UID", {"status": "paused"})
makepay.send_payment_request_email("PAYMENT_LINK_UID", "buyer@example.com")
```

## Settings

```python
makepay.get_settings()

makepay.update_settings(
    {
        "callbackUrl": "https://merchant.example/webhooks/makepay",
    }
)
```

## Verify Webhooks

Read the raw body before parsing JSON.

```python
from makepay import parse_makepay_webhook


def handle_makepay_webhook(raw_body: bytes, headers: dict[str, str]) -> tuple[str, int]:
    event = parse_makepay_webhook(
        raw_body,
        headers.get("x-makepay-signature"),
        os.environ["MAKEPAY_WEBHOOK_SECRET"],
    )

    if event.get("event", {}).get("type") == "status_changed":
        # Update your local order status.
        pass

    return "ok", 200
```

## Errors

API calls raise `MakePayError` with `status` and `response_body` fields.

```python
from makepay import MakePayError

try:
    makepay.get_payment_link("PAYMENT_LINK_UID")
except MakePayError as error:
    print(error.status, error.response_body)
```
