Metadata-Version: 2.4
Name: tappay
Version: 0.5.2
Summary: TapPay Client Library for Python
Author-email: Shih Wei Chris Lo <shihwei@gmail.com>
Project-URL: Homepage, https://github.com/shihweilo/tappay-python
Project-URL: Bug Tracker, https://github.com/shihweilo/tappay-python/issues
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: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE.txt
Requires-Dist: requests>=2.4.2
Dynamic: license-file


# TapPay Python SDK

![CI](https://github.com/shihweilo/tappay-python/workflows/CI/badge.svg)
[![PyPI version](https://badge.fury.io/py/tappay.svg)](https://badge.fury.io/py/tappay)
[![Python Versions](https://img.shields.io/pypi/pyversions/tappay.svg)](https://pypi.org/project/tappay/)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

> [!IMPORTANT]
> **Python 2 Support Dropped**: As of version 0.5.0, this library no longer supports Python 2.7. Please use Python 3.8 or newer.

This is the unofficial Python client library for TapPay's Backend API. To use it you'll need a TapPay account. Sign up at [tappaysdk.com](https://www.tappaysdk.com).

## Installation

Install using pip:

```bash
pip install tappay
```

## Usage

### Initialization

```python
import tappay

# Initialize the client
client = tappay.Client(
    is_sandbox=True, 
    partner_key="YOUR_PARTNER_KEY", 
    merchant_id="YOUR_MERCHANT_ID"
)
```

For production, you can set `TAPPAY_PARTNER_KEY` and `TAPPAY_MERCHANT_ID` environment variables and omit them in the constructor:

```python
client = tappay.Client(is_sandbox=False)
```

### Pay by Prime

```python
# Create cardholder data
card_holder = tappay.Models.CardHolderData(
    phone_number="0912345678",
    name="Wang Xiao Ming",
    email="test@example.com"
)

# Make payment
response = client.pay_by_prime(
    prime="prime_token_from_frontend",
    amount=100,
    details="Order #123",
    card_holder_data=card_holder
)
print(response)
```

### Pay by Token

```python
response = client.pay_by_token(
    card_key="card_key",
    card_token="card_token",
    amount=100,
    details="Subscription"
)
```

### Refunds

```python
response = client.refund(
    rec_trade_id="rec_trade_id",
    amount=100
)
```

For more API details, please refer to the [TapPay Backend API Documentation](https://docs.tappaysdk.com/tutorial/zh/back.html).

## Development

### Setup

```bash
git clone https://github.com/shihweilo/tappay-python.git
cd tappay-python
pip install -e ".[dev]"
```

### Testing

Run tests using pytest:

```bash
pytest
```

## Contributing

Please see [CONTRIBUTING.md](CONTRIBUTING.md) for details.
