Official PHP SDK for the Klink platform

Maintainers

Package info

github.com/KlinkFinance/Klink-SDK

Language:Python

pkg:composer/klinkfinance/sdk

Statistics

Installs: 0

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

dev-main 2026-02-06 03:57 UTC

This package is auto-updated.

Last update: 2026-04-06 04:19:22 UTC


README

Latest Stable Version PyPI version License

Complete implementation of Klink Finance SDKs in PHP and Python, matching the functionality of the Node.js SDK.

๐Ÿ“ฆ What's Included

PHP SDK (/php-sdk)

  • โœ… Full PHP 8+ implementation with type hints
  • โœ… PSR-4 compliant structure
  • โœ… Composer package with composer.json
  • โœ… Guzzle HTTP client integration
  • โœ… Complete Publisher & Advertiser clients
  • โœ… Comprehensive error handling
  • โœ… Debug mode support
  • โœ… Full documentation and examples

Python SDK (/python-sdk)

  • โœ… Full Python 3.8+ implementation with type hints
  • โœ… pip-installable package with setup.py and pyproject.toml
  • โœ… requests library for HTTP
  • โœ… Complete Publisher & Advertiser clients
  • โœ… Comprehensive exception handling
  • โœ… Debug mode support
  • โœ… Full documentation and examples

๐Ÿš€ Quick Start

Monorepo Management

This repository is set up as a monorepo. You can use the provided Makefile to manage both SDKs simultaneously.

# Install dependencies for both SDKs
make install

# Clean up build artifacts
make clean

PHP SDK

Install via Composer:

composer require klinkfinance/sdk

Or for local development:

cd php-sdk
composer install
<?php
use KlinkFinance\SDK\KlinkSDK;

$client = KlinkSDK::create([
    'apiKey' => 'your-api-key',
    'apiSecret' => 'your-api-secret'
]);

$publisher = $client->publisher();
$offers = $publisher->getOffers(['limit' => 10]);

Python SDK

Install via pip:

pip install klinkfinance-sdk

Or for local development:

cd python-sdk
pip install -e .
from klinkfinance_sdk import KlinkSDK

client = KlinkSDK.create(
    api_key="your-api-key",
    api_secret="your-api-secret"
)

publisher = client.publisher
offers = publisher.get_offers(limit=10)

๐Ÿ“ Project Structure

klink-sdks/
โ”œโ”€โ”€ php-sdk/
โ”‚   โ”œโ”€โ”€ composer.json
โ”‚   โ”œโ”€โ”€ README.md
โ”‚   โ”œโ”€โ”€ src/
โ”‚   โ”‚   โ”œโ”€โ”€ Core/
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ HttpClient.php
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ PublisherClient.php
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ AdvertiserClient.php
โ”‚   โ”‚   โ”œโ”€โ”€ Types/
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ Config.php
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ KlinkException.php
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ [Other Exceptions...]
โ”‚   โ”‚   โ””โ”€โ”€ KlinkSDK.php
โ”‚   โ””โ”€โ”€ examples/
โ”‚       โ””โ”€โ”€ publisher-example.php
โ”‚
โ”œโ”€โ”€ python-sdk/
โ”‚   โ”œโ”€โ”€ setup.py
โ”‚   โ”œโ”€โ”€ pyproject.toml
โ”‚   โ”œโ”€โ”€ requirements.txt
โ”‚   โ”œโ”€โ”€ README.md
โ”‚   โ”œโ”€โ”€ klink_sdk/
โ”‚   โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”‚   โ”œโ”€โ”€ klink_sdk.py
โ”‚   โ”‚   โ”œโ”€โ”€ core/
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ http_client.py
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ publisher_client.py
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ advertiser_client.py
โ”‚   โ”‚   โ”œโ”€โ”€ types/
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ __init__.py (Config class)
โ”‚   โ”‚   โ””โ”€โ”€ exceptions/
โ”‚   โ”‚       โ””โ”€โ”€ __init__.py
โ”‚   โ””โ”€โ”€ examples/
โ”‚       โ”œโ”€โ”€ publisher_example.py
โ”‚       โ””โ”€โ”€ advertiser_example.py
โ”‚
โ””โ”€โ”€ SDK_COMPARISON.md

โœจ Key Features

Both SDKs Include:

  1. Factory Method Initialization

    • Health check before SDK creation
    • Only creates instance if API is available
  2. Complete API Coverage

    • โœ… Publisher: getOffers, getConversions, getUsers, getPostbacks
    • โœ… Publisher: getCountries, getCategories, sendTestPostback
    • โœ… Advertiser: sendPostback
    • โœ… Health check for both clients
  3. Robust Error Handling

    • Custom exception/error classes
    • Detailed error messages
    • Status code access
    • Response data access
  4. Configuration Options

    • API key & secret
    • Custom base URL
    • Configurable timeout
    • Debug mode
  5. Type Safety

    • PHP: Full type hints + PHPDoc
    • Python: Full type hints for IDE support
  6. Best Practices

    • PSR-4 autoloading (PHP)
    • Python package structure
    • Environment variable support
    • Comprehensive documentation

๐Ÿ”„ API Parity with Node.js SDK

All three SDKs (Node.js, PHP, Python) provide identical functionality:

Feature Node.js PHP Python
Factory initialization โœ… โœ… โœ…
Health check โœ… โœ… โœ…
Publisher APIs โœ… โœ… โœ…
Advertiser APIs โœ… โœ… โœ…
Error handling โœ… โœ… โœ…
Debug mode โœ… โœ… โœ…
Type safety โœ… โœ… โœ…
Documentation โœ… โœ… โœ…
Examples โœ… โœ… โœ…

๐Ÿ“– Documentation

Each SDK includes:

  • โœ… Complete README with installation and usage
  • โœ… Configuration options documentation
  • โœ… API methods reference
  • โœ… Error handling guide
  • โœ… Working examples
  • โœ… Development setup instructions

๐ŸŽฏ Publisher API Methods

Both SDKs support all Publisher endpoints:

- getOffers(params) / get_offers(params)
- getConversions(params) / get_conversions(params)
- getUsers(params) / get_users(params)
- getPostbacks(params) / get_postbacks(params)
- getCountries(reload) / get_countries(reload)
- getCategories(reload) / get_categories(reload)
- sendTestPostback(data) / send_test_postback(data)
- healthCheck() / health_check()

๐ŸŽฏ Advertiser API Methods

Both SDKs support all Advertiser endpoints:

- sendPostback(data) / send_postback(data)
- healthCheck() / health_check()

๐Ÿ› ๏ธ Installation

PHP Requirements

  • PHP >= 8.0
  • ext-json
  • guzzlehttp/guzzle ^7.0
cd php-sdk
composer install

Python Requirements

  • Python >= 3.8
  • requests >= 2.25.0
cd python-sdk
pip install -e .
# or
pip install -r requirements.txt

๐Ÿ“ Usage Examples

PHP - Publisher

use KlinkFinance\SDK\KlinkSDK;

$client = KlinkSDK::create([
    'apiKey' => $_ENV['KLINK_API_KEY'],
    'apiSecret' => $_ENV['KLINK_API_SECRET'],
    'debug' => true
]);

$publisher = $client->publisher();

// Fetch offers
$offers = $publisher->getOffers([
    'page' => 1,
    'limit' => 50,
    'category' => ['gaming'],
    'country' => ['US']
]);

// Fetch conversions
$conversions = $publisher->getConversions([
    'page' => 1,
    'limit' => 20,
    'status' => 'approved'
]);

PHP - Advertiser

$advertiser = $client->advertiser();

$result = $advertiser->sendPostback([
    'event_name' => 'create_account',
    'offer_id' => 'offer_123',
    'sub1' => 'sub1_value',
    'tx_id' => 'tx_123',
    'isChargeback' => false,
    'chargebackReason' => '',
    'isTest' => true
]);

Python - Publisher

from klink_sdk import KlinkSDK
import os

client = KlinkSDK.create(
    api_key=os.environ["KLINK_API_KEY"],
    api_secret=os.environ["KLINK_API_SECRET"],
    debug=True
)

publisher = client.publisher

# Fetch offers
offers = publisher.get_offers(
    page=1,
    limit=50,
    category=["gaming"],
    country=["US"]
)

# Fetch conversions
conversions = publisher.get_conversions(
    page=1,
    limit=20,
    status="approved"
)

Python - Advertiser

advertiser = client.advertiser

result = advertiser.send_postback(
    event_name="create_account",
    offer_id="offer_123",
    sub1="sub1_value",
    tx_id="tx_123",
    is_chargeback=False,
    chargeback_reason="",
    is_test=True
)

๐Ÿ”ง Error Handling

PHP

use KlinkFinance\SDK\Exceptions\*;

try {
    $client = KlinkSDK::create([...]);
    $offers = $client->publisher()->getOffers();
} catch (KlinkConfigException $e) {
    // Configuration error
} catch (KlinkAuthException $e) {
    // Authentication error
} catch (KlinkAPIException $e) {
    // API error - includes status code and response data
    echo $e->getStatusCode();
    print_r($e->getResponseData());
} catch (KlinkNetworkException $e) {
    // Network error
}

Python

from klink_sdk import (
    KlinkConfigException,
    KlinkAuthException,
    KlinkAPIException,
    KlinkNetworkException
)

try:
    client = KlinkSDK.create(...)
    offers = client.publisher.get_offers()
except KlinkConfigException as e:
    # Configuration error
    pass
except KlinkAuthException as e:
    # Authentication error
    print(f"Status: {e.status_code}")
except KlinkAPIException as e:
    # API error - includes status code and response data
    print(f"Status: {e.status_code}")
    print(f"Data: {e.response_data}")
except KlinkNetworkException as e:
    # Network error
    pass

๐Ÿงช Testing

PHP

cd php-sdk
composer test
composer analyse

Python

cd python-sdk
pytest
mypy klink_sdk
black klink_sdk
pylint klink_sdk

๐Ÿ“„ License

Both SDKs are released under the MIT License, matching the Node.js SDK.

๐Ÿค Support

For issues, questions, or contributions:

๐ŸŽ‰ Summary

You now have three complete SDKs for Klink Finance:

  1. โœ… Node.js SDK - Original TypeScript implementation
  2. โœ… PHP SDK - Complete PHP 8+ implementation
  3. โœ… Python SDK - Complete Python 3.8+ implementation

All three SDKs:

  • Share identical functionality and API coverage
  • Follow language-specific best practices
  • Include comprehensive documentation
  • Provide working examples
  • Support debug mode
  • Include proper error handling
  • Use factory methods with health checks

๐Ÿ“ฆ Next Steps

  1. Test the SDKs with your API credentials
  2. Publish to package registries:
    • PHP: Packagist (composer)
    • Python: PyPI (pip)
  3. Add CI/CD pipelines for automated testing
  4. Create unit tests for all methods
  5. Add integration tests with live API

๐Ÿ”— Additional Resources

  • See SDK_COMPARISON.md for detailed comparison and migration guide
  • Check individual README files for SDK-specific documentation
  • Review example files for practical usage patterns