Skip to main content

Official async Python SDK for Polako Finance payment gateway

Project description

Polako Finance Python SDK

PyPI version Python Support License: MIT

Official Python SDK for the Polako Finance payment gateway. This library provides an async-first interface following modern Python best practices for seamless integration with the Polako Finance API.

The SDK uses the polako.sdk namespace to avoid naming conflicts with other packages.

Features

  • Async-First - Built with async/await for optimal performance
  • Type Safety - Full type hints for better IDE support and code quality
  • Easy to Use - Simple, intuitive API design
  • Comprehensive - Complete coverage of Polako Finance payment gateway features
  • Well Documented - Extensive documentation and examples
  • Production Ready - Robust error handling and validation
  • Modern - Follows current Python async best practices

Installation

Install using pip:

pip install polako-finance

Or using poetry:

poetry add polako-finance

Requirements

  • Python 3.9+
  • httpx >= 0.25

Quick Start

import asyncio
from polako.sdk import PolakoClient, OrderDetails, OrderItem, CustomerInfo
from decimal import Decimal
from uuid import UUID

async def create_payment():
    # Use as context manager for automatic cleanup
    async with PolakoClient(test_env=True) as client:
        # Create order details
        order = OrderDetails(
            currency="RSD",
            language="en",
            order_id="ORDER-123",
            items=[
                OrderItem(
                    code="PROD-001",
                    name="Premium Product",
                    description="A premium product",
                    price=Decimal("100.00"),
                    quantity=2,
                    tax="VAT"
                )
            ],
            total=Decimal("200.00")
        )
        
        # Create customer information
        customer = CustomerInfo(
            first_name="John",
            last_name="Doe",
            email="john.doe@example.com",
            phone="+381123456789"
        )
        
        # Create payment session
        session = await client.create_order(
            order=order,
            customer=customer,
            platform_id=UUID("your-platform-id"),
            secret_key="your-secret-key"
        )
        
        print(f"Payment URL: {session.paymentPageUrl}")
        print(f"Session ID: {session.paymentSessionId}")
        print(f"Expires at: {session.expiresAt}")
        
        return session

# Run async function
if __name__ == "__main__":
    session = asyncio.run(create_payment())

Payment Callback Handling

Handle payment callbacks from the gateway:

from polako.sdk import PolakoClient

# Parse callback payload
callback_payload = request.body  # From your webhook endpoint
callback = PolakoClient.parse_payment_callback(
    payload=callback_payload,
    secret_key="your-secret-key"  # Optional, for signature verification
)

if callback.success:
    print(f"Payment successful for order: {callback.order_id}")
    print(f"Amount: {callback.total} {callback.currency}")
else:
    print(f"Payment failed for order: {callback.order_id}")

Configuration

Client Options

from polako.sdk import PolakoClient

# Initialize client with options
async with PolakoClient(
    timeout=30.0,      # Request timeout in seconds (default: 30.0)
    test_env=False     # Use production environment (default: False)
) as client:
    # Your code here
    pass

Supported Currencies

  • RSD - Serbian Dinar

Supported Languages

  • sr - Serbian
  • en - English
  • ru - Russian

Tax Schemas

  • VAT - Value Added Tax
  • No_VAT - No VAT
  • Reduced_VAT - Reduced VAT rate

Error Handling

The SDK provides specific exceptions for different error scenarios:

from polako.sdk import PolakoClient, HttpClientError, HttpRequestError

try:
    async with PolakoClient() as client:
        session = await client.create_order(order, customer, platform_id, secret_key)
except ValueError as e:
    # Validation error (invalid order or customer data)
    print(f"Validation error: {e}")
except HttpRequestError as e:
    # HTTP request failed (4xx or 5xx response)
    print(f"Request failed with status {e.status_code}: {e.message}")
    print(f"Response: {e.response_body}")
except HttpClientError as e:
    # Network error or other client-side issue
    print(f"Client error: {e.message}")
except Exception as e:
    # Unexpected error
    print(f"Unexpected error: {e}")

Advanced Usage

Custom Customer Address

from polako.sdk import CustomerInfo, CustomerAddress

customer = CustomerInfo(
    first_name="John",
    last_name="Doe",
    email="john.doe@example.com",
    phone="+381123456789",
    address=CustomerAddress(
        address="123 Main Street",
        city="Belgrade",
        state="Central Serbia",
        zip="11000",
        country="Serbia"
    )
)

Multiple Items in Order

from polako.sdk import OrderDetails, OrderItem
from decimal import Decimal

order = OrderDetails(
    currency="RSD",
    language="en",
    order_id="ORDER-789",
    items=[
        OrderItem(
            code="ITEM-001",
            name="Product A",
            price=Decimal("50.00"),
            quantity=2,
            tax="VAT"
        ),
        OrderItem(
            code="ITEM-002",
            name="Product B",
            price=Decimal("75.00"),
            quantity=1,
            tax="VAT"
        ),
    ],
    total=Decimal("175.00")  # 50*2 + 75*1
)

API Reference

PolakoClient

Async client for Polako Finance API.

Methods

  • async create_order(order, customer, platform_id, secret_key) - Create a new payment order
  • parse_payment_callback(payload, secret_key) - Parse payment callback (static method)

Context Manager

The client supports async context manager protocol for automatic resource cleanup:

async with PolakoClient() as client:
    # Client automatically manages connection lifecycle
    session = await client.create_order(...)
# Resources are automatically cleaned up here

Models

  • OrderDetails - Order information
  • OrderItem - Individual order item
  • CustomerInfo - Customer information
  • CustomerAddress - Customer address details
  • SessionInfo - Payment session response
  • PaymentCallback - Parsed payment callback data

Support

License

This project is licensed under the MIT License - see the LICENSE file for details.

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

polako_finance-0.1.8.tar.gz (17.5 kB view details)

Uploaded Source

Built Distribution

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

polako_finance-0.1.8-py3-none-any.whl (18.1 kB view details)

Uploaded Python 3

File details

Details for the file polako_finance-0.1.8.tar.gz.

File metadata

  • Download URL: polako_finance-0.1.8.tar.gz
  • Upload date:
  • Size: 17.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.2 CPython/3.11.15 Linux/6.17.0-1015-azure

File hashes

Hashes for polako_finance-0.1.8.tar.gz
Algorithm Hash digest
SHA256 6f2eb3f7a71aa9b6eaceae8f6236d6e40536e03168fa2f9748afe92b88d8786e
MD5 1bcc53cd347021a93fe2e19a3d961f5e
BLAKE2b-256 b60525f7025d9c1b6d688f872129498b15fc08b888275cdaa1bc1b1f03b699cb

See more details on using hashes here.

File details

Details for the file polako_finance-0.1.8-py3-none-any.whl.

File metadata

  • Download URL: polako_finance-0.1.8-py3-none-any.whl
  • Upload date:
  • Size: 18.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.2 CPython/3.11.15 Linux/6.17.0-1015-azure

File hashes

Hashes for polako_finance-0.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 a8d7280ca724d7a6e177a5a06ea531aefa61e0ce356da2789b2c7f2e797f99bb
MD5 cbf189b0f7f08afffe217576aeacb38e
BLAKE2b-256 97de5a2d5ae8ea0a9c7fbac162d3fb4ba683763713b4fc8d882d96c351036cd5

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