Metadata-Version: 2.4
Name: lunipay
Version: 0.1.1
Summary: The official LuniPay Python SDK.
Project-URL: Homepage, https://lunipay.io/docs/sdks/python
Project-URL: Documentation, https://lunipay.io/docs/sdks/python
Project-URL: Repository, https://github.com/SammarieoBrown/lunipay-sdk
Project-URL: Issues, https://github.com/SammarieoBrown/lunipay-sdk/issues
Author: LuniPay
License: MIT
Keywords: api,caribbean,checkout,lunipay,payments,sdk,stripe-alternative
Classifier: Development Status :: 4 - Beta
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
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.8
Requires-Dist: requests>=2.20
Requires-Dist: typing-extensions>=4.0; python_version < '3.11'
Description-Content-Type: text/markdown

# lunipay

The official LuniPay Python SDK.

```bash
pip install lunipay
```

## Quick start

```python
import lunipay

lunipay.api_key = "sk_test_YOUR_KEY"

session = lunipay.CheckoutSession.create(
    amount=5000,
    currency="usd",
    success_url="https://example.com/thanks?session_id={CHECKOUT_SESSION_ID}",
)

print(session["url"])
```

## Resources

Every LuniPay resource is a top-level class on the module:

```python
lunipay.Customer.create(email="ada@example.com", first_name="Ada", last_name="Lovelace")
lunipay.Customer.retrieve("cus_01JRZK...")
lunipay.Customer.modify("cus_01JRZK...", phone="+18765559999")
lunipay.Customer.delete("cus_01JRZK...")

for customer in lunipay.Customer.list().auto_paging_iter():
    print(customer["email"])
```

Supported resources: `CheckoutSession`, `Customer`, `Invoice`, `Payment`, `PaymentLink`, `WebhookEndpoint`, `Event`.

## Webhooks

```python
import lunipay

@app.post("/webhook")
def webhook():
    payload = request.get_data()
    sig = request.headers.get("LuniPay-Signature")
    try:
        event = lunipay.Webhook.construct_event(
            payload=payload,
            sig_header=sig,
            secret="whsec_your_secret",
        )
    except lunipay.error.SignatureVerificationError:
        return "bad signature", 400

    if event["type"] == "checkout.session.completed":
        # fulfill the order
        pass

    return "", 200
```

## Errors

All LuniPay API errors raise subclasses of `lunipay.error.LuniPayError`:

```python
try:
    lunipay.Customer.create(email="bad", first_name="x", last_name="y")
except lunipay.error.InvalidRequestError as e:
    print(e.code, e.param, str(e))
```

Subclasses: `AuthenticationError`, `PermissionError`, `InvalidRequestError`, `IdempotencyError`, `RateLimitError`, `APIError`, `APIConnectionError`.

## Idempotency

Pass `idempotency_key` to any mutating request:

```python
import uuid

key = str(uuid.uuid4())
session = lunipay.CheckoutSession.create(
    amount=5000,
    currency="usd",
    success_url="https://example.com/thanks",
    idempotency_key=key,
)
```

## Full documentation

See [lunipay.io/docs/sdks/python](https://lunipay.io/docs/sdks/python).

## License

MIT
