Metadata-Version: 2.5
Name: instantpay-sa
Version: 0.1.0
Summary: Official Python library for the InstantPay API (Saudi merchant payments).
License: MIT
License-File: LICENSE
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Requires-Python: >=3.9
Description-Content-Type: text/markdown

# instantpay (Python)

Official Python library for the [InstantPay](https://developers.instantpay.sa) API. Python 3.9+,
standard library only.

```bash
pip install instantpay-sa   # the package is instantpay-sa; you import instantpay
```

```python
import instantpay

ip = instantpay.InstantPay(os.environ["INSTANTPAY_API_KEY"],
                           base_url="https://instantpay-api.onrender.com")  # demo sandbox

checkout = ip.payment_intents.create(amount="250.00", description="Order 1001",
                                     reference="1001", return_url="https://shop.example.sa/orders/1001")
# redirect the customer to checkout["checkout_url"]

for payment in ip.payments.all(state="settled"):   # every page
    print(payment["id"], payment["amount"]["amount"])

ip.refunds.create(payment_id="pay_…", amount="20.00", reason="One item returned")

# Webhooks (Flask): the raw body, then the event
event = instantpay.webhooks.construct_event(request.get_data(),
                                            request.headers.get("InstantPay-Signature"),
                                            os.environ["INSTANTPAY_WEBHOOK_SECRET"])
```

Errors are `instantpay.InstantPayError` with `status`, `code`, `param` and `request_id`.
Options: `base_url`, `timeout` (30), `max_retries` (2), `transport`. Tests:
`python3 -m unittest discover -s tests`.
