Metadata-Version: 2.4
Name: alatpay-sdk
Version: 0.0.1
Summary: A Python client SDK for integrating with the ALATPay API.
Keywords: ALATPay,wema
Author: Gbenga Adeyi
Author-email: Gbenga Adeyi <adeyigbenga005@gmail.com>
License-Expression: MIT
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Requires-Dist: pydantic>=2.13.4
Requires-Dist: pyreqwest>=0.12.0
Requires-Python: >=3.11
Description-Content-Type: text/markdown

# ALATPay SDK (Python)

[![Downloads](https://static.pepy.tech/badge/alatpay-sdk)](https://pepy.tech/project/alatpay-sdk)
[![Downloads](https://static.pepy.tech/badge/alatpay-sdk/month)](https://pepy.tech/project/alatpay-sdk)
[![Downloads](https://static.pepy.tech/badge/alatpay-sdk/week)](https://pepy.tech/project/alatpay-sdk)

A Python client SDK for integrating with the ALATPay API.

## Features

- Fully Typed.
- Automatic payload, queries and response data case transformation.
- [Pydantic](https://pydantic.dev/docs/validation/latest/get-started/) for payload and response data modeling.
- Custom response data model injection.
- Synchronous and Asynchronous clients


## Installation

Requires Python version `>=3.11`

### With [uv](docs.astral.sh/uv/)

```bash
uv add alatpay-sdk
```

### With pip

```bash
pip install alatpay-sdk
```

## Usage

```python
# You may provide your credentials through environment variables.
# The client automatically loads the following variables:
#
# ALATPAY_SECRET_KEY=""            # Required
# ALATPAY_BUSINESS_ID=""           # Optional. If omitted, methods that require
#                                  #   a business ID will require one explicitly.
# ALATPAY_WEBHOOK_SECRET_KEY=""    # Optional
# ALATPAY_PUBLIC_KEY=""            # Optional
#
# Credentials passed to the client on instantiation take precedence over
# environment variables.

from alatpay_sdk import ALATPayClient, AsyncALATPayClient, PayViaVirtualAccountPayload
from uuid import uuid4

# Instantiate the client
# Credentials may be passed directly if they are not available
# in the environment.
# May raise `MissingCredentialError` if no credentials was passed in 
# on instantiation or found in the environmental variables.
client = ALATPayClient()
# In a async context, you may use the async client
aclient = AsyncALATPayClient()

# Now we create a payload for a debit request via a virtual account.
payload = PayViaVirtualAccountPayload.model_validate(
            {
                "amount": 100,
                "order_id": str(uuid4()),
                "description": "test payin",
                "customer": {
                    "email": "johndoe@example.com",
                    "phone": "08012345678",
                    "first_name": "John",
                    "last_name": "Doe",
                },
            }
        )
# NOTE: Payloads are all pydantic models and you may choose to instantiate it 
#   however you please. They follow a naming convention of converting the method 
#   they are for into PascalCase and appending a `Payload` to it.

# Now we call our client method designated for requesting a debit via a virtual account
# with our payload. (Calling a client method that makes a request, may raise 
# `ClientError` You need to handle this.)
response = client.pay_via_virtual_aaccount(payload)
# If you're using the async clients, the method names remain the same, they just need 
# to be awaited (This only works in a async context ).
response = await aclient.pay_via_virtual_aaccount(payload)

# Use the response data in your application
print(response)
# NOTE: response are pydantic models of type APIResponse[T] where T is the type of the 
# `data` field. The response also includes fields like `status`, `message` and `raw`
# which is the exact response data gotten from ALATPay without any transformation.
# It's also worth noting that you may pass a custom response model while calling
# the client method via the `response_model_class` parameter, for the most part,
# you'll only need to change the `T` of the `APIResponse` e.g if i have 
# `MyCustomResponseData`, then `response_model_class=APIResponse[MyCustomResponseData]`.
# When the client is unable to serialize the data returned by ALATPay, it sets the `data`
# field to `None`, the original data is still present in the `raw` field.
```

---

## Issues and Contributions

If you discover bugs, missing endpoints, incorrect typings, or any other issues, please open an issue or submit a pull request. Contributions are welcome.
