klinkfinance / sdk
Official PHP SDK for the Klink platform
Requires
- php: >=8.0
- ext-json: *
- firebase/php-jwt: ^6.0
- guzzlehttp/guzzle: ^7.0
Requires (Dev)
- phpstan/phpstan: ^1.10
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2026-04-06 04:19:22 UTC
README
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.pyandpyproject.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:
-
Factory Method Initialization
- Health check before SDK creation
- Only creates instance if API is available
-
Complete API Coverage
- โ Publisher: getOffers, getConversions, getUsers, getPostbacks
- โ Publisher: getCountries, getCategories, sendTestPostback
- โ Advertiser: sendPostback
- โ Health check for both clients
-
Robust Error Handling
- Custom exception/error classes
- Detailed error messages
- Status code access
- Response data access
-
Configuration Options
- API key & secret
- Custom base URL
- Configurable timeout
- Debug mode
-
Type Safety
- PHP: Full type hints + PHPDoc
- Python: Full type hints for IDE support
-
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:
- GitHub Issues: https://github.com/KlinkFinance/publisher-sdk/issues
- Email: dev@klinkfinance.com
๐ Summary
You now have three complete SDKs for Klink Finance:
- โ Node.js SDK - Original TypeScript implementation
- โ PHP SDK - Complete PHP 8+ implementation
- โ 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
- Test the SDKs with your API credentials
- Publish to package registries:
- PHP: Packagist (composer)
- Python: PyPI (pip)
- Add CI/CD pipelines for automated testing
- Create unit tests for all methods
- Add integration tests with live API
๐ Additional Resources
- See
SDK_COMPARISON.mdfor detailed comparison and migration guide - Check individual README files for SDK-specific documentation
- Review example files for practical usage patterns