loyaltylt/sdk
Composer 安装命令:
composer require loyaltylt/sdk
包简介
Official PHP SDK for Loyalty.lt Shop API
README 文档
README
Official PHP SDK for Loyalty.lt Shop API.
Installation
composer require loyaltylt/sdk
Requirements
- PHP 8.1 or higher
- ext-json
- Guzzle HTTP client
Quick Start
<?php require_once 'vendor/autoload.php'; use LoyaltyLt\SDK\LoyaltySDK; $sdk = new LoyaltySDK([ 'apiKey' => 'lty_your_api_key', 'apiSecret' => 'your_api_secret', 'environment' => 'production', // or 'staging' 'locale' => 'lt', ]); // Get shops $shops = $sdk->getShops(); print_r($shops['data']);
Configuration Options
| Option | Type | Default | Description |
|---|---|---|---|
apiKey |
string | required | API Key |
apiSecret |
string | required | API Secret |
environment |
string | production |
production or staging |
locale |
string | lt |
API locale (lt, en) |
timeout |
int | 30 |
Request timeout in seconds |
retries |
int | 3 |
Number of retry attempts |
debug |
bool | false |
Enable debug logging |
Features
QR Login
Generate QR codes for customer authentication:
// Generate QR login session $session = $sdk->generateQrLogin('POS Terminal #1', $shopId); echo $session['session_id']; echo $session['qr_code']; // Deep link for QR code echo $session['expires_at']; // Poll for status (or use Ably real-time) $status = $sdk->pollQrLogin($session['session_id']); if ($status['status'] === 'authenticated') { $user = $status['user']; echo "Welcome, " . $user['name']; }
QR Card Scan (POS Customer Identification)
Identify customers via QR code:
// Generate QR card scan session $session = $sdk->generateQrCardSession('POS Terminal', $shopId); // Display QR code to customer $qrImageUrl = "https://api.qrserver.com/v1/create-qr-code/?size=250x250&data=" . urlencode($session['qr_code']); // Poll for customer identification $result = $sdk->pollQrCardStatus($session['session_id']); if ($result['status'] === 'completed') { $card = $result['card_data']; echo "Customer: " . $card['user']['name']; echo "Points: " . $card['points_balance']; }
Real-time Updates with Ably
// Get Ably token $ablyToken = $sdk->getAblyToken($session['session_id']); // Use with Ably client echo $ablyToken['token']; echo $ablyToken['channel'];
Shops
// Get all shops $shops = $sdk->getShops(); // Filter shops $shops = $sdk->getShops([ 'is_active' => true, 'is_virtual' => false, ]);
Loyalty Cards
// Get cards $cards = $sdk->getLoyaltyCards(); // Get single card $card = $sdk->getLoyaltyCard(123); // Get card by number $cardInfo = $sdk->getLoyaltyCardInfo([ 'card_number' => '123-456-789' ]); // Get points balance $balance = $sdk->getPointsBalance([ 'card_id' => 123 ]);
Transactions & Points
// Award points $transaction = $sdk->createTransaction([ 'card_id' => 123, 'amount' => 50.00, 'points' => 50, 'type' => 'earn', 'description' => 'Purchase reward', 'reference' => 'ORDER-12345', ]); // Get transactions $transactions = $sdk->getTransactions([ 'card_id' => 123, 'type' => 'earn', ]);
Offers
// Get offers $offers = $sdk->getOffers(['is_active' => true]); // Create offer $offer = $sdk->createOffer([ 'title' => 'Summer Sale', 'description' => '20% off all items', 'discount_type' => 'percentage', 'discount_value' => 20, 'start_date' => '2024-06-01', 'end_date' => '2024-08-31', ]); // Get categories $categories = $sdk->getCategories();
XML Import
// Import offers from XML $result = $sdk->importFromUrl('https://example.com/offers.xml', [ 'auto_publish' => true, ]); // Validate XML $validation = $sdk->validateXml('https://example.com/offers.xml'); // Get import stats $stats = $sdk->getImportStats();
Error Handling
use LoyaltyLt\SDK\Exceptions\LoyaltySDKException; try { $result = $sdk->getLoyaltyCardInfo(['card_number' => 'INVALID']); } catch (LoyaltySDKException $e) { echo "Error: " . $e->getMessage(); echo "Code: " . $e->getErrorCode(); echo "HTTP Status: " . $e->getHttpStatus(); }
Laravel Integration
Service Provider
// config/services.php 'loyalty' => [ 'api_key' => env('LOYALTY_API_KEY'), 'api_secret' => env('LOYALTY_API_SECRET'), 'environment' => env('LOYALTY_ENVIRONMENT', 'production'), ], // app/Providers/AppServiceProvider.php use LoyaltyLt\SDK\LoyaltySDK; public function register() { $this->app->singleton(LoyaltySDK::class, function ($app) { return new LoyaltySDK([ 'apiKey' => config('services.loyalty.api_key'), 'apiSecret' => config('services.loyalty.api_secret'), 'environment' => config('services.loyalty.environment'), ]); }); } // Usage in controller public function __construct(private LoyaltySDK $loyalty) {} public function processTransaction(Request $request) { return $this->loyalty->createTransaction([ 'card_id' => $request->card_id, 'amount' => $request->amount, 'shop_id' => $request->shop_id, ]); }
API Documentation
Full API documentation: docs.loyalty.lt
Support
- Email: developers@loyalty.lt
- Documentation: https://docs.loyalty.lt
- Issues: https://github.com/Loyalty-lt/sdk-php/issues
License
MIT License - see LICENSE for details.
loyaltylt/sdk 适用场景与选型建议
loyaltylt/sdk 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 12 月 10 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「api」 「sdk」 「rewards」 「pos」 「loyalty」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 loyaltylt/sdk 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 loyaltylt/sdk 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 loyaltylt/sdk 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A PSR-7 compatible library for making CRUD API endpoints
Alfabank REST API integration
Zero-dependency raw PHP DNS resolver, domain-ownership verification, and intoDNS/MxToolbox-style diagnostics. Queries authoritative nameservers directly over sockets — never trusts the recursive cache for ownership checks.
A lightweight plain-PHP framework for database-backed CRUD APIs.
bughq error tracking - PHP SDK
ABsurge PHP SDK for feature flags and A/B testing
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 20
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-12-10