Skip to main content

Python SDK for the TransFi Payment API

Project description

python-sdk

Python SDK for the TransFi Payment API.

Installation

pip install transfi-sdk

Quick start

from transfi import TransFiPaymentAPI, TransFiError
from transfi.types import PaymentInvoiceRequest, Individual, ProductDetails

api = TransFiPaymentAPI(
    public_key="YOUR_PUBLIC_KEY",
    secret_key="YOUR_SECRET_KEY",
)

request = PaymentInvoiceRequest(
    payment_link_id="LINK_ID",
    amount="100",
    currency="USD",
    product_details=ProductDetails(
        name="Premium Plan",
        description="Monthly subscription",
    ),
    individual=Individual(
        first_name="John",
        last_name="Doe",
        email="john@example.com",
        phone="1234567890",
        phone_code="+1",
        country="US",
    ),
    success_redirect_url="https://example.com/success",
    failure_redirect_url="https://example.com/failure",
    customer_order_id="order-001",
)

try:
    payment_url = api.create_payment_invoice(request)
    print("Checkout URL:", payment_url)
except TransFiError as e:
    print("API Error   :", e)
    print("Status Code :", e.status_code)
    print("Response    :", e.response_data)

You can also pass a plain dict instead of the dataclass if you prefer (keys match the JSON API: camelCase):

payment_url = api.create_payment_invoice({
    "paymentLinkId": "LINK_ID",
    "amount": "100",
    "currency": "USD",
    "productDetails": {
        "name": "Premium Plan",
        "description": "Monthly subscription",
    },
    "individual": {
        "firstName": "John",
        "lastName": "Doe",
        "email": "john@example.com",
        "phone": "1234567890",
        "phoneCode": "+1",
        "country": "US",
    },
    "successRedirectUrl": "https://example.com/success",
    "failureRedirectUrl": "https://example.com/failure",
    "customerOrderId": "order-001",
})

Context manager

with TransFiPaymentAPI(public_key="...", secret_key="...") as api:
    url = api.create_payment_invoice(request)

Types reference

Python class Fields
PaymentInvoiceRequest payment_link_id, amount, currency, success_redirect_url, failure_redirect_url, product_details?, individual?, customer_order_id?
ProductDetails name, description?, image_url?
Individual first_name, last_name, email, phone?, phone_code?, country?, address?
Address city?, state?, street?, postal_code?

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

transfi_sdk-0.1.0.tar.gz (6.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

transfi_sdk-0.1.0-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file transfi_sdk-0.1.0.tar.gz.

File metadata

  • Download URL: transfi_sdk-0.1.0.tar.gz
  • Upload date:
  • Size: 6.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for transfi_sdk-0.1.0.tar.gz
Algorithm Hash digest
SHA256 71e2bcb1eb93b7c8b92d5b2f58743d9bf0de8c793c41dd9a92dff4a149938ce6
MD5 a9256d792f4991d5b478e6c52cddc2b2
BLAKE2b-256 026455cb418d08a5b19c1c81e75619773c1c92fd061f51da7749a62175e04136

See more details on using hashes here.

File details

Details for the file transfi_sdk-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: transfi_sdk-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for transfi_sdk-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4ecff67d53b9ecd130851efcb40259c69180e37f2c900e1820e74ee57af0710e
MD5 b8af38859d7b4dc0f05e3518c26a14cc
BLAKE2b-256 7bb15ee6dda748b18606d0da5460df8bffe204a95bd5def215202f8ed2934b4c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page