Skip to content

shihweilo/tappay-python

Repository files navigation

TapPay Python SDK

CI PyPI version Python Versions Code style: black License: 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.

Installation

Install using pip:

pip install tappay

Usage

Initialization

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:

client = tappay.Client(is_sandbox=False)

Pay by Prime

# Create cardholder data
card_holder = tappay.Models.CardHolderData(
    phone_number="0912345678",
    name="Wang Xiao Ming",
    email="[email protected]"
)

# 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

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

Refunds

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

For more API details, please refer to the TapPay Backend API Documentation.

Development

Setup

  1. Clone the repository:
git clone https://github.com/shihweilo/tappay-python.git
cd tappay-python
  1. Create a virtual environment and install dependencies:
python3 -m venv .venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate
pip install -e .
pip install pytest pytest-cov ruff

Testing

Run tests using pytest:

pytest

Run tests with coverage:

pytest --cov=tappay

Linting and Formatting

Check code with ruff:

ruff check .

Format code with ruff:

ruff format .

Contributing

Please see CONTRIBUTING.md for details.

About

TapPay Backend SDK for Python.

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published

Languages