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.
Install using pip:
pip install tappayimport 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)# 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)response = client.pay_by_token(
card_key="card_key",
card_token="card_token",
amount=100,
details="Subscription"
)response = client.refund(
rec_trade_id="rec_trade_id",
amount=100
)For more API details, please refer to the TapPay Backend API Documentation.
- Clone the repository:
git clone https://github.com/shihweilo/tappay-python.git
cd tappay-python- 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 ruffRun tests using pytest:
pytestRun tests with coverage:
pytest --cov=tappayCheck code with ruff:
ruff check .Format code with ruff:
ruff format .Please see CONTRIBUTING.md for details.