tebex/tebex-sdk-php
Composer 安装命令:
composer require tebex/tebex-sdk-php
包简介
Gaming payments done right - Tebex is the monetization platform designed to grow your gaming revenue streams
README 文档
README
The Tebex PHP library provides access to Tebex APIs from applications written using PHP.
Requirements
PHP 7.4.0 or above.
Composer
Install the SDK via Composer using the following command:
composer require tebex/tebex-sdk-php
Use Composer's autoload to use the Tebex library.
require_once 'vendor/autoload.php';
Dependencies
The following PHP extensions must be installed in your PHP environment:
curljson
Composer will install these extensions automatically. If installing manually, ensure these extensions are available and enabled for your PHP distribution.
Examples
Headless API
Headless allows interaction with your Tebex project using pre-defined packages and is available for all stores.
$project = Headless::setProject("your-public-token"); // Interact with the project through $project $categories = $project->listCategories(); $packages = $project->listPackages(); $project->getCategory(12345); $project->getPackage(67890); // Create baskets through the project, providing completion and cancellation urls $basket = $project->createBasket("https://tebex.io/completed", "https://tebex.io/cancelled"); // If the project requires auth, direct the user to authorize before adding packages if ($project->requiresUserAuth()) { $authUrl = $project->getUserAuthUrl($basket, "https://tebex.io/auth-return"); echo "- User auth required at: " . $authUrl . ".\n"; } // Once user is successfully authed we can add packages via $basket $package = $packages[0]; $basket = $basket->addPackage($package); $basket = $basket->addGiftedPackage($package, "Tebex"); $basket = $basket->addGiftCardPackage($package, "tebex-integrations@overwolf.com"); // You can also add variable data as needed per each package $basket->addPackage($package, [ "server_id" => "127244" ]); // Each function returns the remote basket after completion, but you can always request the current basket from the API $basket = $basket->refreshBasket(); // Query the $basket object for any info echo "Price: $" . $basket->getBasePrice() . "\n"; // Go to checkout $checkoutLink = $basket->getLinks()->getCheckout(); echo "Checkout at: " . $checkoutLink;
Webhooks
Webhooks are sent to authorized endpoints configured within your Tebex creator panel. They contain information about events that occur in your project such as payments, refunds, and disputes.
Note: The secret key must be your webhook key provided at https://creator.tebex.io/webhooks/endpoints
// You must set your secret key first so that webhooks can be validated. Webhooks::setSecretKey("2248c2227ac29e5cbdbab44ed6a0f961"); // Is read from php://input unless an argument is provided $webhook = Webhook::parse(); // You can check for specific webhook types if ($webhook->isType(\Tebex\Webhook\VALIDATION_WEBHOOK)) { echo json_encode(["id" => $webhook->getId()]); // Respond to validation endpoint } // You can quickly check the type of webhook with helper functions as well else if ($webhook->isTypeOfPayment() || $webhook->isTypeOfDispute()) { // The "subject" contains data about the webhook action $pmtSubject = $webhook->getSubject(); // type is \TebexCheckout\Model\PaymentSubject // etc.... } else if ($webhook->isTypeOfRecurringPayment()) { $recurringPmtSubject = $webhook->getSubject(); // \TebexCheckout\Model\RecurringPaymentSubject // etc... }
Checkout API
The Checkout API allows collecting payment for ad-hoc products not defined in a Tebex project.
This API requires prior approval. Please contact Tebex support to enable on your account.
// Authorize your store using your API keys Checkout::setApiKeys("projectId", "privateKey");
Creating Baskets
Use the Checkout\BasketBuilder to create and manage your baskets.
// Use the BasketBuilder to create your basket for Checkout $builder = Checkout\BasketBuilder::new() ->email("tebex-integrations@overwolf.com") ->firstname("Tebex") ->lastname("Integrations") ->ip("127.0.0.1") // provide client IP if running on your backend server ->returnUrl("https://tebex.io/") ->completeUrl("https://tebex.io/");
Adding Packages
Use the Checkout\PackageBuilder to create the packages you wish to add to your basket.
$package1 = Checkout\PackageBuilder::new()->name("100 Gold")->qty(1)->price(1.27) ->oneTime(); $package2 = Checkout\PackageBuilder::new()->name("1 Month Sub")->qty(1)->price(2.44) ->subscription()->monthly()->expiryLength(1);
Checkout Request (Recommended)
You can use Checkout::checkoutRequest to send basket information and its products in a single request. The list
of packages should be an array of CheckoutItem, which can be provided by the PackageBuilder with buildCheckoutItem().
$builder = Checkout\BasketBuilder::new() ->email("support@tebex.io")->firstname("Tebex")->lastname("Support") ->ip($_SERVER["REMOTE_ADDR"]) ->returnUrl("https://tebex.io/")->completeUrl("https://tebex.io/"); $package1 = Checkout\PackageBuilder::new()->name("100 Gold")->qty(1)->price(1.27)->oneTime(); $basket = Checkout::checkoutRequest($builder, [$package1->buildCheckoutItem()]); echo "Checkout at: " . $basket->getLinks()->getCheckout();
❓ API Documentation
Our APIs are fully documented at https://docs.tebex.io/developers as a resource for all options, events, and advanced functionality possible through Tebex.
🔗 Useful Links
Contributions
This SDK is open source and we welcome contributions from the community. If you wish to make a contribution, please review CONTRIBUTING.md for guidelines and things to know before making your contribution.
🙋♂️ Support
For issues relating to this library, please raise an issue in its repository. Otherwise you may also contact tebex-integrations@tebex.io.
tebex/tebex-sdk-php 适用场景与选型建议
tebex/tebex-sdk-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 914 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 12 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「api」 「payments」 「sdk」 「payment processing」 「gaming」 「game development」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 tebex/tebex-sdk-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 tebex/tebex-sdk-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 tebex/tebex-sdk-php 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Dealing with payments through the Egyptian payment gateway PayMob
Librería para la gestión sencilla de pagos mediante TPV Redsys y Paypal
A PSR-7 compatible library for making CRUD API endpoints
Scanpay module for Magento 2
Official Safaricom Daraja M-Pesa integration for Laravel built on ysg/payment-core.
Официальный PHP SDK для платёжного шлюза Oblodai: приём платежей, выплаты, статические кошельки, вебхуки.
统计信息
- 总下载量: 914
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 13
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-12-20